Tested and fixed comment consumption for all formatters.
This commit is contained in:
parent
b2b4bdcc8a
commit
00d2dc953e
3 changed files with 25 additions and 24 deletions
|
@ -26,7 +26,7 @@ module Twine
|
|||
end
|
||||
|
||||
def read_file(path, lang)
|
||||
comment_regex = /#.? *"(.*)"$/
|
||||
comment_regex = /#\. *"?(.*)"?$/
|
||||
key_regex = /msgid *"(.*)"$/
|
||||
value_regex = /msgstr *"(.*)"$/m
|
||||
|
||||
|
@ -83,6 +83,8 @@ module Twine
|
|||
if comment and comment.length > 0 and !comment.start_with?("--------- ")
|
||||
set_comment_for_key(key, comment)
|
||||
end
|
||||
key = nil
|
||||
value = nil
|
||||
comment = nil
|
||||
end
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ module Twine
|
|||
end
|
||||
end
|
||||
if @options[:consume_comments]
|
||||
match = /#(.*)/.match(line)
|
||||
match = /# *(.*)/.match(line)
|
||||
if match
|
||||
last_comment = match[1]
|
||||
else
|
||||
|
|
|
@ -17,7 +17,20 @@ class FormatterTest < TwineTestCase
|
|||
end
|
||||
|
||||
@strings = Twine::StringsFile.new
|
||||
@formatter = formatter_class.new @strings, { consume_all: true }
|
||||
@formatter = formatter_class.new @strings, { consume_all: true, consume_comments: true }
|
||||
end
|
||||
|
||||
def assert_translations_read_correctly
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
end
|
||||
|
||||
def assert_file_contents_read_correctly
|
||||
assert_translations_read_correctly
|
||||
|
||||
assert_equal "comment key1", @strings.strings_map["key1"].comment
|
||||
assert_equal "comment key4", @strings.strings_map["key4"].comment
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,9 +42,7 @@ class TestAndroidFormatter < FormatterTest
|
|||
def test_read_file_format
|
||||
@formatter.read_file fixture('formatter_android.xml'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_file_contents_read_correctly
|
||||
end
|
||||
|
||||
def test_set_translation_transforms_leading_spaces
|
||||
|
@ -94,9 +105,7 @@ class TestAppleFormatter < FormatterTest
|
|||
def test_read_file_format
|
||||
@formatter.read_file fixture('formatter_apple.strings'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_file_contents_read_correctly
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
|
@ -127,9 +136,7 @@ class TestJQueryFormatter < FormatterTest
|
|||
def test_read_file_format
|
||||
@formatter.read_file fixture('formatter_jquery.json'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_translations_read_correctly
|
||||
end
|
||||
|
||||
def test_set_translation_escapes_newlines
|
||||
|
@ -159,9 +166,7 @@ class TestGettextFormatter < FormatterTest
|
|||
def test_read_file_format
|
||||
@formatter.read_file fixture('formatter_gettext.po'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_file_contents_read_correctly
|
||||
end
|
||||
|
||||
def test_read_file_with_multiple_line_value
|
||||
|
@ -188,9 +193,7 @@ class TestTizenFormatter < FormatterTest
|
|||
skip 'the current implementation of Tizen formatter does not support read_file'
|
||||
@formatter.read_file fixture('formatter_tizen.xml'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_file_contents_read_correctly
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
|
@ -209,9 +212,7 @@ class TestDjangoFormatter < FormatterTest
|
|||
def test_read_file_format
|
||||
@formatter.read_file fixture('formatter_django.po'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_file_contents_read_correctly
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
|
@ -229,9 +230,7 @@ class TestFlashFormatter < FormatterTest
|
|||
def test_read_file_format
|
||||
@formatter.read_file fixture('formatter_flash.properties'), 'en'
|
||||
|
||||
1.upto(4) do |i|
|
||||
assert_equal "value#{i}-english", @strings.strings_map["key#{i}"].translations['en']
|
||||
end
|
||||
assert_file_contents_read_correctly
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
|
|
Reference in a new issue