diff options
author | Sebastian Ludwig <sebastian@lurado.de> | 2016-11-23 00:26:24 +0300 |
---|---|---|
committer | Sebastian Ludwig <sebastian@lurado.de> | 2016-12-08 12:18:15 +0300 |
commit | 280914bdc53cc607bf64633e608c4979776af843 (patch) | |
tree | 4174b04143340f44cd50b68a752a47078cfac544 /test | |
parent | 74d7cb1d85ed1d2b06ce567ab93dd74a0805c7d7 (diff) |
Fixed #169 by adding proper placeholder handling to Flash formatter.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_formatters.rb | 9 | ||||
-rw-r--r-- | test/test_placeholders.rb | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/test/test_formatters.rb b/test/test_formatters.rb index b25662a..38fb0d2 100644 --- a/test/test_formatters.rb +++ b/test/test_formatters.rb @@ -338,9 +338,18 @@ class TestFlashFormatter < FormatterTest assert_file_contents_read_correctly end + def test_set_translation_converts_placeholders + @formatter.set_translation_for_key 'key1', 'en', "value {#{rand(10)}}" + assert_equal 'value %@', @empty_twine_file.definitions_by_key['key1'].translations['en'] + end + def test_format_file formatter = Twine::Formatters::Flash.new formatter.twine_file = @twine_file assert_equal content('formatter_flash.properties'), formatter.format_file('en') end + + def test_format_value_converts_placeholders + assert_equal "value {0}", @formatter.format_value('value %d') + end end diff --git a/test/test_placeholders.rb b/test/test_placeholders.rb index 55d0f02..e67625e 100644 --- a/test/test_placeholders.rb +++ b/test/test_placeholders.rb @@ -86,4 +86,32 @@ class PlaceholderTest < TwineTest assert_equal "some %@ value", from_android("some %s value") end end + + class ToFlash < PlaceholderTest + def to_flash(value) + Twine::Placeholders.convert_placeholders_from_twine_to_flash(value) + end + + def test_replaces_placeholder + assert_equal "some {0} text", to_flash("some #{placeholder} text") + end + + def test_replaces_string_placeholder + assert_equal "some {0} text", to_flash("some #{placeholder('@')} text") + end + + def test_numbers_placeholders + assert_equal "some {0} more {1} text {2}", to_flash("some #{placeholder('@')} more #{placeholder('@')} text #{placeholder('@')}") + end + end + + class FromFlash < PlaceholderTest + def from_flash(value) + Twine::Placeholders.convert_placeholders_from_flash_to_twine(value) + end + + def test_maps_all_placeholders_to_string + assert_equal "some %@ more %@ text %@", from_flash("some {0} more {1} text {2}") + end + end end |