Added unit tests for Django and Flash formatters.
This commit is contained in:
parent
00000ba9c9
commit
bcb6dd928e
4 changed files with 82 additions and 1 deletions
|
@ -51,7 +51,7 @@ module Twine
|
|||
match = /((?:[^"\\]|\\.)+)\s*=\s*((?:[^"\\]|\\.)*)/.match(line)
|
||||
if match
|
||||
key = match[1]
|
||||
value = match[2]
|
||||
value = match[2].strip
|
||||
value.gsub!(/\{[0-9]\}/, '%@')
|
||||
set_translation_for_key(key, lang, value)
|
||||
if last_comment
|
||||
|
|
27
test/fixtures/formatter_django.po
vendored
Normal file
27
test/fixtures/formatter_django.po
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
##
|
||||
# Django Strings File
|
||||
# Generated by Twine 0.7.0
|
||||
# Language: en
|
||||
|
||||
|
||||
#--------- Section 1 ---------#
|
||||
|
||||
#. comment key1
|
||||
# base translation: "value1-english"
|
||||
msgid "key1"
|
||||
msgstr "value1-english"
|
||||
|
||||
# base translation: "value2-english"
|
||||
msgid "key2"
|
||||
msgstr "value2-english"
|
||||
|
||||
#--------- Section 2 ---------#
|
||||
|
||||
# base translation: "value3-english"
|
||||
msgid "key3"
|
||||
msgstr "value3-english"
|
||||
|
||||
#. comment key4
|
||||
# base translation: "value4-english"
|
||||
msgid "key4"
|
||||
msgstr "value4-english"
|
14
test/fixtures/formatter_flash.properties
vendored
Normal file
14
test/fixtures/formatter_flash.properties
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
## Flash Strings File
|
||||
## Generated by Twine 0.7.0
|
||||
## Language: en
|
||||
|
||||
## Section 1 ##
|
||||
|
||||
# comment key1
|
||||
key1=value1-english
|
||||
key2=value2-english
|
||||
## Section 2 ##
|
||||
|
||||
key3=value3-english
|
||||
# comment key4
|
||||
key4=value4-english
|
|
@ -200,3 +200,43 @@ class TestTizenFormatter < FormatterTest
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class TestDjangoFormatter < FormatterTest
|
||||
def setup
|
||||
super Twine::Formatters::Django
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Django.new @twine_file, {}
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_django.po'), output_content
|
||||
end
|
||||
end
|
||||
|
||||
class TestFlashFormatter < FormatterTest
|
||||
def setup
|
||||
super Twine::Formatters::Flash
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Flash.new @twine_file, {}
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_flash.properties'), output_content
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue