Do not strip whitespace from sections and string keys.

Fixes Issue #14
This commit is contained in:
Sebastian Celis 2012-07-18 09:28:01 -05:00
parent c0b49745fe
commit 4958a0bff0
4 changed files with 25 additions and 2 deletions

View file

@ -88,14 +88,14 @@ module Twine
if line.length > 4 && line[0, 2] == '[['
match = /^\[\[(.+)\]\]$/.match(line)
if match
current_section = StringsSection.new(match[1].strip)
current_section = StringsSection.new(match[1])
@sections << current_section
parsed = true
end
elsif line.length > 2 && line[0, 1] == '['
match = /^\[(.+)\]$/.match(line)
if match
current_row = StringsRow.new(match[1].strip)
current_row = StringsRow.new(match[1])
@strings_map[current_row.key] = current_row
if !current_section
current_section = StringsSection.new('')

5
test/fixtures/strings-2.txt vendored Normal file
View file

@ -0,0 +1,5 @@
[[My Strings]]
[key with space ]
en = `string with space `
tags = tag1
comment = String ends with space

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

@ -0,0 +1,10 @@
/**
* Apple Strings File
* Generated by Twine <%= Twine::VERSION %>
* Language: en
*/
/********** My Strings **********/
/* String ends with space */
"key with space " = "string with space ";

View file

@ -28,6 +28,14 @@ class TwineTest < Test::Unit::TestCase
end
end
def test_generate_string_file_4
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'en.strings')
Twine::Runner.run(%W(generate-string-file test/fixtures/strings-2.txt #{output_path} -t tag1))
assert_equal(ERB.new(File.read('test/fixtures/test-output-6.txt')).result, File.read(output_path))
end
end
def test_consume_string_file_1
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'strings.txt')