1. Stephen McKamey
  2. duel

Commits

Stephen McKamey  committed f197132

- fixing test and resource paths

  • Participants
  • Parent commits e2bdc7c
  • Branches default

Comments (0)

Files changed (10)

File duel/dueljs/src/test/javascript/bindTests.js

View file
+try{
+
+module("duel(data)");
+
+test("static view", function() {
+
+	var expected =
+		["div", { "class" : "list", "style" : "color:blue" },
+			["h2", "This is the title"],
+			["ul",
+				["li", { "class" : "item" },
+					["b", "Example"],
+					": ",
+					["i", "First!"]
+				],
+				["li", { "class" : "item" },
+					["b", "Sample"],
+					": ",
+					["i", "Last!"]
+				]
+			]
+		];
+
+	var actual = duel(expected)().value;
+
+	same(actual, expected, "");
+});
+
+test("simple expressions", function() {
+
+	var data = {
+	        name: "Foo.js",
+	        url: "http://example.com/foo.js",
+	        size: 5.87,
+	        datestamp: new Date(1291486489939),
+	        details: "Lorem ipsum dolor sit amet"
+	    };
+
+	var view = duel(
+		["div", { "class" : "download" },
+			["h2",
+			 	"Filename: ",
+				function(data, index, count) { return data.name; }
+			],
+			["p",
+			 	"URL: ",
+			 	["a", { "href" : function(data, index, count) { return data.url; }, "target" : "_blank" },
+			 	 	function(data, index, count) { return data.url ;}
+			 	],
+			 	" (",
+			 	function(data, index, count) { return data.size ;},
+			 	"KB)"
+		 	],
+			["p",
+			 	"DateStamp: ",
+			 	function(data, index, count) { return data.datestamp; }
+			],
+			["p",
+			 	"Description: ",
+			 	function(data, index, count) { return data.details; }
+			]
+		]);
+
+	var actual = view(data).value;
+
+	var expected = 
+		["div", { "class" : "download" },
+			["h2",
+			 	"Filename: Foo.js"
+			],
+			["p",
+			 	"URL: ",
+			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank" },
+			 		"http://example.com/foo.js"
+		 		],
+			 	" (5.87KB)"
+		 	],
+			["p",
+			 	"DateStamp: 2010-12-04 18:14:49 Z"
+			],
+			["p",
+			 	"Description: Lorem ipsum dolor sit amet"
+			]
+		];
+
+	same(actual, expected, "");
+});
+
+test("simple orphaned if/else", function() {
+
+	var view = duel(
+		["",
+		 	["$if", { "test" : function(data, index, count) { return data.name === "Example"; } },
+		 	 	["p", "True: Example === ", function(data, index, count) { return data.name; } ]
+		 	],
+		 	["$if", { "test" : function(data, index, count) { return data.name !== "Example"; } },
+		 	 	["p", "False: Example !== ", function(data, index, count) { return data.name; } ]
+		 	],
+		 	["$if",
+		 	 	["p", "Both: orphaned else always executes" ]
+		 	]
+		]);
+
+	var data1 = { name: "Example" };
+	var actual1 = view(data1).value;
+	var expected1 =
+		["",
+		 	["p", "True: Example === Example"],
+		 	["p", "Both: orphaned else always executes" ]
+		];
+
+	same(actual1, expected1, "Binding with simple if statements.");
+
+	var data2 = { name: "Sample" };
+	var actual2 = view(data2).value;
+	var expected2 =
+		["",
+		 	["p", "False: Example !== Sample"],
+		 	["p", "Both: orphaned else always executes" ]
+		];
+
+	same(actual2, expected2, "");
+});
+
+test("XOR block", function() {
+
+	var view = duel(
+	 	["$xor",
+		 	["$if", { "test" : function(data, index, count) { return !data.children || !data.children.length; } },
+		 	 	["p", "Has no items."]
+		 	],
+		 	["$if", { "test" : function(data, index, count) { return data.children && data.children.length === 1; } },
+		 	 	["p", "Has only one item."]
+		 	],
+		 	["$if",
+		 	 	["p", "Has ", function(data, index, count) { return data.children.length; }, " items."]
+		 	]
+	 	]);
+
+	var data1 = { name: "Three", children: [0,2,4] };
+	var actual1 = view(data1).value;
+	var expected1 = ["p", "Has 3 items."];
+
+	same(actual1, expected1, "Binding with choose block.");
+
+	var data2 = { name: "One", children: [42] };
+	var actual2 = view(data2).value;
+	var expected2 = ["p", "Has only one item."];
+
+	same(actual2, expected2, "Binding with choose block.");
+
+	var data3 = { name: "Zero", children: [] };
+	var actual3 = view(data3).value;
+	var expected3 = ["p", "Has no items."];
+
+	same(actual3, expected3, "");
+});
+
+test("for-each array", function() {
+
+	var data = {
+	        title: "This is the title",
+	        items: [
+	            { name: "One" },
+	            { name: "Two" },
+	            { name: "Three" },
+	            { name: "Four" },
+	            { name: "Five" }
+	        ]
+	    };
+
+	var view = duel(
+		["div", { "class" : "list", "style" : "color:blue" },
+			["h2",
+			 	function(data, index, count) { return data.title; }
+			],
+			["ul",
+			 	["$for", { "each" : function(data, index, count) { return data.items; } },
+					["li", { "class" : "item" },
+						["b",
+						 	function(data, index, count) { return data.name; }
+						],
+						": ",
+						["i",
+						 	function(data, index, count) { return index + 1; },
+							" of ",
+							function(data, index, count) { return count; }
+						]
+					]
+			 	]
+			]
+		]);
+
+	var actual = view(data).value;
+
+	var expected =
+		["div", { "class" : "list", "style" : "color:blue" },
+			["h2", "This is the title"],
+			["ul",
+				["li", { "class" : "item" },
+					["b", "One"],
+					": ",
+					["i", "1 of 5"]
+				],
+				["li", { "class" : "item" },
+					["b", "Two"],
+					": ",
+					["i", "2 of 5" ]
+				],
+				["li", { "class" : "item" },
+					["b", "Three"],
+					": ",
+					["i", "3 of 5"]
+				],
+				["li", { "class" : "item" },
+					["b", "Four"],
+					": ",
+					["i", "4 of 5"]
+				],
+				["li", { "class" : "item" },
+					["b", "Five"],
+					": ",
+					["i", "5 of 5"]
+				]
+			]
+		];
+
+	same(actual, expected, "");
+});
+
+test("for-each primitive", function() {
+
+	var data = {
+	        title: "This is the title",
+	        items: "One"
+	    };
+
+	var view = duel(
+		["div", { "class" : "list", "style" : "color:blue" },
+			["h2",
+			 	function(data, index, count) { return data.title; }
+			],
+			["ul",
+			 	["$for", { "each" : function(data, index, count) { return data.items; } },
+					["li", { "class" : "item" },
+						["b",
+						 	function(data, index, count) { return data; }
+						],
+						": ",
+						["i",
+						 	function(data, index, count) { return index + 1; },
+							" of ",
+							function(data, index, count) { return count; }
+						]
+					]
+			 	]
+			]
+		]);
+
+	var actual = view(data).value;
+
+	var expected =
+		["div", { "class" : "list", "style" : "color:blue" },
+			["h2", "This is the title"],
+			["ul",
+				["li", { "class" : "item" },
+					["b", "One"],
+					": ",
+					["i", "1 of 1"]
+				]
+			]
+		];
+
+	same(actual, expected, "");
+});
+
+test("for-in object", function() {
+	var data = {
+	        name: "List of items",
+	        total: 5,
+	        items: [
+	            "One",
+	            "Two",
+	            "Three",
+	            "Four",
+	            "Five"
+	        ]
+	    };
+
+	var view = duel(
+		["",
+		 	"data => ",
+		 	["dl",
+				["$for", { "in" : function(data) { return data; } },
+				 	["dt",
+					 	function(data, index) { return index; },
+					 	" of ",
+					 	function(data, index, count) { return count; },
+					 	" - ",
+					 	function(data, index, count, key) { return key; },
+					 	" : "],
+					["dd",
+					 	"(",
+					 	function(data) { return (data instanceof Array) ? "array" : typeof data; },
+					 	") ",
+					 	function(data) { return "" + data; }
+				 	]
+			 	]
+		 	]
+	 	]);
+
+	var actual = view(data).value;
+
+	var expected =
+		["",
+		 	"data => ",
+		 	["dl",
+		 	 	["dt", "0 of 3 - name : "],
+		 	 	["dd", "(string) List of items"],
+		 	 	["dt", "1 of 3 - total : "],
+		 	 	["dd", "(number) 5"],
+		 	 	["dt", "2 of 3 - items : "],
+				["dd", "(array) One,Two,Three,Four,Five"]
+		 	]
+	 	];
+
+	same(actual, expected, "");
+});
+
+test("for-count", function() {
+	var data = {
+	        name: "List of items",
+	        total: 5,
+	        items: [
+	            "One",
+	            "Two",
+	            "Three",
+	            "Four",
+	            "Five"
+	        ]
+	    };
+
+	var view = duel(
+		["",
+		 	"list => ",
+		 	["dl",
+				["$for", {
+						"count" : function(data, index, count) { return 4; },
+						"data" : function(data, index, count) { return data.name; }
+					},
+				 	["dt",
+					 	function(data, index, count) { return index; },
+					 	" of ",
+					 	function(data, index, count) { return count; },
+					 	": "],
+					["dd",
+					 	function(data, index, count) { return "" + data; }
+				 	]
+			 	]
+		 	]
+	 	]);
+
+	var actual = view(data).value;
+
+	var expected =
+		["",
+		 	"list => ",
+		 	["dl",
+		 	 	["dt", "0 of 4: "],
+		 	 	["dd", "List of items"],
+		 	 	["dt", "1 of 4: "],
+		 	 	["dd", "List of items"],
+		 	 	["dt", "2 of 4: "],
+		 	 	["dd", "List of items"],
+		 	 	["dt", "3 of 4: "],
+				["dd", "List of items"]
+		 	]
+	 	];
+
+	same(actual, expected, "");
+});
+
+test("markup data", function() {
+
+	var data = {
+	        details: "<blink>Lorem ipsum dolor sit amet</blink>"
+	    };
+
+	var view = duel(
+		["div", { "class" : "test" },
+			["p",
+			 	"Description: ",
+			 	function(data, index, count) { return duel.raw(data.details); }
+			]
+		]);
+
+	var actual = view(data).value;
+
+	var expected = 
+		["div", { "class" : "test" },
+			["p",
+			 	"Description: ",
+			 	duel.raw("<blink>Lorem ipsum dolor sit amet</blink>")
+			]
+		];
+
+	same(actual, expected, "");
+});
+
+test("array result", function() {
+
+	var data = {};
+
+	var view = duel(
+		["p",
+			/* http://stackoverflow.com/questions/4170978 */
+			"Should render \"fuel\" => \"",
+			function() { return ( (![]+[])[+[]]+(!![]+[])[+!+[]+!+[]]+(!![]+[])[+!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]] ); },
+			"\""
+		]);
+
+	var actual = view(data).value;
+
+	var expected = 
+		["p",
+		 	"Should render \"fuel\" => \"fuel\""
+		];
+
+	same(actual, expected, "");
+});
+
+test("call view", function() {
+
+	var data = {
+	        name: "Outer list",
+	        items: ["One", "Two", "Three"]
+	    };
+
+	var Foo = {
+			itemView: duel(
+					["li",
+					 	"data: ",
+					 	function(data, index, count) { return data; },
+					 	["br"],
+					 	"index: ",
+					 	function(data, index, count) { return index; },
+					 	["br"],
+					 	"count: ",
+					 	function(data, index, count) { return count; },
+					]),
+			listView: duel(
+					["div",
+					 	["h2", function(data, index, count) { return data.name; } ],
+						["ul",
+						 	["$for", { "each" : function(data, index, count) { return data.items; } },
+						 		["$call", {
+							 			"view" : function(data, index, count) { return Foo.itemView; },
+							 			"data" :  function(data, index, count) { return data; },
+							 			"index" :  function(data, index, count) { return index; },
+							 			"count" :  function(data, index, count) { return count; }
+						 			}
+						 		]
+						 	]
+						]
+					])
+			};
+
+	var actual = Foo.listView(data).value;
+
+	var expected = 
+		["div",
+		 	["h2", "Outer list" ],
+			["ul",
+				["li",
+					"data: One",
+					["br"],
+					"index: 0",
+					["br"],
+					"count: 3"
+				],
+				["li",
+					"data: Two",
+					["br"],
+					"index: 1",
+					["br"],
+					"count: 3"
+				],
+				["li",
+					"data: Three",
+					["br"],
+					"index: 2",
+					["br"],
+					"count: 3"
+				]
+			]
+		];
+
+	same(actual, expected, "");
+});
+
+test("call wrapper view", function() {
+
+	var data = {
+	        name: "Outer list",
+	        items: ["One", "Two", "Three"]
+	    };
+
+	var Foo = {
+			itemView: duel(
+					["li",
+					 	["$part", { "name" : "itemLayout" }]
+					]),
+			listView: duel(
+					["div",
+					 	["h2", function(data, index, count) { return data.name; } ],
+						["ul",
+						 	["$for", { "each" : function(data, index, count) { return data.items; } },
+						 		["$call", {
+							 			"view" : function(data, index, count) { return Foo.itemView; },
+							 			"data" :  function(data, index, count) { return data; },
+							 			"index" :  function(data, index, count) { return index; },
+							 			"count" :  function(data, index, count) { return count; }
+						 			},
+						 			["$part", { "name" : "itemLayout" },
+						 			 	"data: ",
+									 	function(data, index, count) { return data; },
+									 	["br"],
+									 	"index: ",
+									 	function(data, index, count) { return index; },
+									 	["br"],
+									 	"count: ",
+									 	function(data, index, count) { return count; }
+								 	]
+						 		]
+						 	]
+						]
+					])
+			};
+
+	var actual = Foo.listView(data).value;
+
+	var expected = 
+		["div",
+		 	["h2", "Outer list" ],
+			["ul",
+				["li",
+					"data: One",
+					["br"],
+					"index: 0",
+					["br"],
+					"count: 3"
+				],
+				["li",
+					"data: Two",
+					["br"],
+					"index: 1",
+					["br"],
+					"count: 3"
+				],
+				["li",
+					"data: Three",
+					["br"],
+					"index: 2",
+					["br"],
+					"count: 3"
+				]
+			]
+		];
+
+	same(actual, expected, "");
+});
+
+}catch(ex){alert(ex);}

File duel/dueljs/src/test/javascript/domTests.js

View file
+try {
+
+module("Result.toDOM()");
+
+test("nested elements with attributes", function() {
+
+	var view = duel(
+		["div", { "class" : "download" },
+			["h2",
+			 	"Filename: Foo.js"
+			],
+			["p",
+			 	"URL: ",
+			 	["br"],
+			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
+			 		"http://example.com/foo.js"
+		 		],
+			 	" (5.87KB)"
+		 	],
+		 	["hr"],
+			["p",
+			 	"Description: Lorem ipsum dolor sit amet"
+			]
+		]);
+
+	var actual = view().toDOM();
+
+	var temp, expected = document.createElement("div");
+	expected.className = "download";
+
+	temp = document.createElement("h2");
+	temp.appendChild(document.createTextNode("Filename: Foo.js"));
+	expected.appendChild(temp);
+
+	temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("URL: "));
+	temp.appendChild(document.createElement("br"));
+	var temp2 = document.createElement("a");
+	temp2.setAttribute("href", "http://example.com/foo.js");
+	temp2.setAttribute("target", "_blank");
+	temp2.setAttribute("title", "Lorem ipsum dolor sit amet");
+	temp2.appendChild(document.createTextNode("http://example.com/foo.js"));
+	temp.appendChild(temp2);
+	temp.appendChild(document.createTextNode(" (5.87KB)"));
+	expected.appendChild(temp);
+
+	expected.appendChild(document.createElement("hr"));
+
+	temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("Description: Lorem ipsum dolor sit amet"));
+	expected.appendChild(temp);
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("docFrag root", function() {
+
+	var view = duel(
+		["",
+		 	["p", "Inner child one."],
+		 	["p", "Inner child two." ]
+		]);
+
+	var actual = view().toDOM();
+
+	var expected = document.createDocumentFragment();
+
+	var temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("Inner child one."));
+	expected.appendChild(temp);
+
+	temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("Inner child two."));
+	expected.appendChild(temp);
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("docFrag inner", function() {
+
+	var view = duel(
+		["div",
+			["",
+			 	["p", "Inner child one."],
+			 	["p", "Inner child two." ]
+			]
+		]);
+
+	var actual = view().toDOM();
+
+	var expected = document.createElement("div");
+
+	var temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("Inner child one."));
+	expected.appendChild(temp);
+
+	temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("Inner child two."));
+	expected.appendChild(temp);
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("markup data", function() {
+
+	var view = duel(
+		["div", { "class" : "test" },
+			["p",
+			 	"Description: ",
+			 	duel.raw("<b>Lorem </b>"),
+			 	duel.raw("<blink>ipsum</blink>"),
+			 	" ",
+			 	duel.raw("<i>dolor sit amet</i>")
+			]
+		]);
+
+	var actual = view().toDOM();
+
+	var expected = document.createElement("div");
+	expected.className = "test";
+
+	var temp = document.createElement("p");
+	temp.appendChild(document.createTextNode("Description: "));
+
+	var temp2 = document.createElement("div");
+	temp2.innerHTML = "<b>Lorem </b>";
+	while (temp2.firstChild) {
+		temp.appendChild(temp2.firstChild);
+	}
+	temp2.innerHTML = "<blink>ipsum</blink>";
+	while (temp2.firstChild) {
+		temp.appendChild(temp2.firstChild);
+	}
+
+	temp.appendChild(document.createTextNode(" "));
+	temp2.innerHTML = "<i>dolor sit amet</i>";
+	while (temp2.firstChild) {
+		temp.appendChild(temp2.firstChild);
+	}
+
+	expected.appendChild(temp);
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("falsey attribute values", function() {
+
+	var view = duel(
+		["div", { "data-str" : "", "data-num" : 0, "data-bool" : false, "data-null" : null, "data-undef" : undefined },
+		 	"Lorem ipsum"
+		]);
+
+	var actual = view().toDOM();
+
+	var expected = document.createElement("div");
+	expected.setAttribute("data-str", "");
+	expected.setAttribute("data-num", 0);
+	expected.setAttribute("data-bool", false);
+	expected.setAttribute("data-null", "");
+	expected.setAttribute("data-undef", "");
+	expected.appendChild(document.createTextNode("Lorem ipsum"));
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("comment nodes", function() {
+
+	var view = duel(
+		["div",
+		 	["!",
+		 	 	"Comment before"],
+		 	"Lorem ipsum",
+		 	["!",
+		 	 	"Comment after"]
+		]);
+
+	var actual = view().toDOM();
+
+	var expected = document.createElement("div");
+	expected.appendChild(document.createComment("Comment before"));
+	expected.appendChild(document.createTextNode("Lorem ipsum"));
+	expected.appendChild(document.createComment("Comment after"));
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("ignore doctype node", function() {
+
+	var view = duel(
+		["",
+		 	["!DOCTYPE",
+		 	 	"html"],
+	 	 	"\n",
+			["html",
+			 	["body",
+			 	 	"Lorem ipsum."]
+			]
+	 	]);
+
+	var actual = view().toDOM();
+
+	var expected = document.createElement("html");
+	var temp = document.createElement("body");
+	temp.appendChild(document.createTextNode("Lorem ipsum."));
+	expected.appendChild(temp);
+
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+test("deferred attribute binding", function() {
+
+	var attrs = {
+		"class" : function() { return "hello"; },
+		"data-foo" : function() { return "foo"; }
+	};
+
+	var id = "__"+new Date().valueOf();
+
+	var expected = document.createElement("div");
+	expected.setAttribute("id", id);
+	expected.appendChild(document.createTextNode("Lorem ipsum"));
+	expected.setAttribute("class", "hello");
+	expected.setAttribute("data-foo", "foo");
+
+	var actual = document.createElement("div");
+	actual.setAttribute("id", id);
+	actual.appendChild(document.createTextNode("Lorem ipsum"));
+
+	duel.attr(actual, attrs);
+	
+	same(toHTML(actual), toHTML(expected), "");
+});
+
+}catch(ex){alert(ex);}

File duel/dueljs/src/test/javascript/js/bindTests.js

-try{
-
-module("duel(data)");
-
-test("static view", function() {
-
-	var expected =
-		["div", { "class" : "list", "style" : "color:blue" },
-			["h2", "This is the title"],
-			["ul",
-				["li", { "class" : "item" },
-					["b", "Example"],
-					": ",
-					["i", "First!"]
-				],
-				["li", { "class" : "item" },
-					["b", "Sample"],
-					": ",
-					["i", "Last!"]
-				]
-			]
-		];
-
-	var actual = duel(expected)().value;
-
-	same(actual, expected, "");
-});
-
-test("simple expressions", function() {
-
-	var data = {
-	        name: "Foo.js",
-	        url: "http://example.com/foo.js",
-	        size: 5.87,
-	        datestamp: new Date(1291486489939),
-	        details: "Lorem ipsum dolor sit amet"
-	    };
-
-	var view = duel(
-		["div", { "class" : "download" },
-			["h2",
-			 	"Filename: ",
-				function(data, index, count) { return data.name; }
-			],
-			["p",
-			 	"URL: ",
-			 	["a", { "href" : function(data, index, count) { return data.url; }, "target" : "_blank" },
-			 	 	function(data, index, count) { return data.url ;}
-			 	],
-			 	" (",
-			 	function(data, index, count) { return data.size ;},
-			 	"KB)"
-		 	],
-			["p",
-			 	"DateStamp: ",
-			 	function(data, index, count) { return data.datestamp; }
-			],
-			["p",
-			 	"Description: ",
-			 	function(data, index, count) { return data.details; }
-			]
-		]);
-
-	var actual = view(data).value;
-
-	var expected = 
-		["div", { "class" : "download" },
-			["h2",
-			 	"Filename: Foo.js"
-			],
-			["p",
-			 	"URL: ",
-			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank" },
-			 		"http://example.com/foo.js"
-		 		],
-			 	" (5.87KB)"
-		 	],
-			["p",
-			 	"DateStamp: 2010-12-04 18:14:49 Z"
-			],
-			["p",
-			 	"Description: Lorem ipsum dolor sit amet"
-			]
-		];
-
-	same(actual, expected, "");
-});
-
-test("simple orphaned if/else", function() {
-
-	var view = duel(
-		["",
-		 	["$if", { "test" : function(data, index, count) { return data.name === "Example"; } },
-		 	 	["p", "True: Example === ", function(data, index, count) { return data.name; } ]
-		 	],
-		 	["$if", { "test" : function(data, index, count) { return data.name !== "Example"; } },
-		 	 	["p", "False: Example !== ", function(data, index, count) { return data.name; } ]
-		 	],
-		 	["$if",
-		 	 	["p", "Both: orphaned else always executes" ]
-		 	]
-		]);
-
-	var data1 = { name: "Example" };
-	var actual1 = view(data1).value;
-	var expected1 =
-		["",
-		 	["p", "True: Example === Example"],
-		 	["p", "Both: orphaned else always executes" ]
-		];
-
-	same(actual1, expected1, "Binding with simple if statements.");
-
-	var data2 = { name: "Sample" };
-	var actual2 = view(data2).value;
-	var expected2 =
-		["",
-		 	["p", "False: Example !== Sample"],
-		 	["p", "Both: orphaned else always executes" ]
-		];
-
-	same(actual2, expected2, "");
-});
-
-test("XOR block", function() {
-
-	var view = duel(
-	 	["$xor",
-		 	["$if", { "test" : function(data, index, count) { return !data.children || !data.children.length; } },
-		 	 	["p", "Has no items."]
-		 	],
-		 	["$if", { "test" : function(data, index, count) { return data.children && data.children.length === 1; } },
-		 	 	["p", "Has only one item."]
-		 	],
-		 	["$if",
-		 	 	["p", "Has ", function(data, index, count) { return data.children.length; }, " items."]
-		 	]
-	 	]);
-
-	var data1 = { name: "Three", children: [0,2,4] };
-	var actual1 = view(data1).value;
-	var expected1 = ["p", "Has 3 items."];
-
-	same(actual1, expected1, "Binding with choose block.");
-
-	var data2 = { name: "One", children: [42] };
-	var actual2 = view(data2).value;
-	var expected2 = ["p", "Has only one item."];
-
-	same(actual2, expected2, "Binding with choose block.");
-
-	var data3 = { name: "Zero", children: [] };
-	var actual3 = view(data3).value;
-	var expected3 = ["p", "Has no items."];
-
-	same(actual3, expected3, "");
-});
-
-test("for-each array", function() {
-
-	var data = {
-	        title: "This is the title",
-	        items: [
-	            { name: "One" },
-	            { name: "Two" },
-	            { name: "Three" },
-	            { name: "Four" },
-	            { name: "Five" }
-	        ]
-	    };
-
-	var view = duel(
-		["div", { "class" : "list", "style" : "color:blue" },
-			["h2",
-			 	function(data, index, count) { return data.title; }
-			],
-			["ul",
-			 	["$for", { "each" : function(data, index, count) { return data.items; } },
-					["li", { "class" : "item" },
-						["b",
-						 	function(data, index, count) { return data.name; }
-						],
-						": ",
-						["i",
-						 	function(data, index, count) { return index + 1; },
-							" of ",
-							function(data, index, count) { return count; }
-						]
-					]
-			 	]
-			]
-		]);
-
-	var actual = view(data).value;
-
-	var expected =
-		["div", { "class" : "list", "style" : "color:blue" },
-			["h2", "This is the title"],
-			["ul",
-				["li", { "class" : "item" },
-					["b", "One"],
-					": ",
-					["i", "1 of 5"]
-				],
-				["li", { "class" : "item" },
-					["b", "Two"],
-					": ",
-					["i", "2 of 5" ]
-				],
-				["li", { "class" : "item" },
-					["b", "Three"],
-					": ",
-					["i", "3 of 5"]
-				],
-				["li", { "class" : "item" },
-					["b", "Four"],
-					": ",
-					["i", "4 of 5"]
-				],
-				["li", { "class" : "item" },
-					["b", "Five"],
-					": ",
-					["i", "5 of 5"]
-				]
-			]
-		];
-
-	same(actual, expected, "");
-});
-
-test("for-each primitive", function() {
-
-	var data = {
-	        title: "This is the title",
-	        items: "One"
-	    };
-
-	var view = duel(
-		["div", { "class" : "list", "style" : "color:blue" },
-			["h2",
-			 	function(data, index, count) { return data.title; }
-			],
-			["ul",
-			 	["$for", { "each" : function(data, index, count) { return data.items; } },
-					["li", { "class" : "item" },
-						["b",
-						 	function(data, index, count) { return data; }
-						],
-						": ",
-						["i",
-						 	function(data, index, count) { return index + 1; },
-							" of ",
-							function(data, index, count) { return count; }
-						]
-					]
-			 	]
-			]
-		]);
-
-	var actual = view(data).value;
-
-	var expected =
-		["div", { "class" : "list", "style" : "color:blue" },
-			["h2", "This is the title"],
-			["ul",
-				["li", { "class" : "item" },
-					["b", "One"],
-					": ",
-					["i", "1 of 1"]
-				]
-			]
-		];
-
-	same(actual, expected, "");
-});
-
-test("for-in object", function() {
-	var data = {
-	        name: "List of items",
-	        total: 5,
-	        items: [
-	            "One",
-	            "Two",
-	            "Three",
-	            "Four",
-	            "Five"
-	        ]
-	    };
-
-	var view = duel(
-		["",
-		 	"data => ",
-		 	["dl",
-				["$for", { "in" : function(data) { return data; } },
-				 	["dt",
-					 	function(data, index) { return index; },
-					 	" of ",
-					 	function(data, index, count) { return count; },
-					 	" - ",
-					 	function(data, index, count, key) { return key; },
-					 	" : "],
-					["dd",
-					 	"(",
-					 	function(data) { return (data instanceof Array) ? "array" : typeof data; },
-					 	") ",
-					 	function(data) { return "" + data; }
-				 	]
-			 	]
-		 	]
-	 	]);
-
-	var actual = view(data).value;
-
-	var expected =
-		["",
-		 	"data => ",
-		 	["dl",
-		 	 	["dt", "0 of 3 - name : "],
-		 	 	["dd", "(string) List of items"],
-		 	 	["dt", "1 of 3 - total : "],
-		 	 	["dd", "(number) 5"],
-		 	 	["dt", "2 of 3 - items : "],
-				["dd", "(array) One,Two,Three,Four,Five"]
-		 	]
-	 	];
-
-	same(actual, expected, "");
-});
-
-test("for-count", function() {
-	var data = {
-	        name: "List of items",
-	        total: 5,
-	        items: [
-	            "One",
-	            "Two",
-	            "Three",
-	            "Four",
-	            "Five"
-	        ]
-	    };
-
-	var view = duel(
-		["",
-		 	"list => ",
-		 	["dl",
-				["$for", {
-						"count" : function(data, index, count) { return 4; },
-						"data" : function(data, index, count) { return data.name; }
-					},
-				 	["dt",
-					 	function(data, index, count) { return index; },
-					 	" of ",
-					 	function(data, index, count) { return count; },
-					 	": "],
-					["dd",
-					 	function(data, index, count) { return "" + data; }
-				 	]
-			 	]
-		 	]
-	 	]);
-
-	var actual = view(data).value;
-
-	var expected =
-		["",
-		 	"list => ",
-		 	["dl",
-		 	 	["dt", "0 of 4: "],
-		 	 	["dd", "List of items"],
-		 	 	["dt", "1 of 4: "],
-		 	 	["dd", "List of items"],
-		 	 	["dt", "2 of 4: "],
-		 	 	["dd", "List of items"],
-		 	 	["dt", "3 of 4: "],
-				["dd", "List of items"]
-		 	]
-	 	];
-
-	same(actual, expected, "");
-});
-
-test("markup data", function() {
-
-	var data = {
-	        details: "<blink>Lorem ipsum dolor sit amet</blink>"
-	    };
-
-	var view = duel(
-		["div", { "class" : "test" },
-			["p",
-			 	"Description: ",
-			 	function(data, index, count) { return duel.raw(data.details); }
-			]
-		]);
-
-	var actual = view(data).value;
-
-	var expected = 
-		["div", { "class" : "test" },
-			["p",
-			 	"Description: ",
-			 	duel.raw("<blink>Lorem ipsum dolor sit amet</blink>")
-			]
-		];
-
-	same(actual, expected, "");
-});
-
-test("array result", function() {
-
-	var data = {};
-
-	var view = duel(
-		["p",
-			/* http://stackoverflow.com/questions/4170978 */
-			"Should render \"fuel\" => \"",
-			function() { return ( (![]+[])[+[]]+(!![]+[])[+!+[]+!+[]]+(!![]+[])[+!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]] ); },
-			"\""
-		]);
-
-	var actual = view(data).value;
-
-	var expected = 
-		["p",
-		 	"Should render \"fuel\" => \"fuel\""
-		];
-
-	same(actual, expected, "");
-});
-
-test("call view", function() {
-
-	var data = {
-	        name: "Outer list",
-	        items: ["One", "Two", "Three"]
-	    };
-
-	var Foo = {
-			itemView: duel(
-					["li",
-					 	"data: ",
-					 	function(data, index, count) { return data; },
-					 	["br"],
-					 	"index: ",
-					 	function(data, index, count) { return index; },
-					 	["br"],
-					 	"count: ",
-					 	function(data, index, count) { return count; },
-					]),
-			listView: duel(
-					["div",
-					 	["h2", function(data, index, count) { return data.name; } ],
-						["ul",
-						 	["$for", { "each" : function(data, index, count) { return data.items; } },
-						 		["$call", {
-							 			"view" : function(data, index, count) { return Foo.itemView; },
-							 			"data" :  function(data, index, count) { return data; },
-							 			"index" :  function(data, index, count) { return index; },
-							 			"count" :  function(data, index, count) { return count; }
-						 			}
-						 		]
-						 	]
-						]
-					])
-			};
-
-	var actual = Foo.listView(data).value;
-
-	var expected = 
-		["div",
-		 	["h2", "Outer list" ],
-			["ul",
-				["li",
-					"data: One",
-					["br"],
-					"index: 0",
-					["br"],
-					"count: 3"
-				],
-				["li",
-					"data: Two",
-					["br"],
-					"index: 1",
-					["br"],
-					"count: 3"
-				],
-				["li",
-					"data: Three",
-					["br"],
-					"index: 2",
-					["br"],
-					"count: 3"
-				]
-			]
-		];
-
-	same(actual, expected, "");
-});
-
-test("call wrapper view", function() {
-
-	var data = {
-	        name: "Outer list",
-	        items: ["One", "Two", "Three"]
-	    };
-
-	var Foo = {
-			itemView: duel(
-					["li",
-					 	["$part", { "name" : "itemLayout" }]
-					]),
-			listView: duel(
-					["div",
-					 	["h2", function(data, index, count) { return data.name; } ],
-						["ul",
-						 	["$for", { "each" : function(data, index, count) { return data.items; } },
-						 		["$call", {
-							 			"view" : function(data, index, count) { return Foo.itemView; },
-							 			"data" :  function(data, index, count) { return data; },
-							 			"index" :  function(data, index, count) { return index; },
-							 			"count" :  function(data, index, count) { return count; }
-						 			},
-						 			["$part", { "name" : "itemLayout" },
-						 			 	"data: ",
-									 	function(data, index, count) { return data; },
-									 	["br"],
-									 	"index: ",
-									 	function(data, index, count) { return index; },
-									 	["br"],
-									 	"count: ",
-									 	function(data, index, count) { return count; }
-								 	]
-						 		]
-						 	]
-						]
-					])
-			};
-
-	var actual = Foo.listView(data).value;
-
-	var expected = 
-		["div",
-		 	["h2", "Outer list" ],
-			["ul",
-				["li",
-					"data: One",
-					["br"],
-					"index: 0",
-					["br"],
-					"count: 3"
-				],
-				["li",
-					"data: Two",
-					["br"],
-					"index: 1",
-					["br"],
-					"count: 3"
-				],
-				["li",
-					"data: Three",
-					["br"],
-					"index: 2",
-					["br"],
-					"count: 3"
-				]
-			]
-		];
-
-	same(actual, expected, "");
-});
-
-}catch(ex){alert(ex);}

File duel/dueljs/src/test/javascript/js/domTests.js

-try {
-
-module("Result.toDOM()");
-
-test("nested elements with attributes", function() {
-
-	var view = duel(
-		["div", { "class" : "download" },
-			["h2",
-			 	"Filename: Foo.js"
-			],
-			["p",
-			 	"URL: ",
-			 	["br"],
-			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
-			 		"http://example.com/foo.js"
-		 		],
-			 	" (5.87KB)"
-		 	],
-		 	["hr"],
-			["p",
-			 	"Description: Lorem ipsum dolor sit amet"
-			]
-		]);
-
-	var actual = view().toDOM();
-
-	var temp, expected = document.createElement("div");
-	expected.className = "download";
-
-	temp = document.createElement("h2");
-	temp.appendChild(document.createTextNode("Filename: Foo.js"));
-	expected.appendChild(temp);
-
-	temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("URL: "));
-	temp.appendChild(document.createElement("br"));
-	var temp2 = document.createElement("a");
-	temp2.setAttribute("href", "http://example.com/foo.js");
-	temp2.setAttribute("target", "_blank");
-	temp2.setAttribute("title", "Lorem ipsum dolor sit amet");
-	temp2.appendChild(document.createTextNode("http://example.com/foo.js"));
-	temp.appendChild(temp2);
-	temp.appendChild(document.createTextNode(" (5.87KB)"));
-	expected.appendChild(temp);
-
-	expected.appendChild(document.createElement("hr"));
-
-	temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("Description: Lorem ipsum dolor sit amet"));
-	expected.appendChild(temp);
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("docFrag root", function() {
-
-	var view = duel(
-		["",
-		 	["p", "Inner child one."],
-		 	["p", "Inner child two." ]
-		]);
-
-	var actual = view().toDOM();
-
-	var expected = document.createDocumentFragment();
-
-	var temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("Inner child one."));
-	expected.appendChild(temp);
-
-	temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("Inner child two."));
-	expected.appendChild(temp);
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("docFrag inner", function() {
-
-	var view = duel(
-		["div",
-			["",
-			 	["p", "Inner child one."],
-			 	["p", "Inner child two." ]
-			]
-		]);
-
-	var actual = view().toDOM();
-
-	var expected = document.createElement("div");
-
-	var temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("Inner child one."));
-	expected.appendChild(temp);
-
-	temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("Inner child two."));
-	expected.appendChild(temp);
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("markup data", function() {
-
-	var view = duel(
-		["div", { "class" : "test" },
-			["p",
-			 	"Description: ",
-			 	duel.raw("<b>Lorem </b>"),
-			 	duel.raw("<blink>ipsum</blink>"),
-			 	" ",
-			 	duel.raw("<i>dolor sit amet</i>")
-			]
-		]);
-
-	var actual = view().toDOM();
-
-	var expected = document.createElement("div");
-	expected.className = "test";
-
-	var temp = document.createElement("p");
-	temp.appendChild(document.createTextNode("Description: "));
-
-	var temp2 = document.createElement("div");
-	temp2.innerHTML = "<b>Lorem </b>";
-	while (temp2.firstChild) {
-		temp.appendChild(temp2.firstChild);
-	}
-	temp2.innerHTML = "<blink>ipsum</blink>";
-	while (temp2.firstChild) {
-		temp.appendChild(temp2.firstChild);
-	}
-
-	temp.appendChild(document.createTextNode(" "));
-	temp2.innerHTML = "<i>dolor sit amet</i>";
-	while (temp2.firstChild) {
-		temp.appendChild(temp2.firstChild);
-	}
-
-	expected.appendChild(temp);
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("falsey attribute values", function() {
-
-	var view = duel(
-		["div", { "data-str" : "", "data-num" : 0, "data-bool" : false, "data-null" : null, "data-undef" : undefined },
-		 	"Lorem ipsum"
-		]);
-
-	var actual = view().toDOM();
-
-	var expected = document.createElement("div");
-	expected.setAttribute("data-str", "");
-	expected.setAttribute("data-num", 0);
-	expected.setAttribute("data-bool", false);
-	expected.setAttribute("data-null", "");
-	expected.setAttribute("data-undef", "");
-	expected.appendChild(document.createTextNode("Lorem ipsum"));
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("comment nodes", function() {
-
-	var view = duel(
-		["div",
-		 	["!",
-		 	 	"Comment before"],
-		 	"Lorem ipsum",
-		 	["!",
-		 	 	"Comment after"]
-		]);
-
-	var actual = view().toDOM();
-
-	var expected = document.createElement("div");
-	expected.appendChild(document.createComment("Comment before"));
-	expected.appendChild(document.createTextNode("Lorem ipsum"));
-	expected.appendChild(document.createComment("Comment after"));
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("ignore doctype node", function() {
-
-	var view = duel(
-		["",
-		 	["!DOCTYPE",
-		 	 	"html"],
-	 	 	"\n",
-			["html",
-			 	["body",
-			 	 	"Lorem ipsum."]
-			]
-	 	]);
-
-	var actual = view().toDOM();
-
-	var expected = document.createElement("html");
-	var temp = document.createElement("body");
-	temp.appendChild(document.createTextNode("Lorem ipsum."));
-	expected.appendChild(temp);
-
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-test("deferred attribute binding", function() {
-
-	var attrs = {
-		"class" : function() { return "hello"; },
-		"data-foo" : function() { return "foo"; }
-	};
-
-	var id = "__"+new Date().valueOf();
-
-	var expected = document.createElement("div");
-	expected.setAttribute("id", id);
-	expected.appendChild(document.createTextNode("Lorem ipsum"));
-	expected.setAttribute("class", "hello");
-	expected.setAttribute("data-foo", "foo");
-
-	var actual = document.createElement("div");
-	actual.setAttribute("id", id);
-	actual.appendChild(document.createTextNode("Lorem ipsum"));
-
-	duel.attr(actual, attrs);
-	
-	same(toHTML(actual), toHTML(expected), "");
-});
-
-}catch(ex){alert(ex);}

File duel/dueljs/src/test/javascript/js/renderTests.js

-try {
-
-module("Result.toString()");
-
-test("nested elements with attributes", function() {
-
-	var view = duel(
-		["div", { "class" : "download" },
-			["h2",
-			 	"Filename: Foo.js"
-			],
-			["p",
-			 	"URL: ",
-			 	["br"],
-			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
-			 		"http://example.com/foo.js"
-		 		],
-			 	" (5.87KB)"
-		 	],
-		 	["hr"],
-			["p",
-			 	"Description: Lorem ipsum dolor sit amet"
-			]
-		]);
-
-	var actual = view().toString();
-
-	var expected =
-		'<div class="download"><h2>Filename: Foo.js</h2>'+
-		'<p>URL: <br /><a href="http://example.com/foo.js" target="_blank" title="Lorem ipsum dolor sit amet">http://example.com/foo.js</a> (5.87KB)</p>'+
-		'<hr />'+
-		'<p>Description: Lorem ipsum dolor sit amet</p>'+
-		'</div>';
-
-	same(actual, expected, "");
-});
-
-test("native toString", function() {
-
-	var view = duel(
-		["div", { "class" : "download" },
-			["h2",
-			 	"Filename: Foo.js"
-			],
-			["p",
-			 	"URL: ",
-			 	["br"],
-			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
-			 		"http://example.com/foo.js"
-		 		],
-			 	" (5.87KB)"
-		 	],
-		 	["hr"],
-			["p",
-			 	"Description: Lorem ipsum dolor sit amet"
-			]
-		]);
-
-	var actual = ""+view();
-
-	var expected =
-		'<div class="download"><h2>Filename: Foo.js</h2>'+
-		'<p>URL: <br /><a href="http://example.com/foo.js" target="_blank" title="Lorem ipsum dolor sit amet">http://example.com/foo.js</a> (5.87KB)</p>'+
-		'<hr />'+
-		'<p>Description: Lorem ipsum dolor sit amet</p>'+
-		'</div>';
-
-	same(actual, expected, "");
-});
-
-test("innerHTML toString", function() {
-
-	var view = duel(
-		["div", { "class" : "download" },
-			["h2",
-			 	"Filename: Foo.js"
-			],
-			["p",
-			 	"URL: ",
-			 	["br"],
-			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
-			 		"http://example.com/foo.js"
-		 		],
-			 	" (5.87KB)"
-		 	],
-		 	["hr"],
-			["p",
-			 	"Description: Lorem ipsum dolor sit amet"
-			]
-		]);
-
-	var actual = document.createElement("div");
-	actual.innerHTML = view();
-
-	var expected = document.createElement("div");
-	expected.innerHTML =
-		'<div class="download"><h2>Filename: Foo.js</h2>'+
-		'<p>URL: <br /><a href="http://example.com/foo.js" target="_blank" title="Lorem ipsum dolor sit amet">http://example.com/foo.js</a> (5.87KB)</p>'+
-		'<hr />'+
-		'<p>Description: Lorem ipsum dolor sit amet</p>'+
-		'</div>';
-
-	same(actual.innerHTML, expected.innerHTML, "");
-});
-
-test("docFrag root", function() {
-
-	var view = duel(
-		["",
-		 	["p", "Inner child one."],
-		 	["p", "Inner child two." ]
-		]);
-
-	var actual = view().toString();
-	var expected = '<p>Inner child one.</p><p>Inner child two.</p>';
-
-	same(actual, expected, "");
-});
-
-test("docFrag inner", function() {
-
-	var view = duel(
-		["div",
-			["",
-			 	["p", "Inner child one."],
-			 	["p", "Inner child two." ]
-			]
-		]);
-
-	var actual = view().toString();
-	var expected = '<div><p>Inner child one.</p><p>Inner child two.</p></div>';
-
-	same(actual, expected, "");
-});
-
-test("encoding literal", function() {
-
-	var view = duel(
-		["p",
-		 	'&hello"foo<bar><&>'
-		]);
-
-	var actual = view().toString();
-
-	var expected =  '<p>&amp;hello"foo&lt;bar&gt;&lt;&amp;&gt;</p>';
-	
-	same(actual, expected, "");
-});
-
-test("encoding attributes", function() {
-
-	var view = duel(
-		["p", { "title" : '&hello"foo<bar><&>' },
-		 	"Encoded attributes"
-		]);
-
-	var actual = view().toString();
-
-	var expected =  '<p title="&amp;hello&quot;foo&lt;bar&gt;&lt;&amp;&gt;">Encoded attributes</p>';
-	
-	same(actual, expected, "");
-});
-
-test("markup data", function() {
-
-	var view = duel(
-		["div", { "class" : "test" },
-			["p",
-			 	"Description: ",
-			 	duel.raw("<b>Lorem </b>"),
-			 	duel.raw("<blink>ipsum</blink>"),
-			 	" ",
-			 	duel.raw("<i>dolor sit amet</i>")
-			]
-		]);
-
-	var actual = view().toString();
-
-	var expected = 
-		'<div class="test">'+
-		'<p>Description: <b>Lorem </b><blink>ipsum</blink> <i>dolor sit amet</i></p>'+
-		'</div>';
-	same(actual, expected, "");
-});
-
-test("falsey attribute values", function() {
-
-	var view = duel(
-		["div", { "data-str" : "", "data-num" : 0, "data-bool" : false, "data-null" : null, "data-undef" : undefined },
-		 	"Lorem ipsum"
-		]);
-
-	var actual = view().toString();
-
-	var expected = 
-		'<div data-str="" data-num="0" data-bool="false" data-null data-undef>'+
-		'Lorem ipsum'+
-		'</div>';
-	same(actual, expected, "");
-});
-
-test("comment nodes", function() {
-
-	var view = duel(
-		["div",
-		 	["!",
-		 	 	"Comment before"],
-		 	"Lorem ipsum",
-		 	["!",
-		 	 	"Comment after"]
-		]);
-
-	var actual = view().toString();
-
-	var expected = 
-		'<div>'+
-		'<!--Comment before-->'+
-		'Lorem ipsum'+
-		'<!--Comment after-->'+
-		'</div>';
-	same(actual, expected, "");
-});
-
-test("doctype node", function() {
-
-	var view = duel(
-		["",
-		 	["!DOCTYPE",
-		 	 	"html"],
-	 	 	"\n",
-			["html",
-			 	["body",
-			 	 	"Lorem ipsum."]
-			]
-	 	]);
-
-	var actual = view().toString();
-
-	var expected = 
-		'<!DOCTYPE html>\n'+
-		'<html>'+
-		'<body>'+
-		'Lorem ipsum.'+
-		'</body>'+
-		'</html>';
-	same(actual, expected, "");
-});
-
-}catch(ex){alert(ex);}

File duel/dueljs/src/test/javascript/js/utils.js

-function toHTML(node) {
-	var root = document.createElement("div");
-	root.appendChild(node);
-	return root.innerHTML;
-}

File duel/dueljs/src/test/javascript/renderTests.js

View file
+try {
+
+module("Result.toString()");
+
+test("nested elements with attributes", function() {
+
+	var view = duel(
+		["div", { "class" : "download" },
+			["h2",
+			 	"Filename: Foo.js"
+			],
+			["p",
+			 	"URL: ",
+			 	["br"],
+			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
+			 		"http://example.com/foo.js"
+		 		],
+			 	" (5.87KB)"
+		 	],
+		 	["hr"],
+			["p",
+			 	"Description: Lorem ipsum dolor sit amet"
+			]
+		]);
+
+	var actual = view().toString();
+
+	var expected =
+		'<div class="download"><h2>Filename: Foo.js</h2>'+
+		'<p>URL: <br /><a href="http://example.com/foo.js" target="_blank" title="Lorem ipsum dolor sit amet">http://example.com/foo.js</a> (5.87KB)</p>'+
+		'<hr />'+
+		'<p>Description: Lorem ipsum dolor sit amet</p>'+
+		'</div>';
+
+	same(actual, expected, "");
+});
+
+test("native toString", function() {
+
+	var view = duel(
+		["div", { "class" : "download" },
+			["h2",
+			 	"Filename: Foo.js"
+			],
+			["p",
+			 	"URL: ",
+			 	["br"],
+			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
+			 		"http://example.com/foo.js"
+		 		],
+			 	" (5.87KB)"
+		 	],
+		 	["hr"],
+			["p",
+			 	"Description: Lorem ipsum dolor sit amet"
+			]
+		]);
+
+	var actual = ""+view();
+
+	var expected =
+		'<div class="download"><h2>Filename: Foo.js</h2>'+
+		'<p>URL: <br /><a href="http://example.com/foo.js" target="_blank" title="Lorem ipsum dolor sit amet">http://example.com/foo.js</a> (5.87KB)</p>'+
+		'<hr />'+
+		'<p>Description: Lorem ipsum dolor sit amet</p>'+
+		'</div>';
+
+	same(actual, expected, "");
+});
+
+test("innerHTML toString", function() {
+
+	var view = duel(
+		["div", { "class" : "download" },
+			["h2",
+			 	"Filename: Foo.js"
+			],
+			["p",
+			 	"URL: ",
+			 	["br"],
+			 	["a", { "href" : "http://example.com/foo.js", "target" : "_blank", "title" : "Lorem ipsum dolor sit amet" },
+			 		"http://example.com/foo.js"
+		 		],
+			 	" (5.87KB)"
+		 	],
+		 	["hr"],
+			["p",
+			 	"Description: Lorem ipsum dolor sit amet"
+			]