File: phone_spec.lua

package info (click to toggle)
lua-lpeg-patterns 0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220 kB
  • sloc: makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local lpeg = require "lpeg"

describe("Phone numbers", function()
	local phone = require "lpeg_patterns.phone"
	local any_only = phone.phone * lpeg.P(-1)

	it("NANP (North America Numbering Plan)", function()
		assert.truthy(any_only:match"+12345678900")
		assert.truthy(any_only:match"+1 (234) 567-8900")

		assert.truthy(phone.USA:match"1 (234) 567-8900")
		assert.truthy(phone.USA:match"(234) 567-8900")
		assert.falsy(phone.USA:match"2 (234) 567-8900")

		-- N11 not allowed
		assert.falsy(any_only:match"+12345118900")
		-- N9X not allowed
		assert.falsy(any_only:match"+12345978900")
		-- 37X not allowed
		assert.falsy(any_only:match"+12343778900")
		-- 96X not allowed
		assert.falsy(any_only:match"+12349678900")
	end)

	it("Australian numbers", function()
		assert.truthy(phone.Australia:match"0390000000")
		assert.truthy(phone.Australia:match"3 90000000")
		assert.truthy(phone.Australia:match"3 9000 0000")
		assert.truthy(phone.Australia:match"400 000 000")

		assert.truthy(any_only:match"+61390000000")
		assert.truthy(any_only:match"+61 3 90000000")
		assert.truthy(any_only:match"+61 3 9000 0000")
		assert.truthy(any_only:match"+61 400 000 000")

		assert.falsy(any_only:match"+610390000000")
	end)
end)