require 'spec_helper' describe Aigu::IOSImporter do describe :format_strings_file do let(:importer) { Aigu::IOSImporter.new } let(:format_strings_file) { importer.send(:format_strings_file, content) } let(:content) do { 'STRING_1' => 'Value of string #1', 'STRING_2' => 'Value of string #2', 'STRING_3' => 'Value with special chars (%ld) %s\n " = " abc', 'STRING_4' => 'Value with an interpolation %s.', 'STRING_5' => 'Value with %s interpolations %s.', 'STRING_6' => 'Value with an interpolation with an identifier %1$s.', 'STRING_7' => 'Value with %1$s interpolations with an identifier %2$s.' } end let(:expected_content) do <<-EOS.unindent "STRING_1" = "Value of string #1"; "STRING_2" = "Value of string #2"; "STRING_3" = "Value with special chars (%ld) %@\\n " = " abc"; "STRING_4" = "Value with an interpolation %@."; "STRING_5" = "Value with %@ interpolations %@."; "STRING_6" = "Value with an interpolation with an identifier %1$@."; "STRING_7" = "Value with %1$@ interpolations with an identifier %2$@."; EOS end it { expect(format_strings_file).to eql expected_content } end describe :update_stringsdict_content do let(:exporter) { Aigu::IOSImporter.new } let(:update_stringsdict_content) { exporter.send(:update_stringsdict_content, file_content, new_hash) } let(:file_content) do <<-EOS.unindent BUNDLE_1 NSStringLocalizedFormatKey %1$\#@string1@ string1 NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey d zero %d value #1 zero one %d value #1 one other %d value #1 other string2 NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey d zero %d value #2 & zero one %d value #2 one other %d value #2 other BUNDLE_2 NSStringLocalizedFormatKey %1$\#@string1@ string1 NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey d zero %d value #1 zero one %d value #1 one other %d value #1 other EOS end let(:new_hash) do { '__@DICT__BUNDLE_1__@STRING__string1__@ZERO' => '%d value #1 zero new', '__@DICT__BUNDLE_1__@STRING__string1__@ONE' => '%d value #1 one new', '__@DICT__BUNDLE_1__@STRING__string1__@OTHER' => '%d value #1 other new', '__@DICT__BUNDLE_1__@STRING__string2__@ZERO' => '%d value #2 & zero new', '__@DICT__BUNDLE_1__@STRING__string2__@ONE' => '%d value #2 one new', '__@DICT__BUNDLE_1__@STRING__string2__@OTHER' => '%d value #2 other new', '__@DICT__BUNDLE_2__@STRING__string1__@ZERO' => '%d value #1 zero new', '__@DICT__BUNDLE_2__@STRING__string1__@ONE' => '%d value #1 one new', '__@DICT__BUNDLE_2__@STRING__string1__@OTHER' => '%d value #1 other new' } end let(:expected_content) do <<-EOS.unindent BUNDLE_1 NSStringLocalizedFormatKey %1$\#@string1@ string1 NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey d zero %d value #1 zero new one %d value #1 one new other %d value #1 other new string2 NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey d zero %d value #2 & zero new one %d value #2 one new other %d value #2 other new BUNDLE_2 NSStringLocalizedFormatKey %1$\#@string1@ string1 NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey d zero %d value #1 zero new one %d value #1 one new other %d value #1 other new EOS end it { expect(update_stringsdict_content).to eql expected_content } end end