[Pkg-javascript-commits] [ltx] 193/469: serialize 0 children + tests

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:02:23 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 f5f48696e997da9dd20089b31f2697a8444f3a0b
Author: Astro <astro at spaceboyz.net>
Date:   Thu Dec 15 16:12:36 2011 +0100

    serialize 0 children + tests
---
 lib/element.js       |  2 +-
 test/element-test.js | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index c1080c8..14d0c11 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -216,7 +216,7 @@ Element.prototype.write = function(writer) {
 	for(var i = 0; i < this.children.length; i++) {
 	    var child = this.children[i];
 	    /* Skip null/undefined */
-	    if (child) {
+	    if (child || child === 0) {
 		if (child.write)
 		    child.write(writer);
 		else if (typeof child === 'string')
diff --git a/test/element-test.js b/test/element-test.js
index ad204ab..2de09e9 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -31,8 +31,10 @@ vows.describe('ltx').addBatch({
 	    assert.equal(e.toString(), '<e a="23"/>');
 	},
 	'serialize an element with number contents': function() {
-	    var e = new ltx.Element('e').t(23);
-	    assert.equal(e.toString(), '<e>23</e>');
+	    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 });
@@ -42,6 +44,12 @@ vows.describe('ltx').addBatch({
 	    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];

-- 
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