yury-twine 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/LICENSE +30 -0
- data/README.md +230 -0
- data/bin/twine +7 -0
- data/lib/twine.rb +36 -0
- data/lib/twine/cli.rb +200 -0
- data/lib/twine/encoding.rb +22 -0
- data/lib/twine/formatters.rb +20 -0
- data/lib/twine/formatters/abstract.rb +187 -0
- data/lib/twine/formatters/android.rb +254 -0
- data/lib/twine/formatters/apple.rb +328 -0
- data/lib/twine/output_processor.rb +57 -0
- data/lib/twine/placeholders.rb +54 -0
- data/lib/twine/plugin.rb +62 -0
- data/lib/twine/runner.rb +332 -0
- data/lib/twine/twine_file.rb +266 -0
- data/lib/twine/version.rb +3 -0
- data/test/command_test.rb +14 -0
- data/test/fixtures/consume_loc_drop.zip +0 -0
- data/test/fixtures/enc_utf16be.dummy +0 -0
- data/test/fixtures/enc_utf16be_bom.dummy +0 -0
- data/test/fixtures/enc_utf16le.dummy +0 -0
- data/test/fixtures/enc_utf16le_bom.dummy +0 -0
- data/test/fixtures/enc_utf8.dummy +2 -0
- data/test/fixtures/formatter_android.xml +15 -0
- data/test/fixtures/formatter_apple.strings +20 -0
- data/test/fixtures/formatter_django.po +30 -0
- data/test/fixtures/formatter_flash.properties +15 -0
- data/test/fixtures/formatter_gettext.po +26 -0
- data/test/fixtures/formatter_jquery.json +7 -0
- data/test/fixtures/formatter_tizen.xml +15 -0
- data/test/fixtures/gettext_multiline.po +10 -0
- data/test/fixtures/twine_accent_values.txt +13 -0
- data/test/test_abstract_formatter.rb +165 -0
- data/test/test_cli.rb +304 -0
- data/test/test_consume_loc_drop.rb +27 -0
- data/test/test_consume_localization_file.rb +119 -0
- data/test/test_formatters.rb +363 -0
- data/test/test_generate_all_localization_files.rb +102 -0
- data/test/test_generate_loc_drop.rb +80 -0
- data/test/test_generate_localization_file.rb +91 -0
- data/test/test_output_processor.rb +85 -0
- data/test/test_placeholders.rb +84 -0
- data/test/test_twine_definition.rb +111 -0
- data/test/test_twine_file.rb +58 -0
- data/test/test_validate_twine_file.rb +61 -0
- data/test/twine_file_dsl.rb +46 -0
- data/test/twine_test.rb +48 -0
- metadata +179 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'twine_test'
|
2
|
+
|
3
|
+
class CommandTest < TwineTest
|
4
|
+
def prepare_mock_formatter(formatter_class)
|
5
|
+
twine_file = Twine::TwineFile.new
|
6
|
+
twine_file.language_codes.concat KNOWN_LANGUAGES
|
7
|
+
|
8
|
+
formatter = formatter_class.new
|
9
|
+
formatter.twine_file = twine_file
|
10
|
+
Twine::Formatters.formatters.clear
|
11
|
+
Twine::Formatters.formatters << formatter
|
12
|
+
formatter
|
13
|
+
end
|
14
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Android Strings File -->
|
3
|
+
<!-- Generated by Twine <%= Twine::VERSION %> -->
|
4
|
+
<!-- Language: en -->
|
5
|
+
<resources>
|
6
|
+
<!-- SECTION: Section 1 -->
|
7
|
+
<!-- comment key1 -->
|
8
|
+
<string name="key1">value1-english</string>
|
9
|
+
<string name="key2">value2-english</string>
|
10
|
+
|
11
|
+
<!-- SECTION: Section 2 -->
|
12
|
+
<string name="key3">value3-english</string>
|
13
|
+
<!-- comment key4 -->
|
14
|
+
<string name="key4">value4-english</string>
|
15
|
+
</resources>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* Apple Strings File
|
3
|
+
* Generated by Twine <%= Twine::VERSION %>
|
4
|
+
* Language: en
|
5
|
+
*/
|
6
|
+
|
7
|
+
/********** Section 1 **********/
|
8
|
+
|
9
|
+
/* comment key1 */
|
10
|
+
"key1" = "value1-english";
|
11
|
+
|
12
|
+
"key2" = "value2-english";
|
13
|
+
|
14
|
+
|
15
|
+
/********** Section 2 **********/
|
16
|
+
|
17
|
+
"key3" = "value3-english";
|
18
|
+
|
19
|
+
/* comment key4 */
|
20
|
+
"key4" = "value4-english";
|
@@ -0,0 +1,30 @@
|
|
1
|
+
##
|
2
|
+
# Django Strings File
|
3
|
+
# Generated by Twine <%= Twine::VERSION %>
|
4
|
+
# Language: en
|
5
|
+
msgid ""
|
6
|
+
msgstr ""
|
7
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
8
|
+
|
9
|
+
#--------- Section 1 ---------#
|
10
|
+
|
11
|
+
#. comment key1
|
12
|
+
# base translation: "value1-english"
|
13
|
+
msgid "key1"
|
14
|
+
msgstr "value1-english"
|
15
|
+
|
16
|
+
# base translation: "value2-english"
|
17
|
+
msgid "key2"
|
18
|
+
msgstr "value2-english"
|
19
|
+
|
20
|
+
|
21
|
+
#--------- Section 2 ---------#
|
22
|
+
|
23
|
+
# base translation: "value3-english"
|
24
|
+
msgid "key3"
|
25
|
+
msgstr "value3-english"
|
26
|
+
|
27
|
+
#. comment key4
|
28
|
+
# base translation: "value4-english"
|
29
|
+
msgid "key4"
|
30
|
+
msgstr "value4-english"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
## Flash Strings File
|
2
|
+
## Generated by Twine <%= Twine::VERSION %>
|
3
|
+
## Language: en
|
4
|
+
|
5
|
+
## Section 1 ##
|
6
|
+
|
7
|
+
# comment key1
|
8
|
+
key1=value1-english
|
9
|
+
key2=value2-english
|
10
|
+
|
11
|
+
## Section 2 ##
|
12
|
+
|
13
|
+
key3=value3-english
|
14
|
+
# comment key4
|
15
|
+
key4=value4-english
|
@@ -0,0 +1,26 @@
|
|
1
|
+
msgid ""
|
2
|
+
msgstr ""
|
3
|
+
"Language: en\n"
|
4
|
+
"X-Generator: Twine <%= Twine::VERSION %>\n"
|
5
|
+
|
6
|
+
|
7
|
+
# SECTION: Section 1
|
8
|
+
#. "comment key1"
|
9
|
+
msgctxt "key1"
|
10
|
+
msgid "value1-english"
|
11
|
+
msgstr "value1-english"
|
12
|
+
|
13
|
+
msgctxt "key2"
|
14
|
+
msgid "value2-english"
|
15
|
+
msgstr "value2-english"
|
16
|
+
|
17
|
+
|
18
|
+
# SECTION: Section 2
|
19
|
+
msgctxt "key3"
|
20
|
+
msgid "value3-english"
|
21
|
+
msgstr "value3-english"
|
22
|
+
|
23
|
+
#. "comment key4"
|
24
|
+
msgctxt "key4"
|
25
|
+
msgid "value4-english"
|
26
|
+
msgstr "value4-english"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Tizen Strings File -->
|
3
|
+
<!-- Generated by Twine <%= Twine::VERSION %> -->
|
4
|
+
<!-- Language: en -->
|
5
|
+
<string_table Bversion="2.0.0.201311071819" Dversion="20120315">
|
6
|
+
<!-- SECTION: Section 1 -->
|
7
|
+
<!-- comment key1 -->
|
8
|
+
<text id="IDS_KEY1">value1-english</text>
|
9
|
+
<text id="IDS_KEY2">value2-english</text>
|
10
|
+
|
11
|
+
<!-- SECTION: Section 2 -->
|
12
|
+
<text id="IDS_KEY3">value3-english</text>
|
13
|
+
<!-- comment key4 -->
|
14
|
+
<text id="IDS_KEY4">value4-english</text>
|
15
|
+
</string_table>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
[[Section]]
|
2
|
+
[value_with_leading_accent]
|
3
|
+
en = `value
|
4
|
+
[value_with_trailing_accent]
|
5
|
+
en = value`
|
6
|
+
[value_with_leading_space]
|
7
|
+
en = ` value`
|
8
|
+
[value_with_trailing_space]
|
9
|
+
en = `value `
|
10
|
+
[value_wrapped_by_spaces]
|
11
|
+
en = ` value `
|
12
|
+
[value_wrapped_by_accents]
|
13
|
+
en = ``value``
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'twine_test'
|
2
|
+
|
3
|
+
class TestAbstractFormatter < TwineTest
|
4
|
+
class SetTranslation < TwineTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@twine_file = build_twine_file 'en', 'fr' do
|
9
|
+
add_section 'Section' do
|
10
|
+
add_definition key1: 'value1-english'
|
11
|
+
add_definition key2: { en: 'value2-english', fr: 'value2-french' }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
@formatter = Twine::Formatters::Abstract.new
|
16
|
+
@formatter.twine_file = @twine_file
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_set_translation_updates_existing_value
|
20
|
+
@formatter.set_translation_for_key 'key1', 'en', 'value1-english-updated'
|
21
|
+
|
22
|
+
assert_equal 'value1-english-updated', @twine_file.definitions_by_key['key1'].translations['en']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_set_translation_does_not_alter_other_language
|
26
|
+
@formatter.set_translation_for_key 'key2', 'en', 'value2-english-updated'
|
27
|
+
|
28
|
+
assert_equal 'value2-french', @twine_file.definitions_by_key['key2'].translations['fr']
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_set_translation_escapes_newlines
|
32
|
+
@formatter.set_translation_for_key 'key1', 'en', "new\nline"
|
33
|
+
|
34
|
+
assert_equal 'new\nline', @twine_file.definitions_by_key['key1'].translations['en']
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_set_translation_adds_translation_to_existing_key
|
38
|
+
@formatter.set_translation_for_key 'key1', 'fr', 'value1-french'
|
39
|
+
|
40
|
+
assert_equal 'value1-french', @twine_file.definitions_by_key['key1'].translations['fr']
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_set_translation_does_not_add_new_key
|
44
|
+
@formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
45
|
+
|
46
|
+
assert_nil @twine_file.definitions_by_key['new-key']
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_set_translation_consume_all_adds_new_key
|
50
|
+
formatter = Twine::Formatters::Abstract.new
|
51
|
+
formatter.twine_file = @twine_file
|
52
|
+
formatter.options = { consume_all: true }
|
53
|
+
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
54
|
+
|
55
|
+
assert_equal 'new-key-english', @twine_file.definitions_by_key['new-key'].translations['en']
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_set_translation_consume_all_adds_tags
|
59
|
+
random_tag = SecureRandom.uuid
|
60
|
+
formatter = Twine::Formatters::Abstract.new
|
61
|
+
formatter.twine_file = @twine_file
|
62
|
+
formatter.options = { consume_all: true, tags: [random_tag] }
|
63
|
+
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
64
|
+
|
65
|
+
assert_equal [random_tag], @twine_file.definitions_by_key['new-key'].tags
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_set_translation_adds_new_keys_to_category_uncategoriezed
|
69
|
+
formatter = Twine::Formatters::Abstract.new
|
70
|
+
formatter.twine_file = @twine_file
|
71
|
+
formatter.options = { consume_all: true }
|
72
|
+
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
73
|
+
|
74
|
+
assert_equal 'Uncategorized', @twine_file.sections[0].name
|
75
|
+
assert_equal 'new-key', @twine_file.sections[0].definitions[0].key
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class ValueReference < TwineTest
|
80
|
+
def setup
|
81
|
+
super
|
82
|
+
|
83
|
+
@twine_file = build_twine_file 'en', 'fr' do
|
84
|
+
add_section 'Section' do
|
85
|
+
add_definition refkey: 'ref-value'
|
86
|
+
add_definition key: :refkey
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
@formatter = Twine::Formatters::Abstract.new
|
91
|
+
@formatter.twine_file = @twine_file
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_set_translation_does_not_add_unchanged_translation
|
95
|
+
@formatter.set_translation_for_key 'key', 'en', 'ref-value'
|
96
|
+
|
97
|
+
assert_nil @twine_file.definitions_by_key['key'].translations['en']
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_set_translation_adds_changed_translation
|
101
|
+
@formatter.set_translation_for_key 'key', 'en', 'changed value'
|
102
|
+
|
103
|
+
assert_equal 'changed value', @twine_file.definitions_by_key['key'].translations['en']
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class SetComment < TwineTest
|
108
|
+
def setup
|
109
|
+
super
|
110
|
+
|
111
|
+
@twine_file = build_twine_file 'en' do
|
112
|
+
add_section 'Section' do
|
113
|
+
add_definition key: 'value'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_set_comment_for_key_does_not_update_comment
|
119
|
+
formatter = Twine::Formatters::Abstract.new
|
120
|
+
formatter.twine_file = @twine_file
|
121
|
+
formatter.set_comment_for_key('key', 'comment')
|
122
|
+
|
123
|
+
assert_nil formatter.twine_file.definitions_by_key['key'].comment
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_set_comment_for_key_updates_comment_with_update_comments
|
127
|
+
formatter = Twine::Formatters::Abstract.new
|
128
|
+
formatter.twine_file = @twine_file
|
129
|
+
formatter.options = { consume_comments: true }
|
130
|
+
formatter.set_comment_for_key('key', 'comment')
|
131
|
+
|
132
|
+
assert_equal 'comment', formatter.twine_file.definitions_by_key['key'].comment
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class CommentReference < TwineTest
|
137
|
+
def setup
|
138
|
+
super
|
139
|
+
|
140
|
+
@twine_file = build_twine_file 'en' do
|
141
|
+
add_section 'Section' do
|
142
|
+
add_definition refkey: 'ref-value', comment: 'reference comment'
|
143
|
+
add_definition key: 'value', ref: :refkey
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
@formatter = Twine::Formatters::Abstract.new
|
148
|
+
@formatter.twine_file = @twine_file
|
149
|
+
@formatter.options = { consume_comments: true }
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_set_comment_does_not_add_unchanged_comment
|
153
|
+
@formatter.set_comment_for_key 'key', 'reference comment'
|
154
|
+
|
155
|
+
assert_nil @twine_file.definitions_by_key['key'].raw_comment
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_set_comment_adds_changed_comment
|
159
|
+
@formatter.set_comment_for_key 'key', 'changed comment'
|
160
|
+
|
161
|
+
assert_equal 'changed comment', @twine_file.definitions_by_key['key'].raw_comment
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
data/test/test_cli.rb
ADDED
@@ -0,0 +1,304 @@
|
|
1
|
+
require 'twine_test'
|
2
|
+
|
3
|
+
class CLITest < TwineTest
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
|
7
|
+
@twine_file_path = File.join @output_dir, SecureRandom.uuid
|
8
|
+
@input_path = File.join @output_dir, SecureRandom.uuid
|
9
|
+
@input_dir = @output_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(command)
|
13
|
+
@options = Twine::CLI::parse command.split
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestValidateTwineFile < CLITest
|
17
|
+
def test_command
|
18
|
+
parse "validate-twine-file #{@twine_file_path}"
|
19
|
+
|
20
|
+
assert_equal 'validate-twine-file', @options[:command]
|
21
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_pedantic
|
25
|
+
parse "validate-twine-file #{@twine_file_path} --pedantic"
|
26
|
+
assert @options[:pedantic]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_missing_parameter
|
30
|
+
assert_raises Twine::Error do
|
31
|
+
parse 'validate-twine-file'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_extra_parameter
|
36
|
+
assert_raises Twine::Error do
|
37
|
+
parse 'validate-twine-file twine_file extra'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class TestGenerateLocalizationFile < CLITest
|
43
|
+
def test_command
|
44
|
+
parse "generate-localization-file #{@twine_file_path} #{@output_path}"
|
45
|
+
|
46
|
+
assert_equal 'generate-localization-file', @options[:command]
|
47
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
48
|
+
assert_equal @output_path, @options[:output_path]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_missing_parameter
|
52
|
+
assert_raises Twine::Error do
|
53
|
+
parse 'generate-localization-file twine_file'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_validate
|
58
|
+
parse "generate-localization-file #{@twine_file_path} #{@output_path} --validate"
|
59
|
+
assert @options[:validate]
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_extra_parameter
|
63
|
+
assert_raises Twine::Error do
|
64
|
+
parse 'generate-localization-file twine_file output extra'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_only_allows_one_language
|
69
|
+
assert_raises Twine::Error do
|
70
|
+
parse "generate-localization-file twine_file output --lang en,fr"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class TestGenerateAllLocalizationFiles < CLITest
|
76
|
+
def test_command
|
77
|
+
parse "generate-all-localization-files #{@twine_file_path} #{@output_dir}"
|
78
|
+
|
79
|
+
assert_equal 'generate-all-localization-files', @options[:command]
|
80
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
81
|
+
assert_equal @output_dir, @options[:output_path]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_missing_parameter
|
85
|
+
assert_raises Twine::Error do
|
86
|
+
parse "generate-all-localization-files twine_file"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_validate
|
91
|
+
parse "generate-all-localization-files #{@twine_file_path} #{@output_dir} --validate"
|
92
|
+
assert @options[:validate]
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_extra_parameter
|
96
|
+
assert_raises Twine::Error do
|
97
|
+
parse "generate-all-localization-files twine_file output extra"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class TestConsumeLocalizationFile < CLITest
|
103
|
+
def test_command
|
104
|
+
parse "consume-localization-file #{@twine_file_path} #{@input_path}"
|
105
|
+
|
106
|
+
assert_equal 'consume-localization-file', @options[:command]
|
107
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
108
|
+
assert_equal @input_path, @options[:input_path]
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_missing_parameter
|
112
|
+
assert_raises Twine::Error do
|
113
|
+
parse "consume-localization-file twine_file"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_extra_parameter
|
118
|
+
assert_raises Twine::Error do
|
119
|
+
parse "consume-localization-file twine_file output extra"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_only_allows_one_language
|
124
|
+
assert_raises Twine::Error do
|
125
|
+
parse "consume-localization-file twine_file output --lang en,fr"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class TestConsumeAllLocalizationFiles < CLITest
|
131
|
+
def test_command
|
132
|
+
parse "consume-all-localization-files #{@twine_file_path} #{@input_dir}"
|
133
|
+
|
134
|
+
assert_equal 'consume-all-localization-files', @options[:command]
|
135
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
136
|
+
assert_equal @input_dir, @options[:input_path]
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_missing_parameter
|
140
|
+
assert_raises Twine::Error do
|
141
|
+
parse "consume-all-localization-files twine_file"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_extra_parameter
|
146
|
+
assert_raises Twine::Error do
|
147
|
+
parse "consume-all-localization-files twine_file output extra"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class TestGenerateLocDrop < CLITest
|
153
|
+
def test_command
|
154
|
+
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple"
|
155
|
+
|
156
|
+
assert_equal 'generate-loc-drop', @options[:command]
|
157
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
158
|
+
assert_equal @output_path, @options[:output_path]
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_missing_parameter
|
162
|
+
assert_raises Twine::Error do
|
163
|
+
parse "generate-loc-drop twine_file --format apple"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_validate
|
168
|
+
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple --validate"
|
169
|
+
assert @options[:validate]
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_extra_parameter
|
173
|
+
assert_raises Twine::Error do
|
174
|
+
parse "generate-loc-drop twine_file output extra --format apple"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_format_needed
|
179
|
+
assert_raises Twine::Error do
|
180
|
+
parse "generate-loc-drop twine_file output"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
class TestConsumeLocDrop < CLITest
|
186
|
+
def test_command
|
187
|
+
parse "consume-loc-drop #{@twine_file_path} #{@input_path}"
|
188
|
+
|
189
|
+
assert_equal 'consume-loc-drop', @options[:command]
|
190
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
191
|
+
assert_equal @input_path, @options[:input_path]
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_missing_parameter
|
195
|
+
assert_raises Twine::Error do
|
196
|
+
parse "consume-loc-drop twine_file"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_extra_parameter
|
201
|
+
assert_raises Twine::Error do
|
202
|
+
parse "consume-loc-drop twine_file input extra"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
class TestParameters < CLITest
|
208
|
+
def parse_with(parameter)
|
209
|
+
parse 'validate-twine-file input.txt ' + parameter
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_default_options
|
213
|
+
parse_with ''
|
214
|
+
expected = {command: 'validate-twine-file', twine_file: 'input.txt', include: :all}
|
215
|
+
assert_equal expected, @options
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_create_folders
|
219
|
+
parse_with '--create-folders'
|
220
|
+
assert @options[:create_folders]
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_consume_all
|
224
|
+
parse_with '--consume-all'
|
225
|
+
assert @options[:consume_all]
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_consume_comments
|
229
|
+
parse_with '--consume-comments'
|
230
|
+
assert @options[:consume_comments]
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_untagged
|
234
|
+
parse_with '--untagged'
|
235
|
+
assert @options[:untagged]
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_developer_language
|
239
|
+
random_language = KNOWN_LANGUAGES.sample
|
240
|
+
parse_with "--developer-lang #{random_language}"
|
241
|
+
assert_equal random_language, @options[:developer_language]
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_single_language
|
245
|
+
random_language = KNOWN_LANGUAGES.sample
|
246
|
+
parse_with "--lang #{random_language}"
|
247
|
+
assert_equal [random_language], @options[:languages]
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_multiple_languages
|
251
|
+
random_languages = KNOWN_LANGUAGES.shuffle[0, 3]
|
252
|
+
parse_with "--lang #{random_languages.join(',')}"
|
253
|
+
assert_equal random_languages.sort, @options[:languages].sort
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_single_tag
|
257
|
+
random_tag = "tag#{rand(100)}"
|
258
|
+
parse_with "--tags #{random_tag}"
|
259
|
+
assert_equal [[random_tag]], @options[:tags]
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_multiple_OR_tags
|
263
|
+
random_tags = ["tag#{rand(100)}", "tag#{rand(100)}", "tag#{rand(100)}"]
|
264
|
+
parse_with "--tags #{random_tags.join(',')}"
|
265
|
+
sorted_tags = @options[:tags].map { |tags| tags.sort }
|
266
|
+
assert_equal [random_tags.sort], sorted_tags
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_multiple_AND_tags
|
270
|
+
random_tag_1 = "tag#{rand(100)}"
|
271
|
+
random_tag_2 = "tag#{rand(100)}"
|
272
|
+
parse_with "--tags #{random_tag_1} --tags #{random_tag_2}"
|
273
|
+
assert_equal [[random_tag_1], [random_tag_2]], @options[:tags]
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_format
|
277
|
+
random_format = Twine::Formatters.formatters.sample.format_name.downcase
|
278
|
+
parse_with "--format #{random_format}"
|
279
|
+
assert_equal random_format, @options[:format]
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_include
|
283
|
+
random_set = [:all, :translated, :untranslated].sample
|
284
|
+
parse_with "--include #{random_set}"
|
285
|
+
assert_equal random_set, @options[:include]
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_output_path
|
289
|
+
parse_with "--output-file #{@output_path}"
|
290
|
+
assert_equal @output_path, @options[:output_path]
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_file_name
|
294
|
+
random_filename = "#{rand(10000)}"
|
295
|
+
parse_with "--file-name #{random_filename}"
|
296
|
+
assert_equal random_filename, @options[:file_name]
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_encoding
|
300
|
+
parse_with '--encoding UTF16'
|
301
|
+
assert_equal 'UTF16', @options[:output_encoding]
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|