|
| 1 | +// Copyright 2026 Phillip Cloud |
| 2 | +// Licensed under the Apache License, Version 2.0 |
| 3 | + |
| 4 | +package locale_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + |
| 11 | + "github.com/micasa-dev/micasa/internal/locale" |
| 12 | +) |
| 13 | + |
| 14 | +func TestFormatPhoneNumber(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + tests := []struct { |
| 17 | + name string |
| 18 | + number string |
| 19 | + region string |
| 20 | + want string |
| 21 | + }{ |
| 22 | + {"US national", "5551234567", "US", "(555) 123-4567"}, |
| 23 | + {"UK national", "02079460958", "GB", "020 7946 0958"}, |
| 24 | + {"international prefix", "+442079460958", "US", "+44 20 7946 0958"}, |
| 25 | + {"same-region prefix", "+15551234567", "US", "(555) 123-4567"}, |
| 26 | + {"already formatted", "(555) 123-4567", "US", "(555) 123-4567"}, |
| 27 | + {"cross-border shared code", "+16135551234", "US", "+1 613-555-1234"}, |
| 28 | + {"garbage passthrough", "not a phone", "US", "not a phone"}, |
| 29 | + {"empty string", "", "US", ""}, |
| 30 | + {"whitespace only", " ", "US", ""}, |
| 31 | + } |
| 32 | + for _, tt := range tests { |
| 33 | + t.Run(tt.name, func(t *testing.T) { |
| 34 | + t.Parallel() |
| 35 | + got := locale.FormatPhoneNumber(tt.number, tt.region) |
| 36 | + assert.Equal(t, tt.want, got) |
| 37 | + }) |
| 38 | + } |
| 39 | +} |
0 commit comments