react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / htmlparser2 / node_modules / entities / test / test.js
81149 viewsvar assert = require("assert"),1path = require("path"),2entities = require("../");34describe("Encode->decode test", function(){5var testcases = [6{7input: "asdf & ÿ ü '",8xml: "asdf & ÿ ü '",9html: "asdf & ÿ ü '"10}, {11input: "&",12xml: "&#38;",13html: "&#38;"14},15];16testcases.forEach(function(tc) {17var encodedXML = entities.encodeXML(tc.input);18it("should XML encode " + tc.input, function(){19assert.equal(encodedXML, tc.xml);20});21it("should default to XML encode " + tc.input, function(){22assert.equal(entities.encode(tc.input), tc.xml);23});24it("should XML decode " + encodedXML, function(){25assert.equal(entities.decodeXML(encodedXML), tc.input);26});27it("should default to XML encode " + encodedXML, function(){28assert.equal(entities.decode(encodedXML), tc.input);29});30it("should default strict to XML encode " + encodedXML, function(){31assert.equal(entities.decodeStrict(encodedXML), tc.input);32});3334var encodedHTML5 = entities.encodeHTML5(tc.input);35it("should HTML5 encode " + tc.input, function(){36assert.equal(encodedHTML5, tc.html);37});38it("should HTML5 decode " + encodedHTML5, function(){39assert.equal(entities.decodeHTML(encodedHTML5), tc.input);40});41});42});4344describe("Decode test", function(){45var testcases = [46{ input: "&amp;", output: "&" },47{ input: "&#38;", output: "&" },48{ input: "&#x26;", output: "&" },49{ input: "&#X26;", output: "&" },50{ input: "&#38;", output: "&" },51{ input: "&#38;", output: "&" },52{ input: "&#38;", output: "&" },53{ input: ":", output: ":" },54{ input: ":", output: ":" },55{ input: ":", output: ":" },56{ input: ":", output: ":" }57];58testcases.forEach(function(tc) {59it("should XML decode " + tc.input, function(){60assert.equal(entities.decodeXML(tc.input), tc.output);61});62it("should HTML4 decode " + tc.input, function(){63assert.equal(entities.decodeHTML(tc.input), tc.output);64});65it("should HTML5 decode " + tc.input, function(){66assert.equal(entities.decodeHTML(tc.input), tc.output);67});68});69});7071var levels = ["xml", "entities"];7273describe("Documents", function(){74levels75.map(function(n){ return path.join("..", "maps", n); })76.map(require)77.forEach(function(doc, i){78describe("Decode", function(){79it(levels[i], function(){80Object.keys(doc).forEach(function(e){81for(var l = i; l < levels.length; l++){82assert.equal(entities.decode("&" + e + ";", l), doc[e]);83}84});85});86});8788describe("Decode strict", function(){89it(levels[i], function(){90Object.keys(doc).forEach(function(e){91for(var l = i; l < levels.length; l++){92assert.equal(entities.decodeStrict("&" + e + ";", l), doc[e]);93}94});95});96});9798describe("Encode", function(){99it(levels[i], function(){100Object.keys(doc).forEach(function(e){101for(var l = i; l < levels.length; l++){102assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);103}104});105});106});107});108109var legacy = require("../maps/legacy.json");110111describe("Legacy", function(){112it("should decode", runLegacy);113});114115function runLegacy(){116Object.keys(legacy).forEach(function(e){117assert.equal(entities.decodeHTML("&" + e), legacy[e]);118});119}120});121122var astral = {123"1D306": "\uD834\uDF06",124"1D11E": "\uD834\uDD1E"125};126127var astralSpecial = {128"80": "\u20AC",129"110000": "\uFFFD"130};131132133describe("Astral entities", function(){134Object.keys(astral).forEach(function(c){135it("should decode " + astral[c], function(){136assert.equal(entities.decode("&#x" + c + ";"), astral[c]);137});138139it("should encode " + astral[c], function(){140assert.equal(entities.encode(astral[c]), "&#x" + c + ";");141});142});143144Object.keys(astralSpecial).forEach(function(c){145it("special should decode \\u" + c, function(){146assert.equal(entities.decode("&#x" + c + ";"), astralSpecial[c]);147});148});149});150151152