babelish_rnc 1.0.0.pre
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/.babelish.sample +35 -0
- data/.gitignore +34 -0
- data/.hound.yml +4 -0
- data/.travis.yml +15 -0
- data/CONTRIBUTING.md +12 -0
- data/Dockerfile +6 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.md +73 -0
- data/Rakefile +17 -0
- data/babelish.gemspec +41 -0
- data/babelish_rnc.gemspec +42 -0
- data/bin/babelish_rnc +6 -0
- data/lib/babelish_rnc.rb +31 -0
- data/lib/babelish_rnc/android2csv.rb +28 -0
- data/lib/babelish_rnc/base2csv.rb +103 -0
- data/lib/babelish_rnc/commandline.rb +188 -0
- data/lib/babelish_rnc/csv2android.rb +53 -0
- data/lib/babelish_rnc/csv2base.rb +189 -0
- data/lib/babelish_rnc/csv2json.rb +21 -0
- data/lib/babelish_rnc/csv2php.rb +25 -0
- data/lib/babelish_rnc/csv2strings.rb +34 -0
- data/lib/babelish_rnc/google_doc.rb +55 -0
- data/lib/babelish_rnc/json2csv.rb +20 -0
- data/lib/babelish_rnc/language.rb +30 -0
- data/lib/babelish_rnc/php2csv.rb +30 -0
- data/lib/babelish_rnc/strings2csv.rb +61 -0
- data/lib/babelish_rnc/version.rb +3 -0
- data/lib/babelish_rnc/xcode_macros.rb +49 -0
- data/test/babelish_rnc/commands/test_command_android2csv.rb +60 -0
- data/test/babelish_rnc/commands/test_command_csv2android.rb +35 -0
- data/test/babelish_rnc/commands/test_command_csv2strings.rb +139 -0
- data/test/babelish_rnc/commands/test_command_strings2csv.rb +110 -0
- data/test/babelish_rnc/test_android2csv.rb +53 -0
- data/test/babelish_rnc/test_base2csv.rb +43 -0
- data/test/babelish_rnc/test_bins.rb +32 -0
- data/test/babelish_rnc/test_commandline.rb +127 -0
- data/test/babelish_rnc/test_csv2android.rb +72 -0
- data/test/babelish_rnc/test_csv2base.rb +44 -0
- data/test/babelish_rnc/test_csv2json.rb +27 -0
- data/test/babelish_rnc/test_csv2php.rb +27 -0
- data/test/babelish_rnc/test_csv2strings.rb +154 -0
- data/test/babelish_rnc/test_json2csv.rb +34 -0
- data/test/babelish_rnc/test_php2csv.rb +73 -0
- data/test/babelish_rnc/test_strings2csv.rb +147 -0
- data/test/babelish_rnc/test_xcode_macros.rb +112 -0
- data/test/data/android-en.xml +9 -0
- data/test/data/android-fr.xml +9 -0
- data/test/data/android.xml +9 -0
- data/test/data/android_special_chars.csv +8 -0
- data/test/data/android_special_chars.xml +12 -0
- data/test/data/android_special_chars_test_result.xml +10 -0
- data/test/data/genstrings.strings +0 -0
- data/test/data/json.json +6 -0
- data/test/data/php_lang.php +8 -0
- data/test/data/test_comments.strings +2 -0
- data/test/data/test_data.csv +3 -0
- data/test/data/test_data.strings +2 -0
- data/test/data/test_data_fr_with_comments.strings +6 -0
- data/test/data/test_data_fr_with_comments.xml +9 -0
- data/test/data/test_data_multiple_langs.csv +3 -0
- data/test/data/test_data_with_comments.csv +3 -0
- data/test/data/test_data_with_percent.csv +3 -0
- data/test/data/test_data_with_percent_space.csv +4 -0
- data/test/data/test_data_with_semicolon.csv +3 -0
- data/test/data/test_data_with_spaces.csv +3 -0
- data/test/data/test_en.strings +2 -0
- data/test/data/test_fr.strings +2 -0
- data/test/data/test_space.strings +10 -0
- data/test/data/test_utf16.strings +0 -0
- data/test/data/test_with_nil.csv +3 -0
- data/test/data/test_with_nil.strings +4 -0
- data/test/data/xcode_empty.strings +7 -0
- data/test/test_helper.rb +17 -0
- metadata +311 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestCSV2JSON < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_converting_csv_to_dotstrings
|
5
|
+
csv_file = "test/data/test_data.csv"
|
6
|
+
converter = BabelishRnc::CSV2JSON.new(csv_file, 'English' => "en")
|
7
|
+
converter.convert
|
8
|
+
assert File.exist?("en.json"), "the ouptut file does not exist"
|
9
|
+
|
10
|
+
# clean up
|
11
|
+
system("rm -rf en.json")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_converting_csv_to_dotstrings_one_output_option
|
15
|
+
csv_file = "test/data/test_data.csv"
|
16
|
+
single_file = 'myfile.js'
|
17
|
+
converter = BabelishRnc::CSV2JSON.new(csv_file,
|
18
|
+
{'English' => "en"},
|
19
|
+
:output_basename => 'myfile',
|
20
|
+
:ignore_lang_path => true)
|
21
|
+
converter.convert
|
22
|
+
assert File.exist?(single_file), "the ouptut file does not exist"
|
23
|
+
|
24
|
+
# clean up
|
25
|
+
system("rm -rf ./" + single_file)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
class TestCSV2Php < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_converting_csv_to_dotstrings
|
5
|
+
csv_file = "test/data/test_data.csv"
|
6
|
+
converter = BabelishRnc::CSV2Php.new(csv_file, 'English' => "en")
|
7
|
+
converter.convert
|
8
|
+
assert File.exist?("en/lang.php"), "the ouptut file does not exist"
|
9
|
+
|
10
|
+
# clean up
|
11
|
+
system("rm -rf ./en")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_converting_csv_to_dotstrings_one_output_option
|
15
|
+
csv_file = "test/data/test_data.csv"
|
16
|
+
single_file = 'myApp.php'
|
17
|
+
converter = BabelishRnc::CSV2Php.new(csv_file,
|
18
|
+
{'English' => "en"},
|
19
|
+
:output_basename => 'myApp',
|
20
|
+
:ignore_lang_path => true)
|
21
|
+
converter.convert
|
22
|
+
assert File.exist?(single_file), "the ouptut file does not exist"
|
23
|
+
|
24
|
+
# clean up
|
25
|
+
system("rm -rf ./" + single_file)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestCSV2Strings < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_converting_csv_to_dotstrings
|
5
|
+
csv_file = "test/data/test_data.csv"
|
6
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file, 'English' => [:en])
|
7
|
+
converter.convert
|
8
|
+
assert File.exist?("en.lproj/Localizable.strings"), "the ouptut file does not exist"
|
9
|
+
system("rm -rf en.lproj/")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_converting_csv_to_dotstrings_one_output_option
|
13
|
+
csv_file = "test/data/test_data.csv"
|
14
|
+
single_file = 'myApp.strings'
|
15
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file,
|
16
|
+
{'English' => [:en]},
|
17
|
+
:output_basename => 'myApp',
|
18
|
+
:ignore_lang_path => true)
|
19
|
+
converter.convert
|
20
|
+
assert File.exist?(single_file), "the ouptut file does not exist"
|
21
|
+
system("rm -f #{single_file}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_converting_csv_to_dotstrings_default_lang
|
25
|
+
expected_output = String.new(<<-EOS)
|
26
|
+
"GREETINGS" = "Buenos dias";
|
27
|
+
"ANOTHER_STRING" = "testEN";
|
28
|
+
EOS
|
29
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
30
|
+
spanish_file = "es.lproj/Localizable.strings"
|
31
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file,
|
32
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"},
|
33
|
+
:default_lang => "English")
|
34
|
+
converter.convert
|
35
|
+
assert File.exist?(spanish_file), "the ouptut file does not exist"
|
36
|
+
result = File.read(spanish_file)
|
37
|
+
assert_equal expected_output, result
|
38
|
+
system("rm -rf *.lproj")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_converting_csv_to_dotstrings_with_no_default_lang_is_empty
|
42
|
+
expected_output = String.new(<<-EOS)
|
43
|
+
"GREETINGS" = "Buenos dias";
|
44
|
+
"ANOTHER_STRING" = "";
|
45
|
+
EOS
|
46
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
47
|
+
spanish_file = "es.lproj/Localizable.strings"
|
48
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file,
|
49
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"})
|
50
|
+
converter.convert
|
51
|
+
assert File.exist?(spanish_file), "the ouptut file does not exist"
|
52
|
+
result = File.read(spanish_file)
|
53
|
+
assert_equal expected_output, result
|
54
|
+
system("rm -rf *.lproj")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_converting_csv_to_dotstrings_default_lang_to_key
|
58
|
+
expected_output = String.new(<<-EOS)
|
59
|
+
"GREETINGS" = "Buenos dias";
|
60
|
+
"ANOTHER_STRING" = "ANOTHER_STRING";
|
61
|
+
EOS
|
62
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
63
|
+
spanish_file = "es.lproj/Localizable.strings"
|
64
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file,
|
65
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"},
|
66
|
+
:default_lang => "variables")
|
67
|
+
converter.convert
|
68
|
+
assert File.exist?(spanish_file), "the ouptut file does not exist"
|
69
|
+
result = File.read(spanish_file)
|
70
|
+
assert_equal expected_output, result
|
71
|
+
system("rm -rf *.lproj")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_converting_csv_to_dotstrings_keys
|
75
|
+
expected_output = String.new(<<-EOS)
|
76
|
+
"GREETINGS" = "Buenos dias";
|
77
|
+
"ANOTHER_STRING" = "ANOTHER_STRING";
|
78
|
+
EOS
|
79
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
80
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file,
|
81
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"},
|
82
|
+
:default_lang => "variables")
|
83
|
+
converter.convert
|
84
|
+
assert !converter.keys.empty?
|
85
|
+
system("rm -rf *.lproj")
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_converting_csv_to_dotstrings_with_percent
|
89
|
+
expected_output = String.new(<<-EOS)
|
90
|
+
"GREETINGS" = "hello_%@";
|
91
|
+
"ANOTHER_STRING" = "hello";
|
92
|
+
EOS
|
93
|
+
csv_file = "test/data/test_data_with_percent.csv"
|
94
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file, "English" => [:en])
|
95
|
+
converter.convert
|
96
|
+
result = File.read("en.lproj/Localizable.strings")
|
97
|
+
assert_equal expected_output, result
|
98
|
+
system("rm -rf *.lproj")
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_converting_csv_to_dotstrings_with_spaces
|
102
|
+
expected_output = String.new(<<-EOS)
|
103
|
+
"GREETINGS " = "hello ";
|
104
|
+
"ANOTHER_STRING" = " my other string with space at begin";
|
105
|
+
EOS
|
106
|
+
csv_file = "test/data/test_data_with_spaces.csv"
|
107
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file, "English" => [:en])
|
108
|
+
converter.convert
|
109
|
+
result = File.read("en.lproj/Localizable.strings")
|
110
|
+
assert_equal expected_output, result
|
111
|
+
system("rm -rf *.lproj")
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_converting_csv_to_dotstrings_with_percent_space
|
115
|
+
expected_output = String.new(<<-EOS)
|
116
|
+
"GREETINGS" = "you have %d points";
|
117
|
+
"ANOTHER_STRING" = "this is a string with 10% of juice";
|
118
|
+
"ANOTHER_EXAMPLE" = "tu as fait 10% d'efforts";
|
119
|
+
EOS
|
120
|
+
csv_file = "test/data/test_data_with_percent_space.csv"
|
121
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file, "English" => [:en])
|
122
|
+
converter.convert
|
123
|
+
result = File.read("en.lproj/Localizable.strings")
|
124
|
+
assert_equal expected_output, result
|
125
|
+
system("rm -rf *.lproj")
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_converting_csv_to_dotstrings_with_stripping_option
|
129
|
+
expected_output = String.new(<<-EOS)
|
130
|
+
"GREETINGS" = "hello";
|
131
|
+
"ANOTHER_STRING" = "my other string with space at begin";
|
132
|
+
EOS
|
133
|
+
csv_file = "test/data/test_data_with_spaces.csv"
|
134
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file, {"English" => [:en]}, :stripping => true)
|
135
|
+
converter.convert
|
136
|
+
result = File.read("en.lproj/Localizable.strings")
|
137
|
+
assert_equal expected_output, result
|
138
|
+
system("rm -rf *.lproj")
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_converting_with_comments
|
142
|
+
csv_file = "test/data/test_data_with_comments.csv"
|
143
|
+
spanish_file = "fr.lproj/Localizable.strings"
|
144
|
+
expected_output = File.read("test/data/test_data_fr_with_comments.strings")
|
145
|
+
converter = BabelishRnc::CSV2Strings.new(csv_file,
|
146
|
+
{"French" => "fr"},
|
147
|
+
:default_lang => "English", :comments_column => 5)
|
148
|
+
converter.convert
|
149
|
+
assert File.exist?(spanish_file), "the ouptut file does not exist"
|
150
|
+
result = File.read(spanish_file)
|
151
|
+
assert_equal expected_output, result
|
152
|
+
system("rm -rf *.lproj")
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class JSON2CSVTest < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_load_strings_with_wrong_file
|
5
|
+
assert_raise(Errno::ENOENT) do
|
6
|
+
output = BabelishRnc::JSON2CSV.new.load_strings "file that does not exist.strings"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_load_strings
|
11
|
+
expected_output = {"app_name" => "json2csv", "action_greetings" => "hello", "ANOTHER_STRING" => "testEN", "empty" => ""}
|
12
|
+
output = BabelishRnc::JSON2CSV.new.load_strings "test/data/json.json"
|
13
|
+
assert_equal expected_output, output
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
csv_filename = "file.csv"
|
18
|
+
filenames = %w{"french.strings english.strings"}
|
19
|
+
headers = %w{"constants french english"}
|
20
|
+
converter = BabelishRnc::JSON2CSV.new({
|
21
|
+
:csv_filename => csv_filename,
|
22
|
+
:headers => headers,
|
23
|
+
:filenames => filenames })
|
24
|
+
|
25
|
+
assert_equal csv_filename, converter.csv_filename
|
26
|
+
assert_equal headers, converter.headers
|
27
|
+
assert_equal filenames, converter.filenames
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_initialize_with_default_values
|
31
|
+
converter = BabelishRnc::JSON2CSV.new
|
32
|
+
assert_not_nil converter.csv_filename
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestPhp2CSV < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_parse_dotstrings_line_with_good_string
|
5
|
+
input = String.new(<<-EOS)
|
6
|
+
$lang['MY_CONSTANT'] = "This is ok";
|
7
|
+
EOS
|
8
|
+
expected_output = {"MY_CONSTANT" => "This is ok"}
|
9
|
+
|
10
|
+
output = BabelishRnc::Php2CSV.new.parse_dotstrings_line input
|
11
|
+
assert_equal output, expected_output
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_parse_dotstrings_line_with_single_quote
|
15
|
+
input = String.new(<<-EOS)
|
16
|
+
$lang['MY_CONSTANT'] = "This 'is' ok";
|
17
|
+
EOS
|
18
|
+
expected_output = {"MY_CONSTANT" => "This 'is' ok"}
|
19
|
+
|
20
|
+
output = BabelishRnc::Php2CSV.new.parse_dotstrings_line input
|
21
|
+
assert_equal output, expected_output
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_parse_dotstrings_line_with_double_quotes
|
25
|
+
input = String.new(<<-EOS)
|
26
|
+
$lang['MY_CONSTANT'] = "This "is" ok";
|
27
|
+
EOS
|
28
|
+
expected_output = {"MY_CONSTANT" => "This \"is\" ok"}
|
29
|
+
|
30
|
+
output = BabelishRnc::Php2CSV.new.parse_dotstrings_line input
|
31
|
+
assert_equal output, expected_output
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_parse_dotstrings_line_with_wrong_string
|
35
|
+
input = String.new(<<-EOS)
|
36
|
+
$lang['MY_CONSTANT'] = "wrong syntax"
|
37
|
+
EOS
|
38
|
+
|
39
|
+
output = BabelishRnc::Php2CSV.new.parse_dotstrings_line input
|
40
|
+
assert_nil output, "output should be nil with wrong syntax"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_load_strings_with_wrong_file
|
44
|
+
assert_raise(Errno::ENOENT) do
|
45
|
+
output = BabelishRnc::Php2CSV.new.load_strings "file that does not exist.strings"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_load_strings
|
50
|
+
expected_output = {"app_name" => "php2csv", "action_greetings" => "Hello", "ANOTHER_STRING" => "testEN", "empty" => ""}
|
51
|
+
output = BabelishRnc::Php2CSV.new.load_strings "test/data/php_lang.php"
|
52
|
+
assert_equal expected_output, output
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_initialize
|
56
|
+
csv_filename = "file.csv"
|
57
|
+
filenames = %w{"french.php english.php"}
|
58
|
+
headers = %w{"constants french english"}
|
59
|
+
converter = BabelishRnc::Php2CSV.new({
|
60
|
+
:csv_filename => csv_filename,
|
61
|
+
:headers => headers,
|
62
|
+
:filenames => filenames })
|
63
|
+
|
64
|
+
assert_equal csv_filename, converter.csv_filename
|
65
|
+
assert_equal headers, converter.headers
|
66
|
+
assert_equal filenames, converter.filenames
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_initialize_with_default_values
|
70
|
+
converter = BabelishRnc::Php2CSV.new
|
71
|
+
assert_not_nil converter.csv_filename
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestStrings2CSV < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_parse_dotstrings_line_with_good_string
|
5
|
+
input = String.new(<<-EOS)
|
6
|
+
"MY_CONSTANT" = "This is ok";
|
7
|
+
EOS
|
8
|
+
expected_output = ["MY_CONSTANT","This is ok"]
|
9
|
+
|
10
|
+
output = BabelishRnc::Strings2CSV.new.parse_dotstrings_line input
|
11
|
+
assert_equal expected_output, output
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_parse_dotstrings_line_with_single_quote
|
15
|
+
input = String.new(<<-EOS)
|
16
|
+
"MY_CONSTANT" = "This 'is' ok";
|
17
|
+
EOS
|
18
|
+
expected_output = ["MY_CONSTANT","This 'is' ok"]
|
19
|
+
|
20
|
+
output = BabelishRnc::Strings2CSV.new.parse_dotstrings_line input
|
21
|
+
assert_equal expected_output, output
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_parse_dotstrings_line_with_double_quotes
|
25
|
+
input = String.new(<<-EOS)
|
26
|
+
"MY_CONSTANT" = "This "is" ok";
|
27
|
+
EOS
|
28
|
+
expected_output = ["MY_CONSTANT","This \"is\" ok"]
|
29
|
+
|
30
|
+
output = BabelishRnc::Strings2CSV.new.parse_dotstrings_line input
|
31
|
+
assert_equal expected_output, output
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_parse_dotstrings_line_with_wrong_string
|
35
|
+
input = String.new(<<-EOS)
|
36
|
+
"MY_CONSTANT" = "wrong syntax"
|
37
|
+
EOS
|
38
|
+
|
39
|
+
output = BabelishRnc::Strings2CSV.new.parse_dotstrings_line input
|
40
|
+
assert_nil output, "output should be nil with wrong syntax"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_parse_dotstrings_line_with_comment
|
44
|
+
input = String.new(<<-EOS)
|
45
|
+
/* Class = "IBUIButton"; normalTitle = "Wibble"; ObjectID = "xxx-xx-123"; */
|
46
|
+
EOS
|
47
|
+
|
48
|
+
output = BabelishRnc::Strings2CSV.new.parse_dotstrings_line input
|
49
|
+
assert_nil output, "output should be nil with comment"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_parse_comment
|
53
|
+
comment= "/* this is a comment */"
|
54
|
+
output = BabelishRnc::Strings2CSV.new.parse_comment_line comment
|
55
|
+
assert_equal "this is a comment", output
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_load_strings_with_wrong_file
|
59
|
+
assert_raise(Errno::ENOENT) do
|
60
|
+
output = BabelishRnc::Strings2CSV.new.load_strings "file that does not exist.strings"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_load_strings
|
65
|
+
expected_output = [{"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}, {}]
|
66
|
+
output = BabelishRnc::Strings2CSV.new.load_strings "test/data/test_data.strings"
|
67
|
+
assert_equal expected_output, output
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_load_strings_with_spaces
|
71
|
+
expected_output = [{ "name" => "definition",
|
72
|
+
"name1" => "definition1",
|
73
|
+
"name2" => "definition2",
|
74
|
+
"name3" => "definition3",
|
75
|
+
"name4" => "definition4",
|
76
|
+
"this is a name" => "a definition"
|
77
|
+
}, {}]
|
78
|
+
output = BabelishRnc::Strings2CSV.new.load_strings "test/data/test_space.strings"
|
79
|
+
assert_equal expected_output, output
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_load_strings_with_comments
|
83
|
+
expected_output = [{"MY_CONSTANT"=>"This 'is' ok"}, {"MY_CONSTANT"=> "this is a comment"}]
|
84
|
+
|
85
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/test_comments.strings"
|
86
|
+
assert_equal expected_output, output
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_load_strings_with_empty_lines
|
90
|
+
assert_nothing_raised do
|
91
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/test_with_nil.strings"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_load_strings_with_empty_lines_and_comments
|
96
|
+
assert_nothing_raised do
|
97
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/xcode_empty.strings"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_load_strings_with_genstrings_file
|
102
|
+
assert_nothing_raised do
|
103
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/genstrings.strings"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_dotstrings_to_csv
|
108
|
+
converter = Babelish::Strings2CSV.new(:filenames => ["test/data/test_data.strings"])
|
109
|
+
keys, strings = converter.convert(false)
|
110
|
+
assert_equal ["ERROR_HANDLER_WARNING_DISMISS", "ANOTHER_STRING"], keys
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_create_csv_file
|
115
|
+
keys = ["ERROR_HANDLER_WARNING_DISMISS", "ANOTHER_STRING"]
|
116
|
+
filename = "test_data"
|
117
|
+
strings = {filename => {"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}}
|
118
|
+
|
119
|
+
converter = Babelish::Strings2CSV.new(:headers => %w{variables english}, :filenames => [filename])
|
120
|
+
|
121
|
+
converter.send :create_csv_file, keys, strings
|
122
|
+
assert File.exist?(converter.csv_filename)
|
123
|
+
|
124
|
+
# clean up
|
125
|
+
system("rm -rf ./" + converter.csv_filename)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_initialize
|
129
|
+
csv_filename = "file.csv"
|
130
|
+
filenames = %w{french.strings english.strings}
|
131
|
+
headers = %w{constants french english}
|
132
|
+
converter = Babelish::Strings2CSV.new({
|
133
|
+
:csv_filename => csv_filename,
|
134
|
+
:headers => headers,
|
135
|
+
:filenames => filenames })
|
136
|
+
|
137
|
+
assert_equal csv_filename, converter.csv_filename
|
138
|
+
assert_equal headers, converter.headers
|
139
|
+
assert_equal filenames, converter.filenames
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_initialize_with_default_values
|
143
|
+
converter = Babelish::Strings2CSV.new
|
144
|
+
assert_not_nil converter.csv_filename
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|