Skip to content

Commit

Permalink
Update and clarify specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Jun 8, 2021
1 parent 4152f17 commit e73319f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
27 changes: 13 additions & 14 deletions qed/country-specific.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

#### NANP

```ruby
nanp = Phony['1']

nanp.format('5551234567890', :format => :international).assert == '+1 (555) 123-4567890'
nanp.format('5551234567890', :format => :national).assert == '(555) 123-4567890'
nanp.format('5551234567890', :format => :local).assert == '123-4567890'

nanp.normalize("555 1234567890").assert == '5551234567890'
nanp.normalize("+1 555 1234567890").assert == '5551234567890'
nanp.normalize("+1 (0) 555 1234567890").assert == '5551234567890'
nanp.normalize('4159224711').assert == '4159224711'

nanp.assert.plausible?('4159224711')
```
nanp = Phony['1']

nanp.format('5551234567890', :format => :international).assert == '+1 (555) 123-4567890'
nanp.format('5551234567890', :format => :national).assert == '(555) 123-4567890'
nanp.format('5551234567890', :format => :local).assert == '123-4567890'

nanp.normalize("555 1234567890").assert == '5551234567890'
nanp.normalize('4159224711').assert == '4159224711'

Important: It is not expected to handle an international number correctly. This fails:

Expand All @@ -29,6 +23,11 @@ Only expects and handles normalized national numbers:

Phony["81"].format('312345634', :format => :international).assert == '+81 3-1234-5634'

But note that these will not fail, as the contained numbers are still a NANP number.

nanp.normalize("+1 555 1234567890").assert == '15551234567890'
nanp.normalize("+1 (0) 555 1234567890").assert == '15551234567890'

#### Japan

The domestic Telephone number in Japan has to have Trunk prefix.
Expand Down
1 change: 1 addition & 0 deletions qed/normalize.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Handles a number with extra 0.
#### Japan

Phony.normalize('+81 3-1234-5634').assert == '81312345634'
Phony.normalize('3-1234-5634', cc: '81').assert == '81312345634'
Phony.normalize('03-1234-5634', cc: '81').assert == '81312345634'

#### Lithuania
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/phony/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
Phony.normalize('+378903549').should == '3780549903549'
end
end
describe 'Japan' do
it 'normalizes correctly' do
Phony.normalize('03-1234-5634', cc: '81').should == '81312345634'
end
end
end

context "without special cases (with switzerland)" do
Expand Down

0 comments on commit e73319f

Please sign in to comment.