浏览代码

Towards better mxl testing

Andrea Condoluci 9 年之前
父节点
当前提交
91690836b6
共有 4 个文件被更改,包括 61 次插入56 次删除
  1. 1 0
      Gruntfile.js
  2. 5 0
      karma.conf.js
  3. 54 54
      src/Common/FileIO/Xml.ts
  4. 1 2
      test/MusicalScore/Calculation/MeasureSizeCalculator.ts

+ 1 - 0
Gruntfile.js

@@ -131,6 +131,7 @@ module.exports = function (grunt) {
                 src: [
                     '<%= outputDir.build %>',
                     '<%= outputDir.dist %>',
+                    'node-modules',
                     '.tscache',
                     'src/**/*.js', 'test/**/*.js'
                 ]

+ 5 - 0
karma.conf.js

@@ -28,6 +28,11 @@ module.exports = function (config) {
         }, {
             pattern: 'test/data/*.mxl.str',
             included: true
+        }, {
+            pattern: 'test/data/*.mxl',
+            included: false,
+            watched: false,
+            served: true
         }],
 
         // preprocess matching files before serving them to the browser

+ 54 - 54
src/Common/FileIO/Xml.ts

@@ -1,69 +1,69 @@
 export type IXmlAttribute = Attr;
 
 export class IXmlElement {
-  public name: string;
-  public value: string;
-  public hasAttributes: boolean = false;
-  public firstAttribute: IXmlAttribute;
-  public hasElements: boolean;
+    public name: string;
+    public value: string;
+    public hasAttributes: boolean = false;
+    public firstAttribute: IXmlAttribute;
+    public hasElements: boolean;
 
-  private attrs: IXmlAttribute[];
-  private elem: Element;
+    private attrs: IXmlAttribute[];
+    private elem: Element;
 
-  constructor(elem: Element) {
-    this.elem = elem;
-    this.name = elem.nodeName.toLowerCase();
+    constructor(elem: Element) {
+        this.elem = elem;
+        this.name = elem.nodeName.toLowerCase();
 
-    if (elem.hasAttributes()) {
-      this.hasAttributes = true;
-      this.firstAttribute = elem.attributes[0];
-      }
-    this.hasElements = elem.hasChildNodes();
-    // Look for a value
-    if (elem.childNodes.length === 1 && elem.childNodes[0].nodeType === Node.TEXT_NODE) {
-      this.value = elem.childNodes[0].nodeValue;
+        if (elem.hasAttributes()) {
+            this.hasAttributes = true;
+            this.firstAttribute = elem.attributes[0];
+        }
+        this.hasElements = elem.hasChildNodes();
+        // Look for a value
+        if (elem.childNodes.length === 1 && elem.childNodes[0].nodeType === Node.TEXT_NODE) {
+            this.value = elem.childNodes[0].nodeValue;
+        }
     }
-  }
 
-  public attribute(attributeName: string): IXmlAttribute {
-    return this.elem.attributes.getNamedItem(attributeName);
-  }
-
-  public attributes(): IXmlAttribute[] {
-    if (typeof this.attrs === "undefined") {
-      let attributes: NamedNodeMap = this.elem.attributes;
-      let attrs: IXmlAttribute[] = [];
-      for (let i: number = 0; i < attributes.length; i += 1) {
-        attrs.push(attributes[i]);
-      }
-      this.attrs = attrs;
+    public attribute(attributeName: string): IXmlAttribute {
+        return this.elem.attributes.getNamedItem(attributeName);
     }
-    return this.attrs;
-  }
 
-  public element(elementName: string): IXmlElement {
-    return this.elements(elementName)[0];
-  }
+    public attributes(): IXmlAttribute[] {
+        if (typeof this.attrs === "undefined") {
+            let attributes: NamedNodeMap = this.elem.attributes;
+            let attrs: IXmlAttribute[] = [];
+            for (let i: number = 0; i < attributes.length; i += 1) {
+                attrs.push(attributes[i]);
+            }
+            this.attrs = attrs;
+        }
+        return this.attrs;
+    }
 
-  public elements(nodeName?: string): IXmlElement[] {
-    let nodes: NodeList = this.elem.childNodes;
-    let ret: IXmlElement[] = [];
-    let nameUnset: boolean = nodeName === undefined;
-    if (!nameUnset) {
-      nodeName = nodeName.toLowerCase();
+    public element(elementName: string): IXmlElement {
+        return this.elements(elementName)[0];
     }
-    // console.log("-", nodeName, nodes.length, this.elem.childElementCount, this.elem.getElementsByTagName(nodeName).length);
-    // if (nodeName === "measure") {
-    //   console.log(this.elem);
-    // }
-    for (let i: number = 0; i < nodes.length; i += 1) {
-      let node: Node = nodes[i];
-      //console.log("node: ", this.elem.nodeName, ">>", node.nodeName, node.nodeType === Node.ELEMENT_NODE);
-      if (node.nodeType === Node.ELEMENT_NODE &&
-        (nameUnset || node.nodeName.toLowerCase() === nodeName)) {
-          ret.push(new IXmlElement(node as Element));
+
+    public elements(nodeName?: string): IXmlElement[] {
+        let nodes: NodeList = this.elem.childNodes;
+        let ret: IXmlElement[] = [];
+        let nameUnset: boolean = nodeName === undefined;
+        if (!nameUnset) {
+            nodeName = nodeName.toLowerCase();
+        }
+        // console.log("-", nodeName, nodes.length, this.elem.childElementCount, this.elem.getElementsByTagName(nodeName).length);
+        // if (nodeName === "measure") {
+        //   console.log(this.elem);
+        // }
+        for (let i: number = 0; i < nodes.length; i += 1) {
+            let node: Node = nodes[i];
+            //console.log("node: ", this.elem.nodeName, ">>", node.nodeName, node.nodeType === Node.ELEMENT_NODE);
+            if (node.nodeType === Node.ELEMENT_NODE &&
+                (nameUnset || node.nodeName.toLowerCase() === nodeName)) {
+                ret.push(new IXmlElement(node as Element));
+            }
         }
+        return ret;
     }
-    return ret;
-  }
 }

+ 1 - 2
test/MusicalScore/Calculation/MeasureSizeCalculator.ts

@@ -72,8 +72,7 @@ describe("Measure Size Calculator Tests", () => {
           let clef: Vex.Flow.Clef = new Vex.Flow.Clef(t);
           stave2.addModifier(clef, Vex.Flow.StaveModifier.Position.BEGIN);
           stave2.format();
-          // (*&^%$#@) //
-          // FIXME HERE? NaN FIXME FIXME FIXME //
+
           clef.setStave(stave2);
           let bb: Vex.Flow.BoundingBox =
               MeasureSizeCalculator.getClefBoundingBox(clef);