Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. var assert = require("assert"),
  2. path = require("path"),
  3. entities = require("../");
  4. describe("Encode->decode test", function() {
  5. var testcases = [
  6. {
  7. input: "asdf & ÿ ü '",
  8. xml: "asdf & ÿ ü '",
  9. html: "asdf & ÿ ü '"
  10. },
  11. {
  12. input: "&",
  13. xml: "&",
  14. html: "&"
  15. }
  16. ];
  17. testcases.forEach(function(tc) {
  18. var encodedXML = entities.encodeXML(tc.input);
  19. it("should XML encode " + tc.input, function() {
  20. assert.equal(encodedXML, tc.xml);
  21. });
  22. it("should default to XML encode " + tc.input, function() {
  23. assert.equal(entities.encode(tc.input), tc.xml);
  24. });
  25. it("should XML decode " + encodedXML, function() {
  26. assert.equal(entities.decodeXML(encodedXML), tc.input);
  27. });
  28. it("should default to XML encode " + encodedXML, function() {
  29. assert.equal(entities.decode(encodedXML), tc.input);
  30. });
  31. it("should default strict to XML encode " + encodedXML, function() {
  32. assert.equal(entities.decodeStrict(encodedXML), tc.input);
  33. });
  34. var encodedHTML5 = entities.encodeHTML5(tc.input);
  35. it("should HTML5 encode " + tc.input, function() {
  36. assert.equal(encodedHTML5, tc.html);
  37. });
  38. it("should HTML5 decode " + encodedHTML5, function() {
  39. assert.equal(entities.decodeHTML(encodedHTML5), tc.input);
  40. });
  41. });
  42. it("should encode data URIs (issue 16)", function() {
  43. var data = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAALAAABAAEAAAIBRAA7";
  44. assert.equal(entities.decode(entities.encode(data)), data);
  45. });
  46. });
  47. describe("Decode test", function() {
  48. var testcases = [
  49. { input: "&", output: "&" },
  50. { input: "&", output: "&" },
  51. { input: "&", output: "&" },
  52. { input: "&", output: "&" },
  53. { input: "&", output: "&" },
  54. { input: "&", output: "&" },
  55. { input: "&", output: "&" },
  56. { input: ":", output: ":" },
  57. { input: ":", output: ":" },
  58. { input: ":", output: ":" },
  59. { input: ":", output: ":" }
  60. ];
  61. testcases.forEach(function(tc) {
  62. it("should XML decode " + tc.input, function() {
  63. assert.equal(entities.decodeXML(tc.input), tc.output);
  64. });
  65. it("should HTML4 decode " + tc.input, function() {
  66. assert.equal(entities.decodeHTML(tc.input), tc.output);
  67. });
  68. it("should HTML5 decode " + tc.input, function() {
  69. assert.equal(entities.decodeHTML(tc.input), tc.output);
  70. });
  71. });
  72. });
  73. var levels = ["xml", "entities"];
  74. describe("Documents", function() {
  75. levels
  76. .map(function(n) {
  77. return path.join("..", "maps", n);
  78. })
  79. .map(require)
  80. .forEach(function(doc, i) {
  81. describe("Decode", function() {
  82. it(levels[i], function() {
  83. Object.keys(doc).forEach(function(e) {
  84. for (var l = i; l < levels.length; l++) {
  85. assert.equal(entities.decode("&" + e + ";", l), doc[e]);
  86. }
  87. });
  88. });
  89. });
  90. describe("Decode strict", function() {
  91. it(levels[i], function() {
  92. Object.keys(doc).forEach(function(e) {
  93. for (var l = i; l < levels.length; l++) {
  94. assert.equal(entities.decodeStrict("&" + e + ";", l), doc[e]);
  95. }
  96. });
  97. });
  98. });
  99. describe("Encode", function() {
  100. it(levels[i], function() {
  101. Object.keys(doc).forEach(function(e) {
  102. for (var l = i; l < levels.length; l++) {
  103. assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
  104. }
  105. });
  106. });
  107. });
  108. });
  109. var legacy = require("../maps/legacy.json");
  110. describe("Legacy", function() {
  111. it("should decode", runLegacy);
  112. });
  113. function runLegacy() {
  114. Object.keys(legacy).forEach(function(e) {
  115. assert.equal(entities.decodeHTML("&" + e), legacy[e]);
  116. });
  117. }
  118. });
  119. var astral = {
  120. "1D306": "\uD834\uDF06",
  121. "1D11E": "\uD834\uDD1E"
  122. };
  123. var astralSpecial = {
  124. "80": "\u20AC",
  125. "110000": "\uFFFD"
  126. };
  127. describe("Astral entities", function() {
  128. Object.keys(astral).forEach(function(c) {
  129. it("should decode " + astral[c], function() {
  130. assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
  131. });
  132. it("should encode " + astral[c], function() {
  133. assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
  134. });
  135. it("should escape " + astral[c], function() {
  136. assert.equal(entities.escape(astral[c]), "&#x" + c + ";");
  137. });
  138. });
  139. Object.keys(astralSpecial).forEach(function(c) {
  140. it("special should decode \\u" + c, function() {
  141. assert.equal(entities.decode("&#x" + c + ";"), astralSpecial[c]);
  142. });
  143. });
  144. });
  145. describe("Escape", function() {
  146. it("should always decode ASCII chars", function() {
  147. for (var i = 0; i < 0x7f; i++) {
  148. var c = String.fromCharCode(i);
  149. assert.equal(entities.decodeXML(entities.escape(c)), c);
  150. }
  151. });
  152. });