Skip to content

Commit

Permalink
Fix tests with correct translations
Browse files Browse the repository at this point in the history
Add post methods to test
  • Loading branch information
Artforge committed Jul 2, 2010
1 parent c773e8d commit 62523ae
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions tests/ts_translate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

class Translate::TranslateTest < Test::Unit::TestCase
include Google::Language

def test_english_translate
assert_equal("مرحبا العالم", Translate.t("Hello world", "ENGLISH", "ARABIC"));
assert_equal("世界您好", Translate.t("Hello world", "ENGLISH", "CHINESE_SIMPLIFIED"));
assert_equal("您好世界", Translate.t("Hello world", "ENGLISH", "CHINESE_SIMPLIFIED"));
assert_equal("Bonjour tout le monde", Translate.t("Hello world", "ENGLISH", "FRENCH"));
assert_equal("Hallo Welt", Translate.t("Hello world", "ENGLISH", "GERMAN"));
assert_equal("Ciao a tutti", Translate.t("Hello world", "ENGLISH", "ITALIAN"));
Expand All @@ -21,7 +22,7 @@ def test_english_translate

def test_auto_detect_translate
assert_equal("مرحبا العالم", Translate.t("Hello world", nil, "ARABIC"));
assert_equal("世界您好", Translate.t("Hello world", nil, "CHINESE_SIMPLIFIED"));
assert_equal("您好世界", Translate.t("Hello world", nil, "CHINESE_SIMPLIFIED"));
assert_equal("Bonjour tout le monde", Translate.t("Hello world", nil, "FRENCH"));
assert_equal("Hallo Welt", Translate.t("Hello world", nil, "GERMAN"));
assert_equal("Ciao a tutti", Translate.t("Hello world", nil, "ITALIAN"));
Expand All @@ -33,26 +34,42 @@ def test_auto_detect_translate
end

def test_chinese_translate
assert_equal("Hello World", Translate.t("你好世界", "CHINESE", "ENGLISH"))
assert_equal("Hello World", Translate.t("你好世界", 'zh', 'en'))
assert_equal("Hello World", Translate.t("您好世界", "CHINESE", "ENGLISH"))
assert_equal("Hello World", Translate.t("您好世界", 'zh', 'en'))
end

def test_unsupported_translate
assert_raise UnsupportedLanguagePair do
Translate::RTranslate.t("你好世界", 'zh', 'hz')
Translate::RTranslate.t("您好世界", 'zh', 'hz')
end
end

def test_translate_strings
assert_equal(["", "世界"], Translate::RTranslate.translate_strings(["Hello", "World"], "en", "zh-CN"))
assert_equal(["你好", "世界"], Translate::RTranslate.translate_strings(["Hello", "World"], "en", "zh-CN"))
end

def test_translate_string_to_languages
assert_equal(["世界您好", "ハローワールド"], Translate::RTranslate.translate_string_to_languages("Hello World", {:from => "en", :to => ["zh-CN", "ja"]}))
assert_equal(["您好世界", "ハローワールド"], Translate::RTranslate.translate_string_to_languages("Hello World", {:from => "en", :to => ["zh-CN", "ja"]}))
end

def test_batch_translate
assert_equal(["世界您好", "ハローワールド"],
Translate::RTranslate.batch_translate([["Hello World", {:from => "en", :to => "zh-CN"}], ["Hello World", {:from => "en", :to => "ja"}]]))
assert_equal(["您好世界", "ハローワールド"],
Translate::RTranslate.batch_translate([["Hello World", {:from => "en", :to => "zh-CN"}], ["Hello World", {:from => "en", :to => "ja"}]]))
end

def test_post_translate
# Basic
assert_equal("مرحبا العالم", Translate.t("Hello world", "ENGLISH", "ARABIC", {:method => :post}));
# Auto Detect Language
assert_equal("您好世界", Translate.t("Hello world", nil, "CHINESE_SIMPLIFIED", {:method => :post}));
#Chinese
assert_equal("Hello World", Translate.t("您好世界", "CHINESE", "ENGLISH", {:method => :post}))
#Strings
assert_equal(["你好", "世界"], Translate::RTranslate.translate_strings(["Hello", "World"], "en", "zh-CN", {:method => :post}))
# String to Languages
assert_equal(["您好世界", "ハローワールド"], Translate::RTranslate.translate_string_to_languages("Hello World", {:from => "en", :to => ["zh-CN", "ja"], :method => :post}))
# Batch
assert_equal(["您好世界", "ハローワールド"],
Translate::RTranslate.batch_translate([["Hello World", {:from => "en", :to => "zh-CN"}], ["Hello World", {:from => "en", :to => "ja"}]], {:method => :post}))
end
end

0 comments on commit 62523ae

Please sign in to comment.