From fc9cb0f6e0df98c02e126bb482ccf57c9adc11b6 Mon Sep 17 00:00:00 2001 From: Alexandre Podlewski Date: Thu, 17 Aug 2023 12:09:38 +0200 Subject: [PATCH] Add test for --auto-escape-percent option --- .../ios/en.lproj/Localizable.strings | 2 ++ .../ios/en.lproj/Localizable.stringsdict | 27 +++++++++++++++++++ .../ios/fr.lproj/Localizable.strings | 2 ++ .../ios/fr.lproj/Localizable.stringsdict | 27 +++++++++++++++++++ .../reference_auto_escape_percent.csv | 8 ++++++ .../process_export_request_test.rb | 23 ++++++++++++++++ 6 files changed, 89 insertions(+) create mode 100644 test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.strings create mode 100644 test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.stringsdict create mode 100644 test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.strings create mode 100644 test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.stringsdict create mode 100644 test/fixtures/reference_auto_escape_percent.csv diff --git a/test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.strings b/test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.strings new file mode 100644 index 0000000..b1379c9 --- /dev/null +++ b/test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"key1" = "%1$@%% discount"; +"key2" = "%d %@ %2$@"; diff --git a/test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.stringsdict b/test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.stringsdict new file mode 100644 index 0000000..c2a892d --- /dev/null +++ b/test/fixtures/exports_auto_escape_percent/ios/en.lproj/Localizable.stringsdict @@ -0,0 +1,27 @@ + + + + plural_key + + NSStringLocalizedFormatKey + %#@key@ + key + + NSStringFormatSpecTypeKey + NSStringPluralRuleType + NSStringFormatValueTypeKey + d + other + %d %@ %2$@ + + + adaptive_key + + NSStringVariableWidthRuleType + + 20 + %d %@ %2$@ + + + + diff --git a/test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.strings b/test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.strings new file mode 100644 index 0000000..ab55b8e --- /dev/null +++ b/test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.strings @@ -0,0 +1,2 @@ +"key1" = "Réduction de %1$@%%"; +"key2" = "%d %@ %2$@"; diff --git a/test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.stringsdict b/test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.stringsdict new file mode 100644 index 0000000..c2a892d --- /dev/null +++ b/test/fixtures/exports_auto_escape_percent/ios/fr.lproj/Localizable.stringsdict @@ -0,0 +1,27 @@ + + + + plural_key + + NSStringLocalizedFormatKey + %#@key@ + key + + NSStringFormatSpecTypeKey + NSStringPluralRuleType + NSStringFormatValueTypeKey + d + other + %d %@ %2$@ + + + adaptive_key + + NSStringVariableWidthRuleType + + 20 + %d %@ %2$@ + + + + diff --git a/test/fixtures/reference_auto_escape_percent.csv b/test/fixtures/reference_auto_escape_percent.csv new file mode 100644 index 0000000..65b714f --- /dev/null +++ b/test/fixtures/reference_auto_escape_percent.csv @@ -0,0 +1,8 @@ +,key,fr,comment fr,en,comment en +#Generic actions,,,,, +,key1,Réduction de %1$@%,,%1$@% discount, +,key2,%d %@ %2$@,,%d %@ %2$@, +#Plurals,,,,, +,plural_key##{other},%d %@ %2$@,,%d %@ %2$@, +#Adaptive,,,,, +,adaptive_key##{20},%d %@ %2$@,,%d %@ %2$@, diff --git a/test/interactors/process_export_request_test.rb b/test/interactors/process_export_request_test.rb index 05fc7f2..e4835bf 100644 --- a/test/interactors/process_export_request_test.rb +++ b/test/interactors/process_export_request_test.rb @@ -171,6 +171,29 @@ def teardown assert_empty(diff.to_s, "File #{generated_file} do not match reference. Diff: \n\n#{diff}\n") end end + + test 'it should escape percent characters' do + # Given + csv_files = %w[test/fixtures/reference_auto_escape_percent.csv] + csv_files.each { |file| assert(File.exist?(file), "File does not exists #{file}") } + reference_dir = "test/fixtures/exports_auto_escape_percent" + assert(File.exist?(reference_dir), "File does not exists #{reference_dir}") + + # When + export_request = Requests::ExportRequest.new + export_request.csv_paths = csv_files + export_request.auto_escape_percent = true + ProcessExportRequest.new.call(export_request: export_request) + + # Then + ios_files(files: ["Localizable.strings", "Localizable.stringsdict"]).each do |file| + reference_file = "#{reference_dir}/#{file}" + generated_file = "exports/#{file}" + assert(File.exist?(generated_file), "File does not exists #{generated_file}") + diff = Diffy::Diff.new(reference_file, generated_file, :source => 'files') + assert_empty(diff.to_s, "File #{generated_file} do not match reference. Diff: \n\n#{diff}\n") + end + end end end end