[Pkg-javascript-commits] [node-entities] 16/63: Add test suite.
Wolfgang Borgert
debacle at moszumanska.debian.org
Mon Sep 22 08:15:45 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 6ad621f747187c050a95a8d3848678a775ee8e1c
Author: C. Scott Ananian <cscott at cscott.net>
Date: Thu Apr 18 17:19:44 2013 -0400
Add test suite.
This also documents gh issue #8 with a failing test.
---
.gitignore | 1 +
package.json | 9 +++++++++
test.js | 23 -----------------------
test/mocha.opts | 2 ++
test/test.js | 38 ++++++++++++++++++++++++++++++++++++++
5 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/package.json b/package.json
index 72897a3..31be4e7 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,15 @@
"author": "Felix Boehm <me at feedic.com>",
"keywords": ["html", "xml", "entity", "encoding"],
"main": "./index.js",
+ "directories": {
+ "test": "test"
+ },
+ "devDependencies": {
+ "mocha": "~1.9.0"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
"repository": {
"type": "git"
, "url": "git://github.com/fb55/node-entities.git"
diff --git a/test.js b/test.js
deleted file mode 100644
index a8bd925..0000000
--- a/test.js
+++ /dev/null
@@ -1,23 +0,0 @@
-var ben = require("ben"),
- decode = require("./").decodeXML,
- encode = require("./").encode,
- decoded = "asdf & ÿ ü '",
- encoded = encode(decoded);
-
-(function(result){
- if(result !== "asdf & ÿ ü '"){
- throw Error("Unexpected output: " + result);
- }
-}(encode(decoded)));
-
-var tmp = Array(201).join(decoded);
-console.log("Encoding:", ben(function(){ encode(tmp); }));
-
-(function(result){
- if(result !== decoded){
- throw Error("Unexpected output: " + result);
- }
-}(decode(encoded, 2)));
-
-tmp = Array(201).join(encoded);
-console.log("Decoding:", ben(function(){ decode(tmp, 2); }));
\ No newline at end of file
diff --git a/test/mocha.opts b/test/mocha.opts
new file mode 100644
index 0000000..af53e24
--- /dev/null
+++ b/test/mocha.opts
@@ -0,0 +1,2 @@
+--check-leaks
+--reporter spec
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..f3b0bd9
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,38 @@
+var assert = require('assert');
+var entities = require('../');
+
+describe("Encode/decode test", function() {
+ var testcases = [
+ { input: "asdf & ÿ ü '",
+ xml: "asdf & ÿ ü '",
+ html4: "asdf & ÿ ü '",
+ html5: "asdf & ÿ ü '" },
+ { input: '&',
+ xml: '&',
+ html4: '&',
+ html5: '&#38;' },
+ ];
+ testcases.forEach(function(tc) {
+ var encodedXML = entities.encodeXML(tc.input);
+ it('should XML encode '+tc.input, function() {
+ assert.equal(encodedXML, tc.xml);
+ });
+ it('should XML decode '+encodedXML, function() {
+ assert.equal(entities.decodeXML(encodedXML), tc.input);
+ });
+ var encodedHTML4 = entities.encodeHTML4(tc.input);
+ it('should HTML4 encode '+tc.input, function() {
+ assert.equal(encodedHTML4, tc.html4);
+ });
+ 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);
+ });
+ it('should HTML5 decode '+encodedHTML5, function() {
+ assert.equal(entities.decodeHTML5(encodedHTML5), tc.input);
+ });
+ });
+});
--
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