From 0481660eb7e4d73a43372b20560de2f45b0c0186 Mon Sep 17 00:00:00 2001 From: Florian Hanke Date: Thu, 17 May 2012 19:32:47 +1000 Subject: [PATCH] + closes #39, + US formatted using format :national does not prefix a 0 anymore --- spec/lib/phony/country_codes_spec.rb | 6 +++--- spec/lib/phony/country_spec.rb | 8 ++++---- spec/lib/phony/dsl_spec.rb | 2 +- spec/lib/phony/national_code_spec.rb | 10 +++++----- spec/lib/phony/national_splitters/fixed_spec.rb | 12 ++++++------ spec/lib/phony/national_splitters/none_spec.rb | 2 +- spec/lib/phony/national_splitters/regex_spec.rb | 2 +- spec/lib/phony/national_splitters/variable_spec.rb | 10 +++++----- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/spec/lib/phony/country_codes_spec.rb b/spec/lib/phony/country_codes_spec.rb index 960716a2..224c91b3 100644 --- a/spec/lib/phony/country_codes_spec.rb +++ b/spec/lib/phony/country_codes_spec.rb @@ -12,7 +12,7 @@ end it 'formats correctly' do old_format = @countries.international_absolute_format - @countries.international_absolute_format = '!!! %s%s%s%s' + @countries.international_absolute_format = '!!! %s%s%s' @countries.formatted('41443643532', :format => :international).should == '!!! 41 44 364 35 32' @@ -25,7 +25,7 @@ end it 'formats correctly' do old_format = @countries.international_relative_format - @countries.international_relative_format = '000 %s%s%s%s' + @countries.international_relative_format = '000 %s%s%s' @countries.formatted('41443643532', :format => :international_relative).should == '000 41 44 364 35 32' @@ -48,7 +48,7 @@ describe 'split' do it 'splits correctly' do - @countries.split('41443643532').should == ['41', '44', '364', '35', '32'] + @countries.split('41443643532').should == ['41', '0', '44', '364', '35', '32'] end end diff --git a/spec/lib/phony/country_spec.rb b/spec/lib/phony/country_spec.rb index 611c1f5e..782ecb6a 100644 --- a/spec/lib/phony/country_spec.rb +++ b/spec/lib/phony/country_spec.rb @@ -12,7 +12,7 @@ @iceland = described_class.new national_code end it 'splits correctly' do - @iceland.split('112').should == ['112'] + @iceland.split('112').should == [nil, nil, '112'] end end end @@ -28,7 +28,7 @@ describe "split" do it "should handle ZH" do - @switzerland.split('443643532').should == ['44', '364', '35', '32'] + @switzerland.split('443643532').should == ['0', '44', '364', '35', '32'] end end describe 'normalize' do @@ -53,10 +53,10 @@ describe "split" do it "should handle ZH" do - @switzerland.split('443643532').should == ['44', '364', '35', '32'] + @switzerland.split('443643532').should == ['0', '44', '364', '35', '32'] end it "should handle 800" do - @switzerland.split('800333666').should == ['800', '333', '666'] + @switzerland.split('800333666').should == ['0', '800', '333', '666'] end end end diff --git a/spec/lib/phony/dsl_spec.rb b/spec/lib/phony/dsl_spec.rb index 12ae49f1..95eea30e 100644 --- a/spec/lib/phony/dsl_spec.rb +++ b/spec/lib/phony/dsl_spec.rb @@ -6,7 +6,7 @@ it 'has a todo' do Phony.define do - todo.split("123456789012345").should == ["123456789012345"] + todo.split("123456789012345").should == [nil, nil, nil, nil, '123456789012345'] end end diff --git a/spec/lib/phony/national_code_spec.rb b/spec/lib/phony/national_code_spec.rb index fa47ddfa..87300e4f 100644 --- a/spec/lib/phony/national_code_spec.rb +++ b/spec/lib/phony/national_code_spec.rb @@ -12,7 +12,7 @@ @national = Phony::NationalCode.new national_splitter, local_splitter end it 'splits correctly' do - @national.split('112').should == [nil, '112'] + @national.split('112').should == [nil, nil, '112'] end end end @@ -24,10 +24,10 @@ @national = Phony::NationalCode.new national_splitter, local_splitter end it 'splits correctly' do - @national.split('443643532').should == ['44', '364', '35', '32'] + @national.split('443643532').should == ['0', '44', '364', '35', '32'] end it 'splits correctly' do - @national.split('44364353').should == ['44', '364', '35', '3'] + @national.split('44364353').should == ['0', '44', '364', '35', '3'] end it 'normalizes correctly' do @national.normalize('044364353').should == '44364353' @@ -44,10 +44,10 @@ @national = Phony::NationalCode.new national_splitter, local_splitter end it 'splits correctly' do - @national.split('142278186').should == ['1', '42', '27', '81', '86'] + @national.split('142278186').should == ['0', '1', '42', '27', '81', '86'] end it 'splits correctly' do - @national.split('14227818').should == ['1', '42', '27', '81', '8'] + @national.split('14227818').should == ['0', '1', '42', '27', '81', '8'] end it 'normalizes correctly' do @national.normalize('0142278186').should == '142278186' diff --git a/spec/lib/phony/national_splitters/fixed_spec.rb b/spec/lib/phony/national_splitters/fixed_spec.rb index 1b8beae4..b3f5d3d6 100644 --- a/spec/lib/phony/national_splitters/fixed_spec.rb +++ b/spec/lib/phony/national_splitters/fixed_spec.rb @@ -16,13 +16,13 @@ @splitter = Phony::NationalSplitters::Fixed.new 2 end it 'splits correctly' do - @splitter.split('443643532').should == ['44', '3643532'] + @splitter.split('443643532').should == ['0', '44', '3643532'] end it 'splits correctly even when the number is too long' do - @splitter.split('44364353211').should == ['44', '364353211'] + @splitter.split('44364353211').should == ['0', '44', '364353211'] end it 'splits correctly even when the number is too short' do - @splitter.split('443').should == ['44','3'] + @splitter.split('443').should == ['0', '44','3'] end end describe 'split' do @@ -30,13 +30,13 @@ @splitter = Phony::NationalSplitters::Fixed.new nil end it 'splits correctly' do - @splitter.split('443643532').should == ['443643532'] + @splitter.split('443643532').should == ['0', '443643532'] end it 'splits correctly even when the number is too long' do - @splitter.split('44364353211').should == ['44364353211'] + @splitter.split('44364353211').should == ['0', '44364353211'] end it 'splits correctly even when the number is too short' do - @splitter.split('443').should == ['443'] + @splitter.split('443').should == ['0', '443'] end end diff --git a/spec/lib/phony/national_splitters/none_spec.rb b/spec/lib/phony/national_splitters/none_spec.rb index 2d4ed539..51942530 100644 --- a/spec/lib/phony/national_splitters/none_spec.rb +++ b/spec/lib/phony/national_splitters/none_spec.rb @@ -11,7 +11,7 @@ describe 'split' do let(:splitter) { described_class.instance_for } it 'splits correctly into ndc and rest' do - splitter.split('123456789').should == [nil, '123456789'] + splitter.split('123456789').should == [nil, nil, '123456789'] end end diff --git a/spec/lib/phony/national_splitters/regex_spec.rb b/spec/lib/phony/national_splitters/regex_spec.rb index d137de06..5fa0ebc5 100644 --- a/spec/lib/phony/national_splitters/regex_spec.rb +++ b/spec/lib/phony/national_splitters/regex_spec.rb @@ -15,7 +15,7 @@ context 'with on_fail 2' do let(:splitter) { described_class.instance_for(/^(123)\d+$/, 2) } it 'uses the on_fail_take' do - splitter.split('23456789').should == ['23', '456789'] + splitter.split('23456789').should == ['0', '23', '456789'] end end end diff --git a/spec/lib/phony/national_splitters/variable_spec.rb b/spec/lib/phony/national_splitters/variable_spec.rb index 5ae4d582..df84a3d2 100644 --- a/spec/lib/phony/national_splitters/variable_spec.rb +++ b/spec/lib/phony/national_splitters/variable_spec.rb @@ -8,16 +8,16 @@ @splitter = Phony::NationalSplitters::Variable.new 4, ['1', '316', '67', '68', '669', '711'] end it "handles Vienna" do - @splitter.split('198110').should == ['1', '98110'] + @splitter.split('198110').should == ['0', '1', '98110'] end it "handles some mobile services" do - @splitter.split('66914093902').should == ['669', '14093902'] + @splitter.split('66914093902').should == ['0', '669', '14093902'] end it "handles Graz" do - @splitter.split('3161234567891').should == ['316', '1234567891'] + @splitter.split('3161234567891').should == ['0', '316', '1234567891'] end it "handles Rohrau" do - @splitter.split('2164123456789').should == ['2164', '123456789'] + @splitter.split('2164123456789').should == ['0', '2164', '123456789'] end end context 'special handling for using the variable size splitter for Swiss service numbers' do @@ -25,7 +25,7 @@ @splitter = Phony::NationalSplitters::Variable.new 2, ['800'] end it "should handle swiss service numbers" do - @splitter.split('800223344').should == ['800', '223344'] + @splitter.split('800223344').should == ['0', '800', '223344'] end end end