Permalink
Browse files

Added tests for string.escapeXML, string.unescapeXML, string.needsEsc…

…ape and string.needsUnesape
  • Loading branch information...
1 parent a72f0d5 commit ed71d1fd351f51eefdab9a9cd2b27c877784ac7b @larzconwell larzconwell committed Aug 31, 2012
Showing with 73 additions and 1 deletion.
  1. +73 −1 test/string.js
View
@@ -22,7 +22,79 @@ var assert = require('assert')
tests = {
- 'test escapeRegExpCharacters': function () {
+ 'test basic escapeXML for string': function() {
+ var expected = '<html></html>'
+ , actual = string.escapeXML('<html></html>');
+ assert.equal(expected, actual);
+ }
+
+, 'test all escape characters for escapeXML': function() {
+ var expected = '&lt;&gt;&amp;&quot;&#39;'
+ , actual = string.escapeXML('<>&"\'');
+ assert.equal(expected, actual);
+ }
+
+, 'test no escape characters with string for escapeXML': function() {
+ var expected = 'Geddy'
+ , actual = string.escapeXML('Geddy');
+ assert.equal(expected, actual);
+ }
+
+, 'test no escape characters with numbers for escapeXML': function() {
+ var expected = 05
+ , actual = string.escapeXML(05);
+ assert.equal(expected, actual);
+ }
+
+, 'test basic unescapeXML for string': function() {
+ var expected = '<html></html>'
+ , actual = string.unescapeXML('&lt;html&gt;&lt;/html&gt;');
+ assert.equal(expected, actual);
+ }
+
+, 'test all escape characters for unescapeXML': function() {
+ var expected = '<>&"\''
+ , actual = string.unescapeXML('&lt;&gt;&amp;&quot;&#39;');
+ assert.equal(expected, actual);
+ }
+
+, 'test no escape characters with string for unescapeXML': function() {
+ var expected = 'Geddy'
+ , actual = string.unescapeXML('Geddy');
+ assert.equal(expected, actual);
+ }
+
+, 'test no escape characters with numbers for unescapeXML': function() {
+ var expected = 05
+ , actual = string.unescapeXML(05);
+ assert.equal(expected, actual);
+ }
+
+, 'test basic needsEscape for string': function() {
+ var expected = true
+ , actual = string.needsEscape('Geddy>');
+ assert.equal(expected, actual);
+ }
+
+, 'test basic needsEscape thats false for string': function() {
+ var expected = false
+ , actual = string.needsEscape('Geddy');
+ assert.equal(expected, actual);
+ }
+
+, 'test basic needsUnescape for string': function() {
+ var expected = true
+ , actual = string.needsEscape('&quot;Geddy&quot;');
+ assert.equal(expected, actual);
+ }
+
+, 'test basic needsUnescape thats false for string': function() {
+ var expected = false
+ , actual = string.needsEscape('Geddy');
+ assert.equal(expected, actual);
+ }
+
+, 'test escapeRegExpCharacters': function () {
var expected = '\\^\\/\\.\\*\\+\\?\\|\\(\\)\\[\\]\\{\\}\\\\'
actual = string.escapeRegExpChars('^/.*+?|()[]{}\\');
assert.equal(expected, actual);

0 comments on commit ed71d1f

Please sign in to comment.