-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathbuilder_test.go
More file actions
51 lines (45 loc) · 1.8 KB
/
Copy pathbuilder_test.go
File metadata and controls
51 lines (45 loc) · 1.8 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
package phonenumbers
import (
"testing"
"github.com/nyaruka/phonenumbers/v2/internal/metadatabuilder"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestBuilderProcessesSmsServices verifies the short-number metadata builder now
// reads the <smsServices> element (it was previously dropped, leaving
// IsSmsServiceForRegion non-functional). Exercised through the builder directly
// since the committed embedded short metadata predates this fix and carries no
// smsServices data.
func TestBuilderProcessesSmsServices(t *testing.T) {
const shortXML = `<?xml version="1.0" encoding="UTF-8"?>
<phoneNumberMetadata>
<territories>
<territory id="US" countryCode="1">
<generalDesc>
<nationalNumberPattern>[1-9]\d{2,5}</nationalNumberPattern>
</generalDesc>
<shortCode>
<possibleLengths national="[3-6]"/>
<exampleNumber>112</exampleNumber>
<nationalNumberPattern>[2-9]\d{2,5}</nationalNumberPattern>
</shortCode>
<smsServices>
<possibleLengths national="5,6"/>
<exampleNumber>20000</exampleNumber>
<nationalNumberPattern>[2-9]\d{4,5}</nationalNumberPattern>
</smsServices>
</territory>
</territories>
</phoneNumberMetadata>`
coll, err := metadatabuilder.BuildPhoneMetadataCollection([]byte(shortXML), false, false, true)
require.NoError(t, err)
require.Len(t, coll.GetMetadata(), 1)
us := coll.GetMetadata()[0]
sms := us.GetSmsServices()
require.NotNil(t, sms)
assert.Equal(t, `[2-9]\d{4,5}`, sms.GetNationalNumberPattern())
assert.Equal(t, []int32{5, 6}, sms.GetPossibleLength())
// And the matching helper used by IsSmsServiceForRegion now finds it.
assert.True(t, matchesPossibleNumberAndNationalNumber("21234", sms))
assert.False(t, matchesPossibleNumberAndNationalNumber("112", sms))
}