[Pkg-javascript-commits] [node-entities] 36/63: test: reach 100% coverage

Wolfgang Borgert debacle at moszumanska.debian.org
Mon Sep 22 08:15:47 UTC 2014


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

debacle pushed a commit to branch master
in repository node-entities.

commit 51af3839f780c3bb638b1d1d2d08bebd1287b349
Author: fb55 <me at feedic.com>
Date:   Sun Feb 16 21:08:18 2014 +0100

    test: reach 100% coverage
---
 test/test.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/test/test.js b/test/test.js
index 5e418a7..af988b2 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,4 +1,5 @@
 var assert = require("assert"),
+    path = require("path"),
     entities = require('../');
 
 describe("Encode->decode test", function(){
@@ -20,9 +21,19 @@ describe("Encode->decode test", function(){
 		it("should XML encode " + tc.input, function(){
 			assert.equal(encodedXML, tc.xml);
 		});
+		it("should default to XML encode " + tc.input, function(){
+			assert.equal(entities.encode(tc.input), tc.xml);
+		});
 		it("should XML decode " + encodedXML, function(){
 			assert.equal(entities.decodeXML(encodedXML), tc.input);
 		});
+		it("should default to XML encode " + encodedXML, function(){
+			assert.equal(entities.decode(encodedXML), tc.input);
+		});
+		it("should default strict to XML encode " + encodedXML, function(){
+			assert.equal(entities.decodeStrict(encodedXML), tc.input);
+		});
+
 		var encodedHTML4 = entities.encodeHTML4(tc.input);
 		it("should HTML4 encode " + tc.input, function(){
 			assert.equal(encodedHTML4, tc.html4);
@@ -30,6 +41,7 @@ describe("Encode->decode test", function(){
 		it("should HTML4 decode " + encodedHTML4, function(){
 			assert.equal(entities.decodeHTML4(encodedHTML4), tc.input);
 		});
+
 		var encodedHTML5 = entities.encodeHTML5(tc.input);
 		it("should HTML5 encode " + tc.input, function(){
 			assert.equal(encodedHTML5, tc.html5);
@@ -66,3 +78,63 @@ describe("Decode test", function(){
 		});
 	});
 });
+
+var levels = ["xml", "html4", "html5"];
+
+describe("Documents", function(){
+	levels
+	.map(function(n){ return path.join("..", "entities", n); })
+	.map(require)
+	.forEach(function(doc, i){
+		describe("Decode", function(){
+			it(levels[i], function(){
+				Object.keys(doc).forEach(function(e){
+					for(var l = i; l < levels.length; l++){
+						assert.equal(entities.decode("&" + e, l), doc[e]);
+					}
+				});
+			});
+		});
+
+		describe("Decode strict", function(){
+			it(levels[i], function(){
+				Object.keys(doc).forEach(function(e){
+					if(e.substr(-1) !== ";"){
+						assert.equal(entities.decodeStrict("&" + e, i), "&" + e);
+						return;
+					}
+					for(var l = i; l < levels.length; l++){
+						assert.equal(entities.decodeStrict("&" + e, l), doc[e]);
+					}
+				});
+			});
+		});
+
+		describe("Encode", function(){
+			it(levels[i], function(){
+				Object.keys(doc).forEach(function(e){
+					if(e.substr(-1) !== ";") return;
+					for(var l = i; l < levels.length; l++){
+						assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
+					}
+				});
+			});
+		});
+	});
+});
+
+var astral = {
+	"1D306": "\uD834\uDF06",
+	"1D11E": "\uD834\uDD1E"
+};
+
+describe("Astral entities", function(){
+	Object.keys(astral).forEach(function(c){
+		/*it("should decode " + astral[c], function(){
+			assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
+		});*/
+		it("should encode " + astral[c], function(){
+			assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
+		});
+	});
+});

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



More information about the Pkg-javascript-commits mailing list