Add unit tests.

This commit is contained in:
Sebastian Celis 2012-02-10 18:53:38 -06:00
parent 2daebb750e
commit 1152447929
10 changed files with 141 additions and 0 deletions

8
Rakefile Normal file
View file

@ -0,0 +1,8 @@
require 'rake'
require 'rake/testtask'
Rake::TestTask.new do |t|
t.test_files = %w(test/twine_test.rb)
end
task :default => :test

10
test/fixtures/en-1.strings vendored Normal file
View file

@ -0,0 +1,10 @@
/**
* iOS Strings File
* Generated by Twine
* Language: en
*/
/* My Strings */
"key1" = "key1-english";
"key3" = "key3-english";
"key5" = "A new string";

9
test/fixtures/fr-1.xml vendored Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Android Strings File -->
<!-- Generated by Twine -->
<!-- Language: fr -->
<resources>
<string name="key1">key1-french</string>
<string name="key2">key2-french</string>
<string name="key3">key3-french</string>
</resources>

16
test/fixtures/strings-1.txt vendored Normal file
View file

@ -0,0 +1,16 @@
[[My Strings]]
[key1]
en = key1-english
tags = tag1
es = key1-spanish
fr = key1-french
[key2]
en = key2-english
tags = tag2
fr = key2-french
[key3]
en = key3-english
tags = tag1,tag2
es = key3-spanish
[key4]
en = key4-english

10
test/fixtures/test-output-1.txt vendored Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Android Strings File -->
<!-- Generated by Twine -->
<!-- Language: fr -->
<resources>
<!-- My Strings -->
<string name="key1">key1-french</string>
<string name="key2">key2-french</string>
<string name="key3">key3-english</string>
</resources>

9
test/fixtures/test-output-2.txt vendored Normal file
View file

@ -0,0 +1,9 @@
/**
* iOS Strings File
* Generated by Twine
* Language: en
*/
/* My Strings */
"key1" = "key1-english";
"key3" = "key3-english";

17
test/fixtures/test-output-3.txt vendored Normal file
View file

@ -0,0 +1,17 @@
[[My Strings]]
[key1]
en = key1-english
tags = tag1
es = key1-spanish
fr = key1-french
[key2]
en = key2-english
tags = tag2
fr = key2-french
[key3]
en = key3-english
tags = tag1,tag2
es = key3-spanish
fr = key3-french
[key4]
en = key4-english

20
test/fixtures/test-output-4.txt vendored Normal file
View file

@ -0,0 +1,20 @@
[[Uncategorized]]
[key5]
en = A new string
[[My Strings]]
[key1]
en = key1-english
tags = tag1
es = key1-spanish
fr = key1-french
[key2]
en = key2-english
tags = tag2
fr = key2-french
[key3]
en = key3-english
tags = tag1,tag2
es = key3-spanish
[key4]
en = key4-english

40
test/twine_test.rb Normal file
View file

@ -0,0 +1,40 @@
require 'test/unit'
require 'twine'
class TwineTest < Test::Unit::TestCase
def test_generate_string_file_1
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'fr.xml')
Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path}))
assert_equal(File.read('test/fixtures/test-output-1.txt'), File.read(output_path))
end
end
def test_generate_string_file_2
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'en.strings')
Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} -t tag1))
assert_equal(File.read('test/fixtures/test-output-2.txt'), File.read(output_path))
end
end
def test_consume_string_file_1
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'strings.txt')
Twine::Runner.run(%W(consume-string-file test/fixtures/strings-1.txt test/fixtures/fr-1.xml -o #{output_path} -l fr))
assert_equal(File.read('test/fixtures/test-output-3.txt'), File.read(output_path))
end
end
def test_consume_string_file_2
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'strings.txt')
Twine::Runner.run(%W(consume-string-file test/fixtures/strings-1.txt test/fixtures/en-1.strings -o #{output_path} -l en -a))
assert_equal(File.read('test/fixtures/test-output-4.txt'), File.read(output_path))
end
end
def test_generate_report_1
Twine::Runner.run(%w(generate-report test/fixtures/strings-1.txt))
end
end

View file

@ -15,7 +15,9 @@ Gem::Specification.new do |s|
s.files += Dir.glob("lib/**/*")
s.files += Dir.glob("bin/**/*")
s.required_ruby_version = ">= 1.8.7"
s.add_runtime_dependency('rubyzip', "~> 0.9.5")
s.add_development_dependency('rake', "~> 0.9.2")
s.executables = %w( twine )
s.description = <<desc