babelish 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.babelish.sample +26 -0
- data/.gitignore +30 -0
- data/.hound.yml +4 -0
- data/.travis.yml +13 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.md +43 -0
- data/Rakefile +17 -0
- data/babelish.gemspec +41 -0
- data/bin/android2csv +13 -0
- data/bin/babelish +6 -0
- data/bin/csv2android +13 -0
- data/bin/csv2json +13 -0
- data/bin/csv2php +13 -0
- data/bin/csv2strings +14 -0
- data/bin/json2csv +13 -0
- data/bin/php2csv +13 -0
- data/bin/strings2csv +13 -0
- data/lib/babelish/android2csv.rb +25 -0
- data/lib/babelish/base2csv.rb +98 -0
- data/lib/babelish/commandline.rb +114 -0
- data/lib/babelish/csv2android.rb +36 -0
- data/lib/babelish/csv2base.rb +148 -0
- data/lib/babelish/csv2json.rb +22 -0
- data/lib/babelish/csv2php.rb +24 -0
- data/lib/babelish/csv2strings.rb +30 -0
- data/lib/babelish/google_doc.rb +36 -0
- data/lib/babelish/json2csv.rb +20 -0
- data/lib/babelish/language.rb +25 -0
- data/lib/babelish/php2csv.rb +30 -0
- data/lib/babelish/strings2csv.rb +47 -0
- data/lib/babelish/version.rb +3 -0
- data/lib/babelish.rb +27 -0
- data/test/babelish/commands/test_command_android2csv.rb +60 -0
- data/test/babelish/commands/test_command_csv2android.rb +35 -0
- data/test/babelish/commands/test_command_csv2strings.rb +60 -0
- data/test/babelish/commands/test_command_strings2csv.rb +95 -0
- data/test/babelish/test_android2csv.rb +35 -0
- data/test/babelish/test_base2csv.rb +43 -0
- data/test/babelish/test_bins.rb +24 -0
- data/test/babelish/test_csv2android.rb +26 -0
- data/test/babelish/test_csv2base.rb +40 -0
- data/test/babelish/test_csv2json.rb +26 -0
- data/test/babelish/test_csv2php.rb +26 -0
- data/test/babelish/test_csv2strings.rb +20 -0
- data/test/babelish/test_json2csv.rb +35 -0
- data/test/babelish/test_php2csv.rb +74 -0
- data/test/babelish/test_strings2csv.rb +114 -0
- data/test/data/android-en.xml +8 -0
- data/test/data/android-fr.xml +8 -0
- data/test/data/android.xml +8 -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_data.csv +3 -0
- data/test/data/test_data.strings +2 -0
- data/test/data/test_data_multiple_langs.csv +3 -0
- data/test/data/test_en.strings +2 -0
- data/test/data/test_fr.strings +2 -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 +248 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestAndroid2CSV < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_load_strings_with_wrong_file
|
5
|
+
assert_raise(Errno::ENOENT) do
|
6
|
+
output = Babelish::Android2CSV.new.load_strings "file that does not exist.strings"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_load_strings
|
11
|
+
expected_output = {"app_name" => "android2csv", "action_greetings" => "Hello", "ANOTHER_STRING" => "testEN", "empty" => ""}
|
12
|
+
output = Babelish::Android2CSV.new.load_strings "test/data/android.xml"
|
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 = Babelish::Android2CSV.new({
|
21
|
+
:csv_filename => csv_filename,
|
22
|
+
:headers => headers,
|
23
|
+
:filenames => filenames
|
24
|
+
})
|
25
|
+
|
26
|
+
assert_equal csv_filename, converter.csv_filename
|
27
|
+
assert_equal headers, converter.headers
|
28
|
+
assert_equal filenames, converter.filenames
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialize_with_default_values
|
32
|
+
converter = Babelish::Android2CSV.new
|
33
|
+
assert_not_nil converter.csv_filename
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestBase2Csv < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_load_strings
|
5
|
+
expected_output = {}
|
6
|
+
output = Babelish::Base2Csv.new.send :load_strings, nil
|
7
|
+
assert_equal expected_output, output
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create_csv_file
|
11
|
+
keys = ["ERROR_HANDLER_WARNING_DISMISS", "ANOTHER_STRING"]
|
12
|
+
filename = "test_data"
|
13
|
+
strings = {filename => {"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}}
|
14
|
+
|
15
|
+
converter = Babelish::Base2Csv.new(:headers => %w{variables english}, :filenames => [filename])
|
16
|
+
|
17
|
+
converter.send :create_csv_file, keys, strings
|
18
|
+
assert File.exist?(converter.csv_filename)
|
19
|
+
|
20
|
+
#clean up
|
21
|
+
system("rm -rf ./" + converter.csv_filename)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_initialize
|
25
|
+
csv_filename = "file.csv"
|
26
|
+
filenames = %w{"french.strings english.strings"}
|
27
|
+
headers = %w{"constants french english"}
|
28
|
+
converter = Babelish::Base2Csv.new({
|
29
|
+
:csv_filename => csv_filename,
|
30
|
+
:headers => headers,
|
31
|
+
:filenames => filenames
|
32
|
+
})
|
33
|
+
|
34
|
+
assert_equal csv_filename, converter.csv_filename
|
35
|
+
assert_equal headers, converter.headers
|
36
|
+
assert_equal filenames, converter.filenames
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_initialize_with_default_values
|
40
|
+
converter = Babelish::Base2Csv.new
|
41
|
+
assert_not_nil converter.csv_filename
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestBins < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_csv2strings_with_google_doc
|
5
|
+
omit if ENV['TRAVIS']
|
6
|
+
assert_nothing_raised do
|
7
|
+
system("./bin/csv2strings --fetch --filename test.csv")
|
8
|
+
end
|
9
|
+
assert_equal $?.exitstatus, 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_csv2strings_with_config_file
|
13
|
+
system("cp .babelish.sample .babelish")
|
14
|
+
|
15
|
+
assert_nothing_raised NameError do
|
16
|
+
system("./bin/csv2strings")
|
17
|
+
end
|
18
|
+
assert_equal $?.exitstatus, 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
system("rm -f .babelish")
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
class TestCSV2Android < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_converting_csv_to_xml
|
5
|
+
csv_file = "test/data/test_data.csv"
|
6
|
+
converter = Babelish::CSV2Android.new(csv_file, 'English' => "en")
|
7
|
+
converter.convert
|
8
|
+
assert File.exists?("values-en/strings.xml"), "the ouptut file does not exist"
|
9
|
+
|
10
|
+
#clean up
|
11
|
+
system("rm -rf ./values-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.xml'
|
17
|
+
converter = Babelish::CSV2Android.new(csv_file,
|
18
|
+
{'English' => "en"},
|
19
|
+
:output_file => single_file)
|
20
|
+
converter.convert
|
21
|
+
assert File.exists?(single_file), "the ouptut file does not exist"
|
22
|
+
|
23
|
+
#clean up
|
24
|
+
system("rm -rf ./" + single_file)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class TestCsv2Base < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_initialize
|
5
|
+
csv_filename = "file.csv"
|
6
|
+
excluded_states = ["German"]
|
7
|
+
state_column = "Local"
|
8
|
+
keys_column = 23
|
9
|
+
converter = Babelish::Csv2Base.new(csv_filename, {"English" => ["en"]}, {
|
10
|
+
:excluded_states => excluded_states,
|
11
|
+
:state_column => state_column,
|
12
|
+
:keys_column => keys_column
|
13
|
+
})
|
14
|
+
|
15
|
+
assert_equal csv_filename, converter.csv_filename
|
16
|
+
assert_equal excluded_states, converter.excluded_states
|
17
|
+
assert_equal state_column, converter.state_column
|
18
|
+
assert_equal keys_column, converter.keys_column
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initialize_with_default_values
|
22
|
+
converter = Babelish::Csv2Base.new("file.csv", {"English" => ["en"]})
|
23
|
+
assert_not_nil converter.csv_filename
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_create_file_from_path
|
27
|
+
test_file = "test_file.txt"
|
28
|
+
Babelish::Csv2Base.new("file.csv", {"English" => ["en"]}).create_file_from_path test_file
|
29
|
+
assert File.exist?(test_file)
|
30
|
+
|
31
|
+
#clean up
|
32
|
+
system("rm -rf ./" + test_file)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_get_row_format
|
36
|
+
expected_output = "\"test_key\" = \"test_value\""
|
37
|
+
output = Babelish::Csv2Base.new("file.csv", {"English" => ["en"]}).get_row_format("test_key", "test_value")
|
38
|
+
assert_equal expected_output, output
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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 = Babelish::CSV2JSON.new(csv_file, 'English' => "en")
|
7
|
+
converter.convert
|
8
|
+
assert File.exists?("en.js"), "the ouptut file does not exist"
|
9
|
+
|
10
|
+
#clean up
|
11
|
+
system("rm -rf en.js")
|
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 = Babelish::CSV2JSON.new(csv_file,
|
18
|
+
{'English' => "en"},
|
19
|
+
:output_file => single_file)
|
20
|
+
converter.convert
|
21
|
+
assert File.exists?(single_file), "the ouptut file does not exist"
|
22
|
+
|
23
|
+
#clean up
|
24
|
+
system("rm -rf ./" + single_file)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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 = Babelish::CSV2Php.new(csv_file, 'English' => "en")
|
7
|
+
converter.convert
|
8
|
+
assert File.exists?("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 = Babelish::CSV2Php.new(csv_file,
|
18
|
+
{'English' => "en"},
|
19
|
+
:output_file => single_file)
|
20
|
+
converter.convert
|
21
|
+
assert File.exists?(single_file), "the ouptut file does not exist"
|
22
|
+
|
23
|
+
#clean up
|
24
|
+
system("rm -rf ./" + single_file)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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 = Babelish::CSV2Strings.new(csv_file, 'English' => [:en])
|
7
|
+
converter.convert
|
8
|
+
assert File.exists?("en.lproj/Localizable.strings"), "the ouptut file does not exist"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_converting_csv_to_dotstrings_one_output_option
|
12
|
+
csv_file = "test/data/test_data.csv"
|
13
|
+
single_file = 'myApp.strings'
|
14
|
+
converter = Babelish::CSV2Strings.new(csv_file,
|
15
|
+
{'English' => [:en]},
|
16
|
+
:output_file => single_file)
|
17
|
+
converter.convert
|
18
|
+
assert File.exists?(single_file), "the ouptut file does not exist"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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 = Babelish::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 = Babelish::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 = Babelish::JSON2CSV.new({
|
21
|
+
:csv_filename => csv_filename,
|
22
|
+
:headers => headers,
|
23
|
+
:filenames => filenames
|
24
|
+
})
|
25
|
+
|
26
|
+
assert_equal csv_filename, converter.csv_filename
|
27
|
+
assert_equal headers, converter.headers
|
28
|
+
assert_equal filenames, converter.filenames
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialize_with_default_values
|
32
|
+
converter = Babelish::JSON2CSV.new
|
33
|
+
assert_not_nil converter.csv_filename
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,74 @@
|
|
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 = Babelish::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 = Babelish::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 = Babelish::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 = Babelish::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 = Babelish::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 = Babelish::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 = Babelish::Php2CSV.new({
|
60
|
+
:csv_filename => csv_filename,
|
61
|
+
:headers => headers,
|
62
|
+
:filenames => filenames
|
63
|
+
})
|
64
|
+
|
65
|
+
assert_equal csv_filename, converter.csv_filename
|
66
|
+
assert_equal headers, converter.headers
|
67
|
+
assert_equal filenames, converter.filenames
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_initialize_with_default_values
|
71
|
+
converter = Babelish::Php2CSV.new
|
72
|
+
assert_not_nil converter.csv_filename
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,114 @@
|
|
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 = Babelish::Strings2CSV.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
|
+
"MY_CONSTANT" = "This 'is' ok";
|
17
|
+
EOS
|
18
|
+
expected_output = {"MY_CONSTANT"=>"This 'is' ok"}
|
19
|
+
|
20
|
+
output = Babelish::Strings2CSV.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
|
+
"MY_CONSTANT" = "This "is" ok";
|
27
|
+
EOS
|
28
|
+
expected_output = {"MY_CONSTANT"=>"This \"is\" ok"}
|
29
|
+
|
30
|
+
output = Babelish::Strings2CSV.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
|
+
"MY_CONSTANT" = "wrong syntax"
|
37
|
+
EOS
|
38
|
+
|
39
|
+
output = Babelish::Strings2CSV.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 = Babelish::Strings2CSV.new.load_strings "file that does not exist.strings"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_load_strings
|
50
|
+
expected_output = {"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}
|
51
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/test_data.strings"
|
52
|
+
assert_equal expected_output, output
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_load_strings_with_empty_lines
|
56
|
+
assert_nothing_raised do
|
57
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/test_with_nil.strings"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_load_strings_with_empty_lines_and_comments
|
62
|
+
assert_nothing_raised do
|
63
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/xcode_empty.strings"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_load_strings_with_genstrings_file
|
68
|
+
assert_nothing_raised do
|
69
|
+
output = Babelish::Strings2CSV.new.load_strings "test/data/genstrings.strings"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_dotstrings_to_csv
|
74
|
+
converter = Babelish::Strings2CSV.new(:filenames => ["test/data/test_data.strings"])
|
75
|
+
keys, strings = converter.convert(false)
|
76
|
+
assert_equal ["ERROR_HANDLER_WARNING_DISMISS", "ANOTHER_STRING"], keys
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_create_csv_file
|
81
|
+
keys = ["ERROR_HANDLER_WARNING_DISMISS", "ANOTHER_STRING"]
|
82
|
+
filename = "test_data"
|
83
|
+
strings = {filename => {"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}}
|
84
|
+
|
85
|
+
converter = Babelish::Strings2CSV.new(:headers => %w{variables english}, :filenames => [filename])
|
86
|
+
|
87
|
+
converter.send :create_csv_file, keys, strings
|
88
|
+
assert File.exist?(converter.csv_filename)
|
89
|
+
|
90
|
+
#clean up
|
91
|
+
system("rm -rf ./" + converter.csv_filename)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_initialize
|
95
|
+
csv_filename = "file.csv"
|
96
|
+
filenames = %w{"french.strings english.strings"}
|
97
|
+
headers = %w{"constants french english"}
|
98
|
+
converter = Babelish::Strings2CSV.new({
|
99
|
+
:csv_filename => csv_filename,
|
100
|
+
:headers => headers,
|
101
|
+
:filenames => filenames
|
102
|
+
})
|
103
|
+
|
104
|
+
assert_equal csv_filename, converter.csv_filename
|
105
|
+
assert_equal headers, converter.headers
|
106
|
+
assert_equal filenames, converter.filenames
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_initialize_with_default_values
|
110
|
+
converter = Babelish::Strings2CSV.new
|
111
|
+
assert_not_nil converter.csv_filename
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
Binary file
|
data/test/data/json.json
ADDED
Binary file
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter '/test/'
|
8
|
+
end
|
9
|
+
rescue LoadError
|
10
|
+
puts 'Coverage disabled, enable by installing simplecov'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'test/unit'
|
14
|
+
|
15
|
+
require 'babelish'
|
16
|
+
|
17
|
+
require "babelish/commandline"
|