Removed initializer parameters from Abstract formatter because they were only used in unit tests.
This commit is contained in:
parent
1e363f9c65
commit
b53ecb2be6
4 changed files with 43 additions and 20 deletions
|
@ -6,9 +6,9 @@ module Twine
|
|||
attr_accessor :strings
|
||||
attr_accessor :options
|
||||
|
||||
def initialize(strings = StringsFile.new, options = {})
|
||||
@strings = strings
|
||||
@options = options
|
||||
def initialize
|
||||
@strings = StringsFile.new
|
||||
@options = {}
|
||||
end
|
||||
|
||||
def format_name
|
||||
|
|
|
@ -5,7 +5,8 @@ class CommandTestCase < TwineTestCase
|
|||
strings = Twine::StringsFile.new
|
||||
strings.language_codes.concat KNOWN_LANGUAGES
|
||||
|
||||
formatter = formatter_class.new(strings)
|
||||
formatter = formatter_class.new
|
||||
formatter.strings = strings
|
||||
Twine::Formatters.formatters.clear
|
||||
Twine::Formatters.formatters << formatter
|
||||
formatter
|
||||
|
|
|
@ -12,7 +12,8 @@ class TestAbstractFormatter < TwineTestCase
|
|||
end
|
||||
end
|
||||
|
||||
@formatter = Twine::Formatters::Abstract.new(@strings, {})
|
||||
@formatter = Twine::Formatters::Abstract.new
|
||||
@formatter.strings = @strings
|
||||
end
|
||||
|
||||
def test_set_translation_updates_existing_value
|
||||
|
@ -46,7 +47,9 @@ class TestAbstractFormatter < TwineTestCase
|
|||
end
|
||||
|
||||
def test_set_translation_consume_all_adds_new_key
|
||||
formatter = Twine::Formatters::Abstract.new(@strings, { consume_all: true })
|
||||
formatter = Twine::Formatters::Abstract.new
|
||||
formatter.strings = @strings
|
||||
formatter.options = { consume_all: true }
|
||||
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
||||
|
||||
assert_equal 'new-key-english', @strings.strings_map['new-key'].translations['en']
|
||||
|
@ -54,14 +57,18 @@ class TestAbstractFormatter < TwineTestCase
|
|||
|
||||
def test_set_translation_consume_all_adds_tags
|
||||
random_tag = SecureRandom.uuid
|
||||
formatter = Twine::Formatters::Abstract.new(@strings, { consume_all: true, tags: [random_tag] })
|
||||
formatter = Twine::Formatters::Abstract.new
|
||||
formatter.strings = @strings
|
||||
formatter.options = { consume_all: true, tags: [random_tag] }
|
||||
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
||||
|
||||
assert_equal [random_tag], @strings.strings_map['new-key'].tags
|
||||
end
|
||||
|
||||
def test_set_translation_adds_new_keys_to_category_uncategoriezed
|
||||
formatter = Twine::Formatters::Abstract.new(@strings, { consume_all: true })
|
||||
formatter = Twine::Formatters::Abstract.new
|
||||
formatter.strings = @strings
|
||||
formatter.options = { consume_all: true }
|
||||
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
||||
|
||||
assert_equal 'Uncategorized', @strings.sections[0].name
|
||||
|
@ -80,7 +87,8 @@ class TestAbstractFormatter < TwineTestCase
|
|||
end
|
||||
end
|
||||
|
||||
@formatter = Twine::Formatters::Abstract.new(@strings, {})
|
||||
@formatter = Twine::Formatters::Abstract.new
|
||||
@formatter.strings = @strings
|
||||
end
|
||||
|
||||
def test_set_translation_does_not_add_unchanged_translation
|
||||
|
@ -108,14 +116,17 @@ class TestAbstractFormatter < TwineTestCase
|
|||
end
|
||||
|
||||
def test_set_comment_for_key_does_not_update_comment
|
||||
formatter = Twine::Formatters::Abstract.new(@strings, {})
|
||||
formatter = Twine::Formatters::Abstract.new
|
||||
formatter.strings = @strings
|
||||
formatter.set_comment_for_key('key', 'comment')
|
||||
|
||||
assert_nil formatter.strings.strings_map['key'].comment
|
||||
end
|
||||
|
||||
def test_set_comment_for_key_updates_comment_with_update_comments
|
||||
formatter = Twine::Formatters::Abstract.new(@strings, { consume_comments: true })
|
||||
formatter = Twine::Formatters::Abstract.new
|
||||
formatter.strings = @strings
|
||||
formatter.options = { consume_comments: true }
|
||||
formatter.set_comment_for_key('key', 'comment')
|
||||
|
||||
assert_equal 'comment', formatter.strings.strings_map['key'].comment
|
||||
|
@ -133,7 +144,9 @@ class TestAbstractFormatter < TwineTestCase
|
|||
end
|
||||
end
|
||||
|
||||
@formatter = Twine::Formatters::Abstract.new(@strings, { consume_comments: true })
|
||||
@formatter = Twine::Formatters::Abstract.new
|
||||
@formatter.strings = @strings
|
||||
@formatter.options = { consume_comments: true }
|
||||
end
|
||||
|
||||
def test_set_comment_does_not_add_unchanged_comment
|
||||
|
|
|
@ -17,7 +17,9 @@ class FormatterTest < TwineTestCase
|
|||
end
|
||||
|
||||
@strings = Twine::StringsFile.new
|
||||
@formatter = formatter_class.new @strings, { consume_all: true, consume_comments: true }
|
||||
@formatter = formatter_class.new
|
||||
@formatter.strings = @strings
|
||||
@formatter.options = { consume_all: true, consume_comments: true }
|
||||
end
|
||||
|
||||
def assert_translations_read_correctly
|
||||
|
@ -66,7 +68,8 @@ class TestAndroidFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Android.new @twine_file
|
||||
formatter = Twine::Formatters::Android.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_android.xml'), output_content
|
||||
end
|
||||
|
@ -111,7 +114,8 @@ class TestAppleFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Apple.new @twine_file
|
||||
formatter = Twine::Formatters::Apple.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_apple.strings'), output_content
|
||||
end
|
||||
|
@ -142,7 +146,8 @@ class TestJQueryFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::JQuery.new @twine_file
|
||||
formatter = Twine::Formatters::JQuery.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_jquery.json'), output_content
|
||||
end
|
||||
|
@ -171,7 +176,8 @@ class TestGettextFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Gettext.new @twine_file
|
||||
formatter = Twine::Formatters::Gettext.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_gettext.po'), output_content
|
||||
end
|
||||
|
@ -192,7 +198,8 @@ class TestTizenFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Tizen.new @twine_file
|
||||
formatter = Twine::Formatters::Tizen.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_tizen.xml'), output_content
|
||||
end
|
||||
|
@ -211,7 +218,8 @@ class TestDjangoFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Django.new @twine_file
|
||||
formatter = Twine::Formatters::Django.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_django.po'), output_content
|
||||
end
|
||||
|
@ -229,7 +237,8 @@ class TestFlashFormatter < FormatterTest
|
|||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::Flash.new @twine_file
|
||||
formatter = Twine::Formatters::Flash.new
|
||||
formatter.strings = @twine_file
|
||||
formatter.write_file @output_path, 'en'
|
||||
assert_equal content('formatter_flash.properties'), output_content
|
||||
end
|
||||
|
|
Reference in a new issue