Skip to content

Commit

Permalink
Add test suite.
Browse files Browse the repository at this point in the history
This also documents gh issue fb55#8 with a failing test.
  • Loading branch information
cscott committed Apr 18, 2013
1 parent f67c5bf commit 6ad621f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"author": "Felix Boehm <me@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"
Expand Down
23 changes: 0 additions & 23 deletions test.js

This file was deleted.

2 changes: 2 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--check-leaks
--reporter spec
38 changes: 38 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var assert = require('assert');
var entities = require('../');

describe("Encode/decode test", function() {
var testcases = [
{ input: "asdf & ÿ ü '",
xml: "asdf &amp; &#255; &#252; &apos;",
html4: "asdf &amp; &yuml &uuml &apos;",
html5: "asdf &amp; &yuml &uuml &apos;" },
{ input: '&#38;',
xml: '&amp;#38;',
html4: '&amp;#38;',
html5: '&amp;&num;38&semi;' },
];
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);
});
});
});

0 comments on commit 6ad621f

Please sign in to comment.