From 3a56f08778e93071b537aee2896fe2b7e0d921a9 Mon Sep 17 00:00:00 2001 From: Alexandre Podlewski Date: Wed, 18 Oct 2023 17:17:05 +0200 Subject: [PATCH] Create test for checking csv parser stripping --- .../reference_whitespace_stripping.csv | 5 ++ test/parsers/csv_parser_test.rb | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/fixtures/reference_whitespace_stripping.csv diff --git a/test/fixtures/reference_whitespace_stripping.csv b/test/fixtures/reference_whitespace_stripping.csv new file mode 100644 index 0000000..53d0b78 --- /dev/null +++ b/test/fixtures/reference_whitespace_stripping.csv @@ -0,0 +1,5 @@ +,key,en, +,no_whitespaces,no_whitespaces, +, before, before, +,after ,after , +, both , both , diff --git a/test/parsers/csv_parser_test.rb b/test/parsers/csv_parser_test.rb index c360e40..864591c 100644 --- a/test/parsers/csv_parser_test.rb +++ b/test/parsers/csv_parser_test.rb @@ -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