Skip to content

Commit

Permalink
Create test for checking csv parser stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-pod committed Oct 18, 2023
1 parent 89be12a commit 3a56f08
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/reference_whitespace_stripping.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
,key,en,
,no_whitespaces,no_whitespaces,
, before, before,
,after ,after ,
, both , both ,
48 changes: 48 additions & 0 deletions test/parsers/csv_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,54 @@
module AdLocalize
module Parsers
class CSVParserTest < TestCase
test 'should trim whitespace on keys and translations' do
# Given
csv_path = "test/fixtures/reference_whitespace_stripping.csv"
assert(File.exist?(csv_path), "File does not exists #{csv_path}")
parser = Parsers::CSVParser.new
export_request = Requests::ExportRequest.new

# When
wording = parser.call(csv_path: csv_path, export_request: export_request)

# Then
en_singular_wording = wording["en"].singulars

assert_equal en_singular_wording["no_whitespaces"].key.label, "no_whitespaces"
assert_equal en_singular_wording["before"].key.label, "before"
assert_equal en_singular_wording["after"].key.label, "after"
assert_equal en_singular_wording["both"].key.label, "both"

assert_equal en_singular_wording["no_whitespaces"].value, "no_whitespaces"
assert_equal en_singular_wording["before"].value, "before"
assert_equal en_singular_wording["after"].value, "after"
assert_equal en_singular_wording["both"].value, "both"
end

test 'should not trim whitespace on translation when strip is disabled' do
# Given
csv_path = "test/fixtures/reference_whitespace_stripping.csv"
assert(File.exist?(csv_path), "File does not exists #{csv_path}")
parser = Parsers::CSVParser.new
export_request = Requests::ExportRequest.new
export_request.skip_value_stripping = true

# When
wording = parser.call(csv_path: csv_path, export_request: export_request)

# Then
en_singular_wording = wording["en"].singulars

assert_equal en_singular_wording["no_whitespaces"].key.label, "no_whitespaces"
assert_equal en_singular_wording["before"].key.label, "before"
assert_equal en_singular_wording["after"].key.label, "after"
assert_equal en_singular_wording["both"].key.label, "both"

assert_equal en_singular_wording["no_whitespaces"].value, "no_whitespaces"
assert_equal en_singular_wording["before"].value, " before"
assert_equal en_singular_wording["after"].value, "after "
assert_equal en_singular_wording["both"].value, " both "
end
end
end
end

0 comments on commit 3a56f08

Please sign in to comment.