unidecode.mocha.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Tests are taken from Text-Unidecode-0.04/test.pl
  3. *
  4. * @see <http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm>
  5. */
  6. 'use strict';
  7. /* global describe, it */
  8. var assert = require('assert');
  9. var unidecode = require('../unidecode');
  10. describe('# Purity tests', function(){
  11. var code;
  12. var tests = [];
  13. for(code=0; code<=127; code++) {
  14. tests.push(String.fromCharCode(code));
  15. }
  16. tests.forEach(function(test) {
  17. it(test.charCodeAt(0).toString(16) + ' ' + test, function(){
  18. var exp = test;
  19. var res = unidecode(exp);
  20. assert.equal(res, exp);
  21. });
  22. });
  23. });
  24. describe('# Basic string tests', function(){
  25. var tests = [
  26. "",
  27. 1/10,
  28. "I like pie.",
  29. "\n",
  30. "\r\n", // "\cm\cj" - perl control chars Ctrl+M, CTRL+J === \r\n
  31. "I like pie.\n",
  32. ];
  33. tests.forEach(function(test) {
  34. it(test, function(){
  35. var exp = test;
  36. var res = unidecode(test.toString());
  37. assert.equal(res, exp);
  38. });
  39. });
  40. });
  41. describe('# Complex tests', function(){
  42. var tests = [
  43. ["\u00C6neid", "AEneid"],
  44. ["\u00E9tude", "etude"],
  45. ["\u5317\u4EB0", "Bei Jing "],
  46. // Chinese
  47. ["\u1515\u14c7\u14c7", "shanana"],
  48. // Canadian syllabics
  49. ["\u13d4\u13b5\u13c6", "taliqua"],
  50. // Cherokee
  51. ["\u0726\u071b\u073d\u0710\u073a", "ptu'i"],
  52. // Syriac
  53. ["\u0905\u092d\u093f\u091c\u0940\u0924", "abhijiit"],
  54. // Devanagari
  55. ["\u0985\u09ad\u09bf\u099c\u09c0\u09a4", "abhijiit"],
  56. // Bengali
  57. ["\u0d05\u0d2d\u0d3f\u0d1c\u0d40\u0d24", "abhijiit"],
  58. // Malayalaam
  59. ["\u0d2e\u0d32\u0d2f\u0d3e\u0d32\u0d2e\u0d4d", "mlyaalm"],
  60. // the Malayaalam word for "Malayaalam"
  61. // Yes, if we were doing it right, that'd be "malayaalam", not "mlyaalm"
  62. ["\u3052\u3093\u307e\u3044\u8336", "genmaiCha "],
  63. // Japanese, astonishingly unmangled.
  64. ];
  65. tests.forEach(function(test) {
  66. it(test[0] + '-->' + test[1], function(){
  67. var exp = test[1];
  68. var res = unidecode(test[0]);
  69. assert.equal(res, exp);
  70. });
  71. });
  72. });