Skip to content

Commit

Permalink
Add in check_length option for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Nov 6, 2021
1 parent 1d6d8fc commit e522e91
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/phony/country_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def plausible? number, hints = {}

# False if it fails the basic check.
#
return false unless (4..16) === normalized.size
return false unless (4..16) === normalized.size # unless hints[:check_length] == false

country, cc, rest = partial_split normalized

Expand Down
2 changes: 2 additions & 0 deletions lib/phony/local_splitters/fixed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def split number
#
#
def plausible? rest, hints = {}
return true if hints[:check_length] == false

@length === rest.inject(0) { |total, part| total + part.size }
end

Expand Down
18 changes: 17 additions & 1 deletion qed/plausibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ NDC with several subscriber number length.
Phony.assert.plausible?('+32 489 12 34 56')
Phony.assert.plausible?('+32 490 12 34 56')
Phony.assert.plausible?('+32 499 12 34 56')

# Edge cases with too long/short numbers (check_length option).
Phony.refute.plausible?('+s32 470 12 34 56 79')
Phony.assert.plausible?('+32 470 12 34 56 79', check_length: false)

#### Benin

Expand Down Expand Up @@ -508,14 +512,20 @@ Mobile.
Phony.assert.plausible?('+49 6421 123456789')
Phony.assert.plausible?('+49 209 1234567890')
Phony.assert.plausible?('+49 40 12345678901')

# Edge cases with too short numbers (check_length option).
Phony.refute.plausible?('49214301')
Phony.refute.plausible?('49251830')
Phony.assert.plausible?('49214301', check_length: false)
Phony.assert.plausible?('49251830', check_length: false)

#### Greece

plausible? true: [
'+30 21 4234 5678',
'+30 24 4234 5678',
'+30 50 3457 1234',
'+30 69 0123 4567',
'+30 690 123 4567',
'+30 70 0123 4567',
'+30 800 100 1234',
'+30 801 100 1234',
Expand All @@ -524,6 +534,12 @@ Mobile.
'+30 901 123 4565',
'+30 909 123 4565'
]

# Testing check_length option.
Phony.refute.plausible?('+30 690 123 127')
Phony.assert.plausible?('+30 690 123 127', check_length: false)
Phony.refute.plausible?('+30 690 123 12347')
Phony.assert.plausible?('+30 690 123 12347', check_length: false)

#### Hong Kong
plausible? true: [
Expand Down

0 comments on commit e522e91

Please sign in to comment.