twine 0.9.1 → 0.10.0
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 +4 -4
- data/README.md +56 -69
- data/lib/twine.rb +11 -3
- data/lib/twine/cli.rb +375 -155
- data/lib/twine/formatters.rb +0 -5
- data/lib/twine/formatters/abstract.rb +43 -43
- data/lib/twine/formatters/android.rb +58 -59
- data/lib/twine/formatters/apple.rb +3 -3
- data/lib/twine/formatters/django.rb +15 -21
- data/lib/twine/formatters/flash.rb +17 -20
- data/lib/twine/formatters/gettext.rb +11 -15
- data/lib/twine/formatters/jquery.rb +8 -11
- data/lib/twine/formatters/tizen.rb +4 -4
- data/lib/twine/output_processor.rb +15 -15
- data/lib/twine/placeholders.rb +26 -6
- data/lib/twine/runner.rb +95 -95
- data/lib/twine/{stringsfile.rb → twine_file.rb} +53 -48
- data/lib/twine/version.rb +1 -1
- data/test/{command_test_case.rb → command_test.rb} +5 -5
- data/test/fixtures/{consume_loc_drop.zip → consume_localization_archive.zip} +0 -0
- data/test/fixtures/formatter_django.po +3 -1
- data/test/test_abstract_formatter.rb +40 -40
- data/test/test_cli.rb +313 -211
- data/test/test_consume_localization_archive.rb +27 -0
- data/test/{test_consume_string_file.rb → test_consume_localization_file.rb} +19 -19
- data/test/test_formatters.rb +108 -43
- data/test/{test_generate_all_string_files.rb → test_generate_all_localization_files.rb} +18 -18
- data/test/{test_generate_loc_drop.rb → test_generate_localization_archive.rb} +14 -14
- data/test/{test_generate_string_file.rb → test_generate_localization_file.rb} +18 -18
- data/test/test_output_processor.rb +26 -26
- data/test/test_placeholders.rb +44 -9
- 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 +12 -12
- data/test/{twine_test_case.rb → twine_test.rb} +1 -1
- metadata +23 -23
- data/test/test_consume_loc_drop.rb +0 -27
- data/test/test_strings_file.rb +0 -58
- data/test/test_strings_row.rb +0 -47
- data/test/test_validate_strings_file.rb +0 -61
@@ -1,15 +1,5 @@
|
|
1
1
|
module Twine
|
2
|
-
class
|
3
|
-
attr_reader :name
|
4
|
-
attr_reader :rows
|
5
|
-
|
6
|
-
def initialize(name)
|
7
|
-
@name = name
|
8
|
-
@rows = []
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class StringsRow
|
2
|
+
class TwineDefinition
|
13
3
|
attr_reader :key
|
14
4
|
attr_accessor :comment
|
15
5
|
attr_accessor :tags
|
@@ -32,34 +22,49 @@ module Twine
|
|
32
22
|
@comment
|
33
23
|
end
|
34
24
|
|
25
|
+
# [['tag1', 'tag2'], ['~tag3']] == (tag1 OR tag2) AND (!tag3)
|
35
26
|
def matches_tags?(tags, include_untagged)
|
36
|
-
if tags == nil || tags.empty?
|
37
|
-
# The user did not specify any tags. Everything passes.
|
27
|
+
if tags == nil || tags.empty? # The user did not specify any tags. Everything passes.
|
38
28
|
return true
|
39
|
-
elsif @tags == nil
|
40
|
-
# This row has no tags.
|
29
|
+
elsif @tags == nil # This definition has no tags -> check reference (if any)
|
41
30
|
return reference ? reference.matches_tags?(tags, include_untagged) : include_untagged
|
42
31
|
elsif @tags.empty?
|
43
32
|
return include_untagged
|
44
33
|
else
|
45
|
-
return
|
34
|
+
return tags.all? do |set|
|
35
|
+
regular_tags, negated_tags = set.partition { |tag| tag[0] != '~' }
|
36
|
+
negated_tags.map! { |tag| tag[1..-1] }
|
37
|
+
matches_regular_tags = (!regular_tags.empty? && !(regular_tags & @tags).empty?)
|
38
|
+
matches_negated_tags = (!negated_tags.empty? && (negated_tags & @tags).empty?)
|
39
|
+
matches_regular_tags or matches_negated_tags
|
40
|
+
end
|
46
41
|
end
|
47
42
|
|
48
43
|
return false
|
49
44
|
end
|
50
45
|
|
51
|
-
def
|
46
|
+
def translation_for_lang(lang)
|
52
47
|
translation = [lang].flatten.map { |l| @translations[l] }.first
|
53
48
|
|
54
|
-
translation = reference.
|
49
|
+
translation = reference.translation_for_lang(lang) if translation.nil? && reference
|
55
50
|
|
56
51
|
return translation
|
57
52
|
end
|
58
53
|
end
|
59
54
|
|
60
|
-
class
|
55
|
+
class TwineSection
|
56
|
+
attr_reader :name
|
57
|
+
attr_reader :definitions
|
58
|
+
|
59
|
+
def initialize(name)
|
60
|
+
@name = name
|
61
|
+
@definitions = []
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class TwineFile
|
61
66
|
attr_reader :sections
|
62
|
-
attr_reader :
|
67
|
+
attr_reader :definitions_by_key
|
63
68
|
attr_reader :language_codes
|
64
69
|
|
65
70
|
private
|
@@ -73,7 +78,7 @@ module Twine
|
|
73
78
|
|
74
79
|
def initialize
|
75
80
|
@sections = []
|
76
|
-
@
|
81
|
+
@definitions_by_key = {}
|
77
82
|
@language_codes = []
|
78
83
|
end
|
79
84
|
|
@@ -102,7 +107,7 @@ module Twine
|
|
102
107
|
File.open(path, 'r:UTF-8') do |f|
|
103
108
|
line_num = 0
|
104
109
|
current_section = nil
|
105
|
-
|
110
|
+
current_definition = nil
|
106
111
|
while line = f.gets
|
107
112
|
parsed = false
|
108
113
|
line.strip!
|
@@ -115,20 +120,20 @@ module Twine
|
|
115
120
|
if line.length > 4 && line[0, 2] == '[['
|
116
121
|
match = /^\[\[(.+)\]\]$/.match(line)
|
117
122
|
if match
|
118
|
-
current_section =
|
123
|
+
current_section = TwineSection.new(match[1])
|
119
124
|
@sections << current_section
|
120
125
|
parsed = true
|
121
126
|
end
|
122
127
|
elsif line.length > 2 && line[0, 1] == '['
|
123
128
|
key = match_key(line)
|
124
129
|
if key
|
125
|
-
|
126
|
-
@
|
130
|
+
current_definition = TwineDefinition.new(key)
|
131
|
+
@definitions_by_key[current_definition.key] = current_definition
|
127
132
|
if !current_section
|
128
|
-
current_section =
|
133
|
+
current_section = TwineSection.new('')
|
129
134
|
@sections << current_section
|
130
135
|
end
|
131
|
-
current_section.
|
136
|
+
current_section.definitions << current_definition
|
132
137
|
parsed = true
|
133
138
|
end
|
134
139
|
else
|
@@ -141,16 +146,16 @@ module Twine
|
|
141
146
|
|
142
147
|
case key
|
143
148
|
when 'comment'
|
144
|
-
|
149
|
+
current_definition.comment = value
|
145
150
|
when 'tags'
|
146
|
-
|
151
|
+
current_definition.tags = value.split(',')
|
147
152
|
when 'ref'
|
148
|
-
|
153
|
+
current_definition.reference_key = value if value
|
149
154
|
else
|
150
155
|
if !@language_codes.include? key
|
151
156
|
add_language_code(key)
|
152
157
|
end
|
153
|
-
|
158
|
+
current_definition.translations[key] = value
|
154
159
|
end
|
155
160
|
parsed = true
|
156
161
|
end
|
@@ -163,9 +168,9 @@ module Twine
|
|
163
168
|
end
|
164
169
|
|
165
170
|
# resolve_references
|
166
|
-
@
|
167
|
-
next unless
|
168
|
-
|
171
|
+
@definitions_by_key.each do |key, definition|
|
172
|
+
next unless definition.reference_key
|
173
|
+
definition.reference = @definitions_by_key[definition.reference_key]
|
169
174
|
end
|
170
175
|
end
|
171
176
|
|
@@ -180,26 +185,26 @@ module Twine
|
|
180
185
|
|
181
186
|
f.puts "[[#{section.name}]]"
|
182
187
|
|
183
|
-
section.
|
184
|
-
f.puts "\t[#{
|
188
|
+
section.definitions.each do |definition|
|
189
|
+
f.puts "\t[#{definition.key}]"
|
185
190
|
|
186
|
-
value = write_value(
|
187
|
-
if !value && !
|
188
|
-
puts "Warning: #{
|
191
|
+
value = write_value(definition, dev_lang, f)
|
192
|
+
if !value && !definition.reference_key
|
193
|
+
puts "Warning: #{definition.key} does not exist in developer language '#{dev_lang}'"
|
189
194
|
end
|
190
195
|
|
191
|
-
if
|
192
|
-
f.puts "\t\tref = #{
|
196
|
+
if definition.reference_key
|
197
|
+
f.puts "\t\tref = #{definition.reference_key}"
|
193
198
|
end
|
194
|
-
if
|
195
|
-
tag_str =
|
199
|
+
if definition.tags && definition.tags.length > 0
|
200
|
+
tag_str = definition.tags.join(',')
|
196
201
|
f.puts "\t\ttags = #{tag_str}"
|
197
202
|
end
|
198
|
-
if
|
199
|
-
f.puts "\t\tcomment = #{
|
203
|
+
if definition.raw_comment and definition.raw_comment.length > 0
|
204
|
+
f.puts "\t\tcomment = #{definition.raw_comment}"
|
200
205
|
end
|
201
206
|
@language_codes[1..-1].each do |lang|
|
202
|
-
write_value(
|
207
|
+
write_value(definition, lang, f)
|
203
208
|
end
|
204
209
|
end
|
205
210
|
end
|
@@ -208,8 +213,8 @@ module Twine
|
|
208
213
|
|
209
214
|
private
|
210
215
|
|
211
|
-
def write_value(
|
212
|
-
value =
|
216
|
+
def write_value(definition, language, file)
|
217
|
+
value = definition.translations[language]
|
213
218
|
return nil unless value
|
214
219
|
|
215
220
|
if value[0] == ' ' || value[-1] == ' ' || (value[0] == '`' && value[-1] == '`')
|
data/lib/twine/version.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'twine_test'
|
2
2
|
|
3
|
-
class
|
3
|
+
class CommandTest < TwineTest
|
4
4
|
def prepare_mock_formatter(formatter_class)
|
5
|
-
|
6
|
-
|
5
|
+
twine_file = Twine::TwineFile.new
|
6
|
+
twine_file.language_codes.concat KNOWN_LANGUAGES
|
7
7
|
|
8
8
|
formatter = formatter_class.new
|
9
|
-
formatter.
|
9
|
+
formatter.twine_file = twine_file
|
10
10
|
Twine::Formatters.formatters.clear
|
11
11
|
Twine::Formatters.formatters << formatter
|
12
12
|
formatter
|
File without changes
|
@@ -1,164 +1,164 @@
|
|
1
|
-
require '
|
1
|
+
require 'twine_test'
|
2
2
|
|
3
|
-
class TestAbstractFormatter <
|
4
|
-
class SetTranslation <
|
3
|
+
class TestAbstractFormatter < TwineTest
|
4
|
+
class SetTranslation < TwineTest
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
|
8
|
-
@
|
8
|
+
@twine_file = build_twine_file 'en', 'fr' do
|
9
9
|
add_section 'Section' do
|
10
|
-
|
11
|
-
|
10
|
+
add_definition key1: 'value1-english'
|
11
|
+
add_definition key2: { en: 'value2-english', fr: 'value2-french' }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
@formatter = Twine::Formatters::Abstract.new
|
16
|
-
@formatter.
|
16
|
+
@formatter.twine_file = @twine_file
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_set_translation_updates_existing_value
|
20
20
|
@formatter.set_translation_for_key 'key1', 'en', 'value1-english-updated'
|
21
21
|
|
22
|
-
assert_equal 'value1-english-updated', @
|
22
|
+
assert_equal 'value1-english-updated', @twine_file.definitions_by_key['key1'].translations['en']
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_set_translation_does_not_alter_other_language
|
26
26
|
@formatter.set_translation_for_key 'key2', 'en', 'value2-english-updated'
|
27
27
|
|
28
|
-
assert_equal 'value2-french', @
|
28
|
+
assert_equal 'value2-french', @twine_file.definitions_by_key['key2'].translations['fr']
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_set_translation_escapes_newlines
|
32
32
|
@formatter.set_translation_for_key 'key1', 'en', "new\nline"
|
33
33
|
|
34
|
-
assert_equal 'new\nline', @
|
34
|
+
assert_equal 'new\nline', @twine_file.definitions_by_key['key1'].translations['en']
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_set_translation_adds_translation_to_existing_key
|
38
38
|
@formatter.set_translation_for_key 'key1', 'fr', 'value1-french'
|
39
39
|
|
40
|
-
assert_equal 'value1-french', @
|
40
|
+
assert_equal 'value1-french', @twine_file.definitions_by_key['key1'].translations['fr']
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_set_translation_does_not_add_new_key
|
44
44
|
@formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
45
45
|
|
46
|
-
assert_nil @
|
46
|
+
assert_nil @twine_file.definitions_by_key['new-key']
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_set_translation_consume_all_adds_new_key
|
50
50
|
formatter = Twine::Formatters::Abstract.new
|
51
|
-
formatter.
|
51
|
+
formatter.twine_file = @twine_file
|
52
52
|
formatter.options = { consume_all: true }
|
53
53
|
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
54
54
|
|
55
|
-
assert_equal 'new-key-english', @
|
55
|
+
assert_equal 'new-key-english', @twine_file.definitions_by_key['new-key'].translations['en']
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_set_translation_consume_all_adds_tags
|
59
59
|
random_tag = SecureRandom.uuid
|
60
60
|
formatter = Twine::Formatters::Abstract.new
|
61
|
-
formatter.
|
61
|
+
formatter.twine_file = @twine_file
|
62
62
|
formatter.options = { consume_all: true, tags: [random_tag] }
|
63
63
|
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
64
64
|
|
65
|
-
assert_equal [random_tag], @
|
65
|
+
assert_equal [random_tag], @twine_file.definitions_by_key['new-key'].tags
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_set_translation_adds_new_keys_to_category_uncategoriezed
|
69
69
|
formatter = Twine::Formatters::Abstract.new
|
70
|
-
formatter.
|
70
|
+
formatter.twine_file = @twine_file
|
71
71
|
formatter.options = { consume_all: true }
|
72
72
|
formatter.set_translation_for_key 'new-key', 'en', 'new-key-english'
|
73
73
|
|
74
|
-
assert_equal 'Uncategorized', @
|
75
|
-
assert_equal 'new-key', @
|
74
|
+
assert_equal 'Uncategorized', @twine_file.sections[0].name
|
75
|
+
assert_equal 'new-key', @twine_file.sections[0].definitions[0].key
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
class ValueReference <
|
79
|
+
class ValueReference < TwineTest
|
80
80
|
def setup
|
81
81
|
super
|
82
82
|
|
83
|
-
@
|
83
|
+
@twine_file = build_twine_file 'en', 'fr' do
|
84
84
|
add_section 'Section' do
|
85
|
-
|
86
|
-
|
85
|
+
add_definition refkey: 'ref-value'
|
86
|
+
add_definition key: :refkey
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
@formatter = Twine::Formatters::Abstract.new
|
91
|
-
@formatter.
|
91
|
+
@formatter.twine_file = @twine_file
|
92
92
|
end
|
93
93
|
|
94
94
|
def test_set_translation_does_not_add_unchanged_translation
|
95
95
|
@formatter.set_translation_for_key 'key', 'en', 'ref-value'
|
96
96
|
|
97
|
-
assert_nil @
|
97
|
+
assert_nil @twine_file.definitions_by_key['key'].translations['en']
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_set_translation_adds_changed_translation
|
101
101
|
@formatter.set_translation_for_key 'key', 'en', 'changed value'
|
102
102
|
|
103
|
-
assert_equal 'changed value', @
|
103
|
+
assert_equal 'changed value', @twine_file.definitions_by_key['key'].translations['en']
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
class SetComment <
|
107
|
+
class SetComment < TwineTest
|
108
108
|
def setup
|
109
109
|
super
|
110
110
|
|
111
|
-
@
|
111
|
+
@twine_file = build_twine_file 'en' do
|
112
112
|
add_section 'Section' do
|
113
|
-
|
113
|
+
add_definition key: 'value'
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
def test_set_comment_for_key_does_not_update_comment
|
119
119
|
formatter = Twine::Formatters::Abstract.new
|
120
|
-
formatter.
|
120
|
+
formatter.twine_file = @twine_file
|
121
121
|
formatter.set_comment_for_key('key', 'comment')
|
122
122
|
|
123
|
-
assert_nil formatter.
|
123
|
+
assert_nil formatter.twine_file.definitions_by_key['key'].comment
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_set_comment_for_key_updates_comment_with_update_comments
|
127
127
|
formatter = Twine::Formatters::Abstract.new
|
128
|
-
formatter.
|
128
|
+
formatter.twine_file = @twine_file
|
129
129
|
formatter.options = { consume_comments: true }
|
130
130
|
formatter.set_comment_for_key('key', 'comment')
|
131
131
|
|
132
|
-
assert_equal 'comment', formatter.
|
132
|
+
assert_equal 'comment', formatter.twine_file.definitions_by_key['key'].comment
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
class CommentReference <
|
136
|
+
class CommentReference < TwineTest
|
137
137
|
def setup
|
138
138
|
super
|
139
139
|
|
140
|
-
@
|
140
|
+
@twine_file = build_twine_file 'en' do
|
141
141
|
add_section 'Section' do
|
142
|
-
|
143
|
-
|
142
|
+
add_definition refkey: 'ref-value', comment: 'reference comment'
|
143
|
+
add_definition key: 'value', ref: :refkey
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
147
|
@formatter = Twine::Formatters::Abstract.new
|
148
|
-
@formatter.
|
148
|
+
@formatter.twine_file = @twine_file
|
149
149
|
@formatter.options = { consume_comments: true }
|
150
150
|
end
|
151
151
|
|
152
152
|
def test_set_comment_does_not_add_unchanged_comment
|
153
153
|
@formatter.set_comment_for_key 'key', 'reference comment'
|
154
154
|
|
155
|
-
assert_nil @
|
155
|
+
assert_nil @twine_file.definitions_by_key['key'].raw_comment
|
156
156
|
end
|
157
157
|
|
158
158
|
def test_set_comment_adds_changed_comment
|
159
159
|
@formatter.set_comment_for_key 'key', 'changed comment'
|
160
160
|
|
161
|
-
assert_equal 'changed comment', @
|
161
|
+
assert_equal 'changed comment', @twine_file.definitions_by_key['key'].raw_comment
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
data/test/test_cli.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'twine_test'
|
2
2
|
|
3
|
-
class
|
3
|
+
class CLITest < TwineTest
|
4
4
|
def setup
|
5
|
-
super
|
5
|
+
super()
|
6
6
|
|
7
|
-
@
|
7
|
+
@twine_file_path = File.join @output_dir, SecureRandom.uuid
|
8
8
|
@input_path = File.join @output_dir, SecureRandom.uuid
|
9
9
|
@input_dir = @output_dir
|
10
10
|
end
|
@@ -13,284 +13,386 @@ class CLITestCase < TwineTestCase
|
|
13
13
|
@options = Twine::CLI::parse command.split
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def parse_with(parameters)
|
17
|
+
raise "you need to implement `parse_with` in your test class"
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def assert_option_consume_all
|
21
|
+
parse_with '--consume-all'
|
22
|
+
assert @options[:consume_all]
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def assert_option_consume_comments
|
26
|
+
parse_with '--consume-comments'
|
27
|
+
assert @options[:consume_comments]
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def assert_option_developer_language
|
31
|
+
random_language = KNOWN_LANGUAGES.sample
|
32
|
+
parse_with "--developer-language #{random_language}"
|
33
|
+
assert_equal random_language, @options[:developer_language]
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
36
|
+
def assert_option_encoding
|
37
|
+
parse_with '--encoding UTF16'
|
38
|
+
assert_equal 'UTF16', @options[:encoding]
|
40
39
|
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def assert_option_format
|
42
|
+
random_format = Twine::Formatters.formatters.sample.format_name.downcase
|
43
|
+
parse_with "--format #{random_format}"
|
44
|
+
assert_equal random_format, @options[:format]
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def assert_option_include
|
48
|
+
random_set = [:all, :translated, :untranslated].sample
|
49
|
+
parse_with "--include #{random_set}"
|
50
|
+
assert_equal random_set, @options[:include]
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def assert_option_single_language
|
54
|
+
random_language = KNOWN_LANGUAGES.sample
|
55
|
+
parse_with "--lang #{random_language}"
|
56
|
+
assert_equal [random_language], @options[:languages]
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def assert_option_multiple_languages
|
60
|
+
random_languages = KNOWN_LANGUAGES.shuffle[0, 3]
|
61
|
+
parse_with "--lang #{random_languages.join(',')}"
|
62
|
+
assert_equal random_languages.sort, @options[:languages].sort
|
63
|
+
end
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
65
|
+
def assert_option_languages
|
66
|
+
assert_option_single_language
|
67
|
+
assert_option_multiple_languages
|
68
|
+
end
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
70
|
+
def assert_option_output_path
|
71
|
+
parse_with "--output-file #{@output_path}"
|
72
|
+
assert_equal @output_path, @options[:output_path]
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
def assert_option_tags
|
76
|
+
# single tag
|
77
|
+
random_tag = "tag#{rand(100)}"
|
78
|
+
parse_with "--tags #{random_tag}"
|
79
|
+
assert_equal [[random_tag]], @options[:tags]
|
80
|
+
|
81
|
+
# multiple OR tags
|
82
|
+
random_tags = ["tag#{rand(100)}", "tag#{rand(100)}", "tag#{rand(100)}"]
|
83
|
+
parse_with "--tags #{random_tags.join(',')}"
|
84
|
+
sorted_tags = @options[:tags].map { |tags| tags.sort }
|
85
|
+
assert_equal [random_tags.sort], sorted_tags
|
86
|
+
|
87
|
+
# multiple AND tags
|
88
|
+
random_tag_1 = "tag#{rand(100)}"
|
89
|
+
random_tag_2 = "tag#{rand(100)}"
|
90
|
+
parse_with "--tags #{random_tag_1} --tags #{random_tag_2}"
|
91
|
+
assert_equal [[random_tag_1], [random_tag_2]], @options[:tags]
|
92
|
+
|
93
|
+
# NOT tag
|
94
|
+
random_tag = "~tag#{rand(100)}"
|
95
|
+
parse_with "--tags #{random_tag}"
|
96
|
+
assert_equal [[random_tag]], @options[:tags]
|
97
|
+
end
|
78
98
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
99
|
+
def assert_option_untagged
|
100
|
+
parse_with '--untagged'
|
101
|
+
assert @options[:untagged]
|
102
|
+
end
|
83
103
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
104
|
+
def assert_option_validate
|
105
|
+
parse_with "--validate"
|
106
|
+
assert @options[:validate]
|
107
|
+
end
|
108
|
+
end
|
89
109
|
|
90
|
-
|
91
|
-
|
92
|
-
|
110
|
+
class TestGenerateLocalizationFileCLI < CLITest
|
111
|
+
def parse_with(parameters)
|
112
|
+
parse "generate-localization-file #{@twine_file_path} #{@output_path} " + parameters
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_command
|
116
|
+
parse_with ""
|
117
|
+
|
118
|
+
assert_equal 'generate-localization-file', @options[:command]
|
119
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
120
|
+
assert_equal @output_path, @options[:output_path]
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_missing_argument
|
124
|
+
assert_raises Twine::Error do
|
125
|
+
parse "generate-localization-file #{@twine_file}"
|
93
126
|
end
|
127
|
+
end
|
94
128
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
129
|
+
def test_extra_argument
|
130
|
+
assert_raises Twine::Error do
|
131
|
+
parse_with "extra"
|
99
132
|
end
|
100
133
|
end
|
101
134
|
|
102
|
-
|
103
|
-
|
104
|
-
|
135
|
+
def test_options
|
136
|
+
assert_option_developer_language
|
137
|
+
assert_option_encoding
|
138
|
+
assert_option_format
|
139
|
+
assert_option_include
|
140
|
+
assert_option_single_language
|
141
|
+
assert_raises(Twine::Error) { assert_option_multiple_languages }
|
142
|
+
assert_option_tags
|
143
|
+
assert_option_untagged
|
144
|
+
assert_option_validate
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class TestGenerateAllLocalizationFilesCLI < CLITest
|
149
|
+
def parse_with(parameters)
|
150
|
+
parse "generate-all-localization-files #{@twine_file_path} #{@output_dir} " + parameters
|
151
|
+
end
|
105
152
|
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal @input_path, @options[:input_path]
|
109
|
-
end
|
153
|
+
def test_command
|
154
|
+
parse_with ""
|
110
155
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
156
|
+
assert_equal 'generate-all-localization-files', @options[:command]
|
157
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
158
|
+
assert_equal @output_dir, @options[:output_path]
|
159
|
+
end
|
116
160
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
161
|
+
def test_missing_argument
|
162
|
+
assert_raises Twine::Error do
|
163
|
+
parse "generate-all-localization-files twine_file"
|
121
164
|
end
|
165
|
+
end
|
122
166
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
167
|
+
def test_extra_arguemnt
|
168
|
+
assert_raises Twine::Error do
|
169
|
+
parse_with "extra"
|
127
170
|
end
|
128
171
|
end
|
129
172
|
|
130
|
-
|
131
|
-
|
132
|
-
|
173
|
+
def test_options
|
174
|
+
assert_option_developer_language
|
175
|
+
assert_option_encoding
|
176
|
+
assert_option_format
|
177
|
+
assert_option_include
|
178
|
+
assert_option_tags
|
179
|
+
assert_option_untagged
|
180
|
+
assert_option_validate
|
181
|
+
end
|
133
182
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
183
|
+
def test_option_create_folders
|
184
|
+
parse_with '--create-folders'
|
185
|
+
assert @options[:create_folders]
|
186
|
+
end
|
138
187
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
188
|
+
def test_option_file_name
|
189
|
+
random_filename = "#{rand(10000)}"
|
190
|
+
parse_with "--file-name #{random_filename}"
|
191
|
+
assert_equal random_filename, @options[:file_name]
|
192
|
+
end
|
193
|
+
end
|
144
194
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
195
|
+
class TestGenerateLocalizationArchiveCLI < CLITest
|
196
|
+
def parse_with(parameters)
|
197
|
+
parse "generate-localization-archive #{@twine_file_path} #{@output_path} --format apple " + parameters
|
150
198
|
end
|
151
199
|
|
152
|
-
|
153
|
-
|
154
|
-
parse "generate-loc-drop #{@strings_file_path} #{@output_path} --format apple"
|
200
|
+
def test_command
|
201
|
+
parse_with ""
|
155
202
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
203
|
+
assert_equal 'generate-localization-archive', @options[:command]
|
204
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
205
|
+
assert_equal @output_path, @options[:output_path]
|
206
|
+
end
|
160
207
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
208
|
+
def test_missing_argument
|
209
|
+
assert_raises Twine::Error do
|
210
|
+
parse "generate-localization-archive twine_file --format apple"
|
165
211
|
end
|
212
|
+
end
|
166
213
|
|
167
|
-
|
168
|
-
|
169
|
-
|
214
|
+
def test_extra_argument
|
215
|
+
assert_raises Twine::Error do
|
216
|
+
parse_with "extra"
|
170
217
|
end
|
218
|
+
end
|
171
219
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
220
|
+
def test_options
|
221
|
+
assert_option_developer_language
|
222
|
+
assert_option_encoding
|
223
|
+
assert_option_include
|
224
|
+
assert_option_tags
|
225
|
+
assert_option_untagged
|
226
|
+
assert_option_validate
|
227
|
+
end
|
177
228
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
end
|
229
|
+
def test_option_format_required
|
230
|
+
assert_raises Twine::Error do
|
231
|
+
parse "generate-localization-archive twine_file output"
|
182
232
|
end
|
183
233
|
end
|
184
234
|
|
185
|
-
|
186
|
-
|
187
|
-
|
235
|
+
def test_supports_deprecated_command
|
236
|
+
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple"
|
237
|
+
assert_equal 'generate-localization-archive', @options[:command]
|
238
|
+
end
|
188
239
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
240
|
+
def test_deprecated_command_prints_warning
|
241
|
+
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple"
|
242
|
+
assert_match "WARNING: Twine commands names have changed.", Twine::stderr.string
|
243
|
+
end
|
244
|
+
end
|
193
245
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
246
|
+
class TestConsumeLocalizationFileCLI < CLITest
|
247
|
+
def parse_with(parameters)
|
248
|
+
parse "consume-localization-file #{@twine_file_path} #{@input_path} " + parameters
|
249
|
+
end
|
199
250
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
251
|
+
def test_command
|
252
|
+
parse_with ""
|
253
|
+
|
254
|
+
assert_equal 'consume-localization-file', @options[:command]
|
255
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
256
|
+
assert_equal @input_path, @options[:input_path]
|
205
257
|
end
|
206
258
|
|
207
|
-
|
208
|
-
|
209
|
-
parse
|
259
|
+
def test_missing_argument
|
260
|
+
assert_raises Twine::Error do
|
261
|
+
parse "consume-localization-file twine_file"
|
210
262
|
end
|
263
|
+
end
|
211
264
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
assert_equal expected, @options
|
265
|
+
def test_extra_argument
|
266
|
+
assert_raises Twine::Error do
|
267
|
+
parse_with "extra"
|
216
268
|
end
|
269
|
+
end
|
217
270
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
271
|
+
def test_options
|
272
|
+
assert_option_consume_all
|
273
|
+
assert_option_consume_comments
|
274
|
+
assert_option_developer_language
|
275
|
+
assert_option_encoding
|
276
|
+
assert_option_format
|
277
|
+
assert_option_single_language
|
278
|
+
assert_raises(Twine::Error) { assert_option_multiple_languages }
|
279
|
+
assert_option_output_path
|
280
|
+
assert_option_tags
|
281
|
+
end
|
282
|
+
end
|
222
283
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
284
|
+
class TestConsumeAllLocalizationFilesCLI < CLITest
|
285
|
+
def parse_with(parameters)
|
286
|
+
parse "consume-all-localization-files #{@twine_file_path} #{@input_dir} " + parameters
|
287
|
+
end
|
227
288
|
|
228
|
-
|
229
|
-
|
230
|
-
assert @options[:consume_comments]
|
231
|
-
end
|
289
|
+
def test_command
|
290
|
+
parse_with ""
|
232
291
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
292
|
+
assert_equal 'consume-all-localization-files', @options[:command]
|
293
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
294
|
+
assert_equal @input_dir, @options[:input_path]
|
295
|
+
end
|
237
296
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
assert_equal random_language, @options[:developer_language]
|
297
|
+
def test_missing_argument
|
298
|
+
assert_raises Twine::Error do
|
299
|
+
parse "consume-all-localization-files twine_file"
|
242
300
|
end
|
301
|
+
end
|
243
302
|
|
244
|
-
|
245
|
-
|
246
|
-
parse_with "
|
247
|
-
assert_equal [random_language], @options[:languages]
|
303
|
+
def test_extra_argument
|
304
|
+
assert_raises Twine::Error do
|
305
|
+
parse_with "extra"
|
248
306
|
end
|
307
|
+
end
|
249
308
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
309
|
+
def test_options
|
310
|
+
assert_option_consume_all
|
311
|
+
assert_option_consume_comments
|
312
|
+
assert_option_developer_language
|
313
|
+
assert_option_encoding
|
314
|
+
assert_option_format
|
315
|
+
assert_option_output_path
|
316
|
+
assert_option_tags
|
317
|
+
end
|
318
|
+
end
|
255
319
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
end
|
320
|
+
class TestConsumeLocalizationArchiveCLI < CLITest
|
321
|
+
def parse_with(parameters)
|
322
|
+
parse "consume-localization-archive #{@twine_file_path} #{@input_path} " + parameters
|
323
|
+
end
|
261
324
|
|
262
|
-
|
263
|
-
|
264
|
-
parse_with "--tags #{random_tags.join(',')}"
|
265
|
-
assert_equal random_tags.sort, @options[:tags].sort
|
266
|
-
end
|
325
|
+
def test_command
|
326
|
+
parse_with ""
|
267
327
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
end
|
328
|
+
assert_equal 'consume-localization-archive', @options[:command]
|
329
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
330
|
+
assert_equal @input_path, @options[:input_path]
|
331
|
+
end
|
273
332
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
assert_equal random_set, @options[:include]
|
333
|
+
def test_missing_argument
|
334
|
+
assert_raises Twine::Error do
|
335
|
+
parse "consume-localization-archive twine_file"
|
278
336
|
end
|
337
|
+
end
|
279
338
|
|
280
|
-
|
281
|
-
|
282
|
-
|
339
|
+
def test_extra_argument
|
340
|
+
assert_raises Twine::Error do
|
341
|
+
parse_with "extra"
|
283
342
|
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_options
|
346
|
+
assert_option_consume_all
|
347
|
+
assert_option_consume_comments
|
348
|
+
assert_option_developer_language
|
349
|
+
assert_option_encoding
|
350
|
+
assert_option_format
|
351
|
+
assert_option_output_path
|
352
|
+
assert_option_tags
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_supports_deprecated_command
|
356
|
+
parse "consume-loc-drop #{@twine_file_path} #{@input_path}"
|
357
|
+
assert_equal 'consume-localization-archive', @options[:command]
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_deprecated_command_prints_warning
|
361
|
+
parse "consume-loc-drop #{@twine_file_path} #{@input_path}"
|
362
|
+
assert_match "WARNING: Twine commands names have changed.", Twine::stderr.string
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
class TestValidateTwineFileCLI < CLITest
|
367
|
+
def parse_with(parameters)
|
368
|
+
parse "validate-twine-file #{@twine_file_path} " + parameters
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_command
|
372
|
+
parse_with ""
|
373
|
+
|
374
|
+
assert_equal 'validate-twine-file', @options[:command]
|
375
|
+
assert_equal @twine_file_path, @options[:twine_file]
|
376
|
+
end
|
284
377
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
assert_equal random_filename, @options[:file_name]
|
378
|
+
def test_missing_argument
|
379
|
+
assert_raises Twine::Error do
|
380
|
+
parse 'validate-twine-file'
|
289
381
|
end
|
382
|
+
end
|
290
383
|
|
291
|
-
|
292
|
-
|
293
|
-
|
384
|
+
def test_extra_argument
|
385
|
+
assert_raises Twine::Error do
|
386
|
+
parse_with 'extra'
|
294
387
|
end
|
295
388
|
end
|
389
|
+
|
390
|
+
def test_options
|
391
|
+
assert_option_developer_language
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_option_pedantic
|
395
|
+
parse "validate-twine-file #{@twine_file_path} --pedantic"
|
396
|
+
assert @options[:pedantic]
|
397
|
+
end
|
296
398
|
end
|