test/tools/test_msgmerge.rb in gettext-3.0.2 vs test/tools/test_msgmerge.rb in gettext-3.0.3

- old
+ new

@@ -21,40 +21,87 @@ require 'gettext/tools/msgmerge' class TestToolsMsgMerge < Test::Unit::TestCase class TestMerger < self def setup - @merger = GetText::Tools::MsgMerge::Merger.new @po = GetText::PO.new @pot = GetText::PO.new + @config = GetText::Tools::MsgMerge::Config.new end - def test_add_entry - @po["hello"] = "bonjour" - @pot["hello"] = "bonjour" - @pot["he"] = "il" - merged_po = @merger.merge(@po, @pot) + def parse_po(po, output) + parser = GetText::POParser.new + parser.report_warning = false + parser.parse(po, output) + end - assert_equal("bonjour", merged_po["hello"].msgstr) - assert_equal("il", merged_po["he"].msgstr) + def merge + merger = GetText::Tools::MsgMerge::Merger.new(@pot, @po, @config) + merger.merge end - def test_existing_obsolete_entry - @po["hello"] = "bonjour" - @po[:last] = generate_entry(:msgid => :last, - :comment => "#~ obsolete_entry") - @pot["hello"] = "bonjour" - merged_po = @merger.merge(@po, @pot) + class TestUpdate < self + def test_msgstr + pot = <<-POT +msgid "hello" +msgstr "" + POT + po = <<-PO +msgid "hello" +msgstr "bonjour" + PO + merged_po = merge(pot, po) - assert_equal("bonjour", merged_po["hello"].msgstr) - assert_nil(merged_po[:last]) + assert_equal(<<-PO, merged_po) +msgid "hello" +msgstr "bonjour" + PO + end + + private + def merge(pot, po) + parse_po(pot, @pot) + parse_po(po, @po) + super().to_s + end end + class TestObosleteEntry < self + def test_in_po + pot = <<-POT +msgid "hello" +msgstr "" + POT + po = <<-PO +msgid "hello" +msgstr "bonjour" + +#~ msgid "he" +#~ msgstr "il" + PO + + assert_equal(<<-PO, merge(pot, po)) +msgid "hello" +msgstr "bonjour" + +#~ msgid "he" +#~ msgstr "il" + PO + end + + private + def merge(pot, po) + parse_po(pot, @pot) + parse_po(po, @po) + super().to_s + end + end + def test_different_msgstr @po["hello"] = "salut" @pot["hello"] = "bonjour" - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("salut", merged_po["hello"].msgstr) end def test_translator_comment @@ -64,11 +111,11 @@ @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "", :translator_comment => "It's comments") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("bonjour", merged_po["hello"].msgstr) assert_equal("comment", merged_po["hello"].translator_comment) end def test_extracted_comment @@ -78,11 +125,11 @@ @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "", :extracted_comment => "extracted comments") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("bonjour", merged_po["hello"].msgstr) assert_equal("extracted comments", merged_po["hello"].extracted_comment) end def test_references @@ -94,11 +141,11 @@ @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "", :references => pot_references) - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("bonjour", merged_po["hello"].msgstr) assert_equal(pot_references, merged_po["hello"].references) end def test_flag @@ -108,11 +155,11 @@ @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "", :flag => "no-c-format") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("bonjour", merged_po["hello"].msgstr) assert_equal("no-c-format", merged_po["hello"].flag) end def test_previous @@ -121,22 +168,22 @@ :previous => "hi") @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("bonjour", merged_po["hello"].msgstr) assert_equal(nil, merged_po["hello"].previous) end class TestAddNoFuzzy < self def test_add_to_nontranslated_entry @po["helol"] = generate_entry(:msgid => "helol", :msgstr => nil) @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => nil) - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_true(merged_po.has_key?("hello")) assert_nil(merged_po["hello"].flag) end def test_fuzzy_header @@ -147,11 +194,11 @@ @pot[""] = generate_entry(:msgid => "", :msgstr => "uninitialized\ncomment", :translator_comment => "uninitialized comment", :flag => "fuzzy") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("header\nentry", merged_po[""].msgstr) assert_equal("header comment", merged_po[""].translator_comment) assert_equal(nil, merged_po[""].flag) end @@ -166,11 +213,11 @@ @pot[""] = generate_entry(:msgid => "", :msgstr => pot_creation_date, :translator_comment => "header comment", :flag => "fuzzy") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal(pot_creation_date, merged_po[""].msgstr) end end class TestAddFuzzy < self @@ -178,11 +225,11 @@ @po["normal", "hello"] = generate_entry(:msgctxt => "normal", :msgid => "hello", :msgstr => "salut") @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_false(merged_po.has_key?("normal", "hello")) assert_true(merged_po.has_key?("hello")) assert_equal("salut", merged_po["hello"].msgstr) assert_equal("fuzzy", merged_po["hello"].flag) @@ -193,21 +240,21 @@ :msgid_plural => "thye", :msgstr => "il\000ils") @pot["he"] = generate_entry(:msgid => "he", :msgid_plural => "they", :msgstr => "") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("il\000ils", merged_po["he"].msgstr) assert_equal("they", merged_po["he"].msgid_plural) assert_equal("fuzzy", merged_po["he"].flag) end def test_fuzzy_matching_entry @po["helol"] = "bonjour" @pot["hello"] = "" - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_false(merged_po.has_key?("helol")) assert_true(merged_po.has_key?("hello")) assert_equal("bonjour", merged_po["hello"].msgstr) assert_equal("fuzzy", merged_po["hello"].flag) @@ -219,20 +266,20 @@ :flag => "fuzzy") @pot["hello"] = generate_entry(:msgid => "hello", :msgstr => "") - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("bonjuor", merged_po["hello"].msgstr) assert_equal("fuzzy", merged_po["hello"].flag) end end def test_obsolete_entry @po["hello"] = "bonjour" @pot["hi"] = "salut" - merged_po = @merger.merge(@po, @pot) + merged_po = merge assert_equal("salut", merged_po["hi"].msgstr) assert_false(merged_po.has_key?("hello")) obsolete_comment = <<-EOC @@ -582,9 +629,65 @@ msgstr "" #: hello.rb:3 msgid "Hello World" msgstr "Translated Hello World. This translation is very long. Yes! Very long translation!!!" + PO + end + end + + class TestFuzzyMatching < self + def pot_content + <<-POT +msgid "Hello" +msgstr "" + POT + end + + def po_content + <<-PO +msgid "Hello!" +msgstr "Bonjour!" + PO + end + + def test_default + @msgmerge.run("--update", + @po_file_path, @pot_file_path) + assert_equal(<<-PO, File.read(@po_file_path)) +#, fuzzy +msgid "Hello" +msgstr "Bonjour!" + +#~ msgid "Hello!" +#~ msgstr "Bonjour!" + PO + end + + def test_fuzzy_matching + @msgmerge.run("--update", + "--fuzzy-matching", + @po_file_path, @pot_file_path) + assert_equal(<<-PO, File.read(@po_file_path)) +#, fuzzy +msgid "Hello" +msgstr "Bonjour!" + +#~ msgid "Hello!" +#~ msgstr "Bonjour!" + PO + end + + def test_no_fuzzy_matching + @msgmerge.run("--update", + "--no-fuzzy-matching", + @po_file_path, @pot_file_path) + assert_equal(<<-PO, File.read(@po_file_path)) +msgid "Hello" +msgstr "" + +#~ msgid "Hello!" +#~ msgstr "Bonjour!" PO end end end end