Added test to verify the android formatter unescapes values properly.
This commit is contained in:
parent
60b0eb2adf
commit
a53384c5d7
1 changed files with 22 additions and 15 deletions
|
@ -39,6 +39,20 @@ end
|
|||
class TestAndroidFormatter < FormatterTest
|
||||
def setup
|
||||
super Twine::Formatters::Android
|
||||
|
||||
@escape_test_values = {
|
||||
'this & that' => 'this & that',
|
||||
'this < that' => 'this < that',
|
||||
"it's complicated" => "it\\'s complicated",
|
||||
'a "good" way' => 'a \"good\" way',
|
||||
'<b>bold</b>' => '<b>bold</b>',
|
||||
'<a href="target">link</a>' => '<a href=\"target\">link</a>',
|
||||
|
||||
'<xliff:g></xliff:g>' => '<xliff:g></xliff:g>',
|
||||
'<xliff:g>untouched</xliff:g>' => '<xliff:g>untouched</xliff:g>',
|
||||
'<xliff:g id="42">untouched</xliff:g>' => '<xliff:g id="42">untouched</xliff:g>',
|
||||
'<xliff:g id="1">first</xliff:g> inbetween <xliff:g id="2">second</xliff:g>' => '<xliff:g id="1">first</xliff:g> inbetween <xliff:g id="2">second</xliff:g>'
|
||||
}
|
||||
end
|
||||
|
||||
def test_read_format
|
||||
|
@ -83,6 +97,13 @@ class TestAndroidFormatter < FormatterTest
|
|||
assert_equal '@value', @empty_twine_file.definitions_by_key['key1'].translations['en']
|
||||
end
|
||||
|
||||
def test_set_translation_unescaping
|
||||
@escape_test_values.each do |expected, input|
|
||||
@formatter.set_translation_for_key 'key1', 'en', input
|
||||
assert_equal expected, @empty_twine_file.definitions_by_key['key1'].translations['en']
|
||||
end
|
||||
end
|
||||
|
||||
def test_format_file
|
||||
formatter = Twine::Formatters::Android.new
|
||||
formatter.twine_file = @twine_file
|
||||
|
@ -102,21 +123,7 @@ class TestAndroidFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_format_value_escaping
|
||||
values = {
|
||||
'this & that' => 'this & that',
|
||||
'this < that' => 'this < that',
|
||||
"it's complicated" => "it\\'s complicated",
|
||||
'a "good" way' => 'a \"good\" way',
|
||||
'<b>bold</b>' => '<b>bold</b>',
|
||||
'<a href="target">link</a>' => '<a href=\"target\">link</a>',
|
||||
|
||||
'<xliff:g></xliff:g>' => '<xliff:g></xliff:g>',
|
||||
'<xliff:g>untouched</xliff:g>' => '<xliff:g>untouched</xliff:g>',
|
||||
'<xliff:g id="42">untouched</xliff:g>' => '<xliff:g id="42">untouched</xliff:g>',
|
||||
'<xliff:g id="1">first</xliff:g> inbetween <xliff:g id="2">second</xliff:g>' => '<xliff:g id="1">first</xliff:g> inbetween <xliff:g id="2">second</xliff:g>'
|
||||
}
|
||||
|
||||
values.each do |input, expected|
|
||||
@escape_test_values.each do |input, expected|
|
||||
assert_equal expected, @formatter.format_value(input)
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue