test.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Before `make install' is performed this script should be runnable with
  2. # `make test'. After `make install' it should work as `perl test.pl'
  3. ######################### We start with some black magic to print on failure.
  4. # Time-stamp: "2001-07-14 01:48:48 MDT"
  5. require 5.006;
  6. # This is a Perl program.
  7. use strict;
  8. use utf8;
  9. use Test;
  10. BEGIN { plan tests => 17 }
  11. use Text::Unidecode;
  12. ok 1;
  13. print "# Text::Unidecode v$Text::Unidecode::VERSION\n",
  14. "# Perl v$]\n",
  15. "# Starting tests...\n";
  16. my $in = "\x{0d9c}\x{0d8e}!\n";
  17. my($was, $should, $is);
  18. foreach my $line (
  19. #"# 7-bit purity tests: all chars 00 to 7F\n",
  20. #map(\ord($_), 0x00 .. 0x7f),
  21. "# Basic string tests\n",
  22. \(
  23. "",
  24. 1/10,
  25. "I like pie.",
  26. "\n",
  27. "\cm\cj",
  28. "I like pie.\n",
  29. ),
  30. "#\n",
  31. "# COMPLEX TESTS\n",
  32. split(m/\n/, <<"EOTESTS"),
  33. <\x{C6}neid> <AEneid>
  34. <\x{E9}tude> <etude>
  35. <\x{5317}\x{4EB0}> <Bei Jing >
  36. ; Chinese
  37. <\x{1515}\x{14c7}\x{14c7}> <shanana>
  38. ; Canadian syllabics
  39. <\x{13d4}\x{13b5}\x{13c6}> <taliqua>
  40. ; Cherokee
  41. <\x{0726}\x{071b}\x{073d}\x{0710}\x{073a}> <ptu'i>
  42. ; Syriac
  43. <\x{0905}\x{092d}\x{093f}\x{091c}\x{0940}\x{0924}> <abhijiit>
  44. ; Devanagari
  45. <\x{0985}\x{09ad}\x{09bf}\x{099c}\x{09c0}\x{09a4}> <abhijiit>
  46. ; Bengali
  47. <\x{0d05}\x{0d2d}\x{0d3f}\x{0d1c}\x{0d40}\x{0d24}> <abhijiit>
  48. ; Malayalaam
  49. <\x{0d2e}\x{0d32}\x{0d2f}\x{0d3e}\x{0d32}\x{0d2e}\x{0d4d}> <mlyaalm>
  50. ; the Malayaalam word for "Malayaalam"
  51. ; Yes, if we were doing it right, that'd be "malayaalam", not "mlyaalm"
  52. <\x{3052}\x{3093}\x{307e}\x{3044}\x{8336}> <genmaiCha >
  53. ; Japanese, astonishingly unmangled.
  54. EOTESTS
  55. # TODO: more tests, I guess.
  56. "# End of test data\n",
  57. ) {
  58. if(ref $line) { # it should pass thru untouched
  59. #print ref($line), "\n";
  60. $was = $should = $$line;
  61. } else {
  62. if($line =~ m/<(.*?)>\s*<(.*?)>/ or $line =~ m/\[(.*?)\]\s*\[(.*?)\]/ ){
  63. ($was, $should) = ($1,$2);
  64. } else {
  65. print $line if $line =~ m/^\s*#/s;
  66. next;
  67. }
  68. }
  69. $is = unidecode($was);
  70. if($should eq $is) {
  71. ok 1;
  72. for($should, $is, $was) { s/\n/\\n/g; s/\cm/\\cm/g; s/\cj/\\cj/g; }
  73. print " # <$was> -> <$is> (ok)\n";
  74. } else {
  75. ok 0;
  76. for($should, $is, $was) { s/\n/\\n/g }
  77. print " # <$was> -> <$is>, but should be <$should>\n";
  78. }
  79. }
  80. print "# Byebye\n";