languages.t 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2006-2019 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. require './t/test.pl';
  16. package OddMuse;
  17. use Test::More;
  18. use utf8; # tests contain UTF-8 characters and it matters
  19. %Languages = ('de' => '\b(der|die|das|und|oder)\b',
  20. 'fr' => '\b(et|le|la|ne|pas)\b', );
  21. is(GetLanguages('This is English text and cannot be identified.'), '', 'unknown language');
  22. is(GetLanguages('Die Katze tritt die Treppe krumm.'), '', 'not enough German words');
  23. is(GetLanguages('Die Katze tritt die Treppe und die Stiege krumm.'), 'de', 'enough German words');
  24. is(GetLanguages('Le chat fait la même chose et ne chante pas.'), 'fr', 'enough French words');
  25. is(GetLanguages('Die Katze tritt die Treppe und die Stiege krumm. ' # 4 matches
  26. . 'Le chat fait la même chose et ne chante pas.' # 5 matches
  27. ), 'fr,de', 'both German and French');
  28. is(GetLanguage('This is English text and cannot be identified.'), 'en', 'now it defaults to English');
  29. is(GetLanguage('Die Katze tritt die Treppe krumm.'), 'en', 'not enough German words but it defaults to English');
  30. is(GetLanguage('Die Katze tritt die Treppe krumm und so.'), 'de', 'three German words');
  31. is(GetLanguage('Die Katze tritt die Treppe und die Stiege krumm. ' # 4 matches
  32. . 'Le chat fait la même chose et ne chante pas.' # 5 matches
  33. ), 'fr', 'French has the most hits');
  34. my $id = 'Test';
  35. my $text = 'Die Katze tritt die Treppe und die Stiege krumm. ' # 4 matches
  36. . 'Le chat fait la même chose et ne chante pas.'; # 5 matches
  37. AppendStringToFile($ConfigFile,<<'EOT');
  38. %Languages = ('de' => '\b(der|die|das|und|oder)\b',
  39. 'fr' => '\b(et|le|la|ne|pas)\b', );
  40. EOT
  41. test_page(update_page($id, $text), /Die Katze/);
  42. test_page(ReadFileOrDie($RcFile), /\bfr,de\b/);
  43. test_page(get_page($id), /lang="fr"/);
  44. done_testing;