[Pkg-javascript-commits] [ltx] 317/469: Fix test/element-test.js

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit e5267fa8fef55c9e52cf7a15e088fded5db05d97
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 16 20:49:01 2014 +0000

    Fix test/element-test.js
---
 lib/sax/sax_ltx.js   |  21 ++--
 test/element-test.js | 343 +++++++++++++++++++++++++--------------------------
 2 files changed, 181 insertions(+), 183 deletions(-)

diff --git a/lib/sax/sax_ltx.js b/lib/sax/sax_ltx.js
index 5c5b737..b71a455 100644
--- a/lib/sax/sax_ltx.js
+++ b/lib/sax/sax_ltx.js
@@ -12,9 +12,6 @@ var STATE_TEXT = 0,
     STATE_ATTR_QUOT = 6,
     STATE_ATTR_VALUE = 7
 
-var RE_TAG_NAME = /^[^\s\/>]+$/,
-    RE_ATTR_NAME = /^[^\s=]+$/
-
 var SaxLtx = module.exports = function SaxLtx() {
     events.EventEmitter.call(this)
 
@@ -80,11 +77,13 @@ var SaxLtx = module.exports = function SaxLtx() {
             case STATE_TAG:
                 if (c === 62 /* > */) {
                     if (!endTag) {
-                    this.emit('startElement', tagName, attrs)
-                    if (selfClosing)
+                        this.emit('startElement', tagName, attrs)
+                        if (selfClosing) {
+                            this.emit('endElement', tagName)
+                        }
+                    } else {
                         this.emit('endElement', tagName)
-                    } else
-                    this.emit('endElement', tagName)
+                    }
                     tagName = undefined
                     attrs = undefined
                     endTag = undefined
@@ -146,12 +145,12 @@ util.inherits(SaxLtx, events.EventEmitter)
 
 
 SaxLtx.prototype.end = function(data) {
-    if (data)
-    this.write(data)
+    if (data) {
+        this.write(data)
+    }
 
     /* Uh, yeah */
-    this.write = function() {
-    }
+    this.write = function() {}
 }
 
 function unescapeXml(s) {
diff --git a/test/element-test.js b/test/element-test.js
index 8123e0f..4a7d759 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -5,185 +5,184 @@ var vows = require('vows')
   , ltx = require('./../lib/index')
 
 vows.describe('ltx').addBatch({
-  'serialization': {
-    'serialize an element': function() {
-      var e = new ltx.Element('e');
-      assert.equal(e.toString(), '<e/>');
-    },
-    'serialize an element with attributes': function() {
-      var e = new ltx.Element('e',
-                              { a1: 'foo' });
-      assert.equal(e.toString(), '<e a1="foo"/>');
-    },
-    'serialize an element with attributes to entities': function() {
-      var e = new ltx.Element('e',
-                              { a1: '"well"' });
-      assert.equal(e.toString(), '<e a1=""well""/>');
-    },
-    'serialize an element with text': function() {
-      var e = new ltx.Element('e').t('bar').root();
-      assert.equal(e.toString(), '<e>bar</e>');
-    },
-    'serialize an element with text to entities': function() {
-      var e = new ltx.Element('e').t('1 < 2').root();
-      assert.equal(e.toString(), '<e>1 < 2</e>');
-    },
-    'serialize an element with a number attribute': function() {
-      var e = new ltx.Element('e', { a: 23 });
-      assert.equal(e.toString(), '<e a="23"/>');
-    },
-    'serialize an element with number contents': function() {
-      var e = new ltx.Element('e');
-      e.c('foo').t(23);
-      e.c('bar').t(0);
-      assert.equal(e.toString(), '<e><foo>23</foo><bar>0</bar></e>');
-    },
-    'serialize with undefined attribute': function() {
-      var e = new ltx.Element('e', { foo: undefined });
-      assert.equal(e.toString(), '<e/>');
-    },
-    'serialize with null attribute': function() {
-      var e = new ltx.Element('e', { foo: null });
-      assert.equal(e.toString(), '<e/>');
-    },
-    'serialize with number attribute': function() {
-      var e = new ltx.Element('e', { foo: 23, bar: 0 });
-      var s = e.toString();
-      assert.ok(s.match(/foo="23"/));
-      assert.ok(s.match(/bar="0"/));
-    },
-    'serialize with undefined child': function() {
-      var e = new ltx.Element('e');
-      e.children = [undefined];
-      assert.equal(e.toString(), '<e></e>');
-    },
-    'serialize with null child': function() {
-      var e = new ltx.Element('e');
-      e.children = [null];
-      assert.equal(e.toString(), '<e></e>');
-    },
-    'serialize with integer text': function() {
-      var e = new ltx.Element('e').t(1000)
-      assert.equal(e.getText(), 1000)
-    }
-  },
+    'serialization': {
+        'serialize an element': function() {
+            var e = new ltx.Element('e')
+            assert.equal(e.toString(), '<e/>')
+        },
+        'serialize an element with attributes': function() {
+            var e = new ltx.Element('e', { a1: 'foo' })
+            assert.equal(e.toString(), '<e a1="foo"/>')
+        },
+        'serialize an element with attributes to entities': function() {
+            var e = new ltx.Element('e', { a1: '"well"' })
+            assert.equal(e.toString(), '<e a1=""well""/>')
+        },
+        'serialize an element with text': function() {
+            var e = new ltx.Element('e').t('bar').root()
+            assert.equal(e.toString(), '<e>bar</e>')
+        },
+        'serialize an element with text to entities': function() {
+            var e = new ltx.Element('e').t('1 < 2').root()
+            assert.equal(e.toString(), '<e>1 &lt 2</e>')
+        },
+        'serialize an element with a number attribute': function() {
+            var e = new ltx.Element('e', { a: 23 })
+            assert.equal(e.toString(), '<e a="23"/>')
+        },
+        'serialize an element with number contents': function() {
+            var e = new ltx.Element('e')
+            e.c('foo').t(23)
+            e.c('bar').t(0)
+            assert.equal(e.toString(), '<e><foo>23</foo><bar>0</bar></e>')
+        },
+        'serialize with undefined attribute': function() {
+            var e = new ltx.Element('e', { foo: undefined })
+            assert.equal(e.toString(), '<e/>')
+        },
+        'serialize with null attribute': function() {
+            var e = new ltx.Element('e', { foo: null })
+            assert.equal(e.toString(), '<e/>')
+        },
+        'serialize with number attribute': function() {
+            var e = new ltx.Element('e', { foo: 23, bar: 0 })
+            var s = e.toString()
+            assert.ok(s.match(/foo="23"/))
+            assert.ok(s.match(/bar="0"/))
+        },
+        'serialize with undefined child': function() {
+            var e = new ltx.Element('e')
+            e.children = [undefined]
+            assert.equal(e.toString(), '<e></e>')
+        },
+        'serialize with null child': function() {
+            var e = new ltx.Element('e')
+            e.children = [null]
+            assert.equal(e.toString(), '<e></e>')
+        },
+        'serialize with integer text': function() {
+            var e = new ltx.Element('e').t(1000)
+            assert.equal(e.getText(), 1000)
+        }
+    },
+    'remove': {
+        'by element': function() {
+            var el = new ltx.Element('e').
+            c('c').c('x').up().up().
+            c('c2').up().
+            c('c').up()
+            el.remove(el.getChild('c'))
+            assert.equal(el.getChildren('c').length, 1)
+            assert.equal(el.getChildren('c2').length, 1)
+        },
+        'by name': function() {
+            var el = new ltx.Element('e').
+            c('c').up().
+            c('c2').up().
+            c('c').up()
+            el.remove('c')
+            assert.equal(el.getChildren('c').length, 0)
+            assert.equal(el.getChildren('c2').length, 1)
+        }
+    },
+    'getAttr': {
+        'without ns': function() {
+            var stanza = '<team xmlns:job="http://site.tld/job">' +
+                '<person name="julien" job:title="hacker" /></team>'
+            var doc = ltx.parse(stanza)
+            var el = doc.getChild('person')
+            assert.equal(el.getAttr('name'), 'julien')
+        },
+        'with ns': function() {
+            var stanza = '<team xmlns:job="http://site.tld/job">' +
+                '<person name="julien" job:title="hacker" /></team>'
+            var doc = ltx.parse(stanza)
+            var el = doc.getChild('person')
+            assert.equal(el.getAttr('title', 'http://site.tld/job'), 'hacker')
+        }
+    },
+    'clone': {
+        'clones': function() {
+            var orig = new ltx.Element('msg', { type: 'get' }).
+            c('content').t('foo').root()
+            var clone = orig.clone()
+            assert.equal(clone.name, orig.name)
+            assert.equal(clone.attrs.type, orig.attrs.type)
+            assert.equal(clone.attrs.to, orig.attrs.to)
+            assert.equal(clone.children.length, orig.children.length)
+            assert.equal(clone.getChildText('content'), orig.getChildText('content'))
 
-  'remove': {
-    'by element': function() {
-      var el = new ltx.Element('e').
-      c('c').c('x').up().up().
-      c('c2').up().
-      c('c').up();
-      el.remove(el.getChild('c'));
-      assert.equal(el.getChildren('c').length, 1);
-      assert.equal(el.getChildren('c2').length, 1);
-    },
-    'by name': function() {
-      var el = new ltx.Element('e').
-      c('c').up().
-      c('c2').up().
-      c('c').up();
-      el.remove('c');
-      assert.equal(el.getChildren('c').length, 0);
-      assert.equal(el.getChildren('c2').length, 1);
-    }
-  },
+            assert.equal(orig.getChild('content').up(), orig)
+            assert.equal(clone.getChild('content').up(), clone)
+        },
+        'mod attr': function() {
+            var orig = new ltx.Element('msg', { type: 'get' })
+            var clone = orig.clone()
+            clone.attrs.type += '-result'
 
-  'getAttr': {
-    'without ns': function() {
-      var doc = ltx.parse('<team xmlns:job="http://site.tld/job"><person name="julien" job:title="hacker" /></team>');
-      var el = doc.getChild("person");
-      assert.equal(el.getAttr('name'), 'julien');
-    },
-    'with ns': function() {
-      var doc = ltx.parse('<team xmlns:job="http://site.tld/job"><person name="julien" job:title="hacker" /></team>');
-      var el = doc.getChild("person");
-      assert.equal(el.getAttr('title', 'http://site.tld/job'), 'hacker');
-    }
-  },
+            assert.equal(orig.attrs.type, 'get')
+            assert.equal(clone.attrs.type, 'get-result')
+        },
+        'rm attr': function() {
+            var orig = new ltx.Element('msg', { from: 'me' })
+            var clone = orig.clone()
+            delete clone.attrs.from
+            clone.attrs.to = 'you'
 
-  'clone': {
-    'clones': function() {
-      var orig = new ltx.Element('msg', { type: 'get' }).
-      c('content').t('foo').root();
-      var clone = orig.clone();
-      assert.equal(clone.name, orig.name);
-      assert.equal(clone.attrs.type, orig.attrs.type);
-      assert.equal(clone.attrs.to, orig.attrs.to);
-      assert.equal(clone.children.length, orig.children.length);
-      assert.equal(clone.getChildText('content'), orig.getChildText('content'));
+            assert.equal(orig.attrs.from, 'me')
+            assert.equal(orig.attrs.to, undefined)
+            assert.equal(clone.attrs.from, undefined)
+            assert.equal(clone.attrs.to, 'you')
+        },
+        'mod child': function() {
+            var orig = new ltx.Element('msg', { type: 'get' }).
+            c('content').t('foo').root()
+            var clone = orig.clone()
+            clone.getChild('content').t('bar').name = 'description'
 
-      assert.equal(orig.getChild('content').up(), orig);
-      assert.equal(clone.getChild('content').up(), clone);
+            assert.equal(orig.children[0].name, 'content')
+            assert.equal(orig.getChildText('content'), 'foo')
+            assert.equal(clone.children[0].name, 'description')
+            assert.equal(clone.getChildText('description'), 'foobar')
+        }
     },
-    'mod attr': function() {
-      var orig = new ltx.Element('msg', { type: 'get' });
-      var clone = orig.clone();
-      clone.attrs.type += '-result';
 
-      assert.equal(orig.attrs.type, 'get');
-      assert.equal(clone.attrs.type, 'get-result');
-    },
-    'rm attr': function() {
-      var orig = new ltx.Element('msg', { from: 'me' });
-      var clone = orig.clone();
-      delete clone.attrs.from;
-      clone.attrs.to = 'you';
+    'recursive': {
+        'getChildrenByAttr': function() {
+            var el = new ltx.Element('a')
+            .c('b')
+            .c('c', {myProperty:'x'}).t('bar').up().up().up()
+            .c('d', {id: 'x'})
+            .c('e', {myProperty:'x'}).root()
 
-      assert.equal(orig.attrs.from, 'me');
-      assert.equal(orig.attrs.to, undefined);
-      assert.equal(clone.attrs.from, undefined);
-      assert.equal(clone.attrs.to, 'you');
+            var results = el.getChildrenByAttr('myProperty', 'x', null, true)
+            assert.equal( results[0].toString(), '<c myProperty="x">bar</c>')
+            assert.equal( results[1].toString(), '<e myProperty="x"/>')
+        },
+        'getChildByAttr': function() {
+            var el = new ltx.Element('a')
+            .c('b')
+            .c('c', {id:'x'})
+            .t('bar').root()
+            assert.equal(el.getChildByAttr('id', 'x', null, true).toString(), '<c id="x">bar</c>')
+        }
     },
-    'mod child': function() {
-      var orig = new ltx.Element('msg', { type: 'get' }).
-      c('content').t('foo').root();
-      var clone = orig.clone();
-      clone.getChild('content').t('bar').name = 'description';
 
-      assert.equal(orig.children[0].name, 'content');
-      assert.equal(orig.getChildText('content'), 'foo');
-      assert.equal(clone.children[0].name, 'description');
-      assert.equal(clone.getChildText('description'), 'foobar');
+    'issue #15: Inconsistency with prefixed elements': {
+        topic: function() {
+            return ltx.parse('<root><x:foo>bar</x:foo></root>')
+        },
+        'getChildText prefixed': function(el) {
+            assert.equal(el.getChildText('x:foo'), null)
+        },
+        'getChildText unprefixed': function(el) {
+            assert.equal(el.getChildText('foo'), 'bar')
+        },
+        'getChild prefixed': function(el) {
+            assert.equal(el.getChild('x:foo'), null)
+        },
+        'getChild unprefixed': function(el) {
+            assert.equal(el.getChild('foo').getText(), 'bar')
+        }
     }
-  },
-
-  'recursive': {
-    'getChildrenByAttr': function() {
-      var el = new ltx.Element('a')
-      .c('b')
-      .c('c', {myProperty:'x'}).t('bar').up().up().up()
-      .c('d', {id: 'x'})
-      .c('e', {myProperty:'x'}).root();
-
-      var results = el.getChildrenByAttr('myProperty', 'x', null, true);
-      assert.equal( results[0].toString(), '<c myProperty="x">bar</c>');
-      assert.equal( results[1].toString(), '<e myProperty="x"/>');
-    },
-    'getChildByAttr': function() {
-      var el = new ltx.Element('a')
-      .c('b')
-      .c('c', {id:'x'})
-      .t('bar').root();
-      assert.equal(el.getChildByAttr('id', 'x', null, true).toString(), '<c id="x">bar</c>');
-    }
-  },
-
-  "issue #15: Inconsistency with prefixed elements": {
-    topic: function() {
-     return ltx.parse('<root><x:foo>bar</x:foo></root>');
-   },
-   "getChildText prefixed": function(el) {
-     assert.equal(el.getChildText('x:foo'), null);
-   },
-   "getChildText unprefixed": function(el) {
-     assert.equal(el.getChildText('foo'), 'bar');
-   },
-   "getChild prefixed": function(el) {
-     assert.equal(el.getChild('x:foo'), null);
-   },
-   "getChild unprefixed": function(el) {
-     assert.equal(el.getChild('foo').getText(), 'bar');
-   }
- }
-}).export(module);
+}).export(module)
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list