-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsms_info_test.go
116 lines (108 loc) · 2.75 KB
/
sms_info_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package sms_info
import (
"testing"
)
type testCase struct {
description string
inputText string
expectedLen int
expectedPartsCount int
expectedRunesPerPart int
expectedCharsetIsGsm bool
}
var smsTexts = []testCase{
{
"empty sms",
"",
0,
0,
0,
true,
},
{
"one part in gsm",
"Hello! This short message tells you nothing",
43,
1,
153,
true,
},
{
"one part in ucs",
"Привет! Это короткое сообщение не имеет смысла",
46,
1,
67,
false,
},
{
"several parts in gsm",
"Hello! This is a very-very long message for sms service. Though it tells you nothing, it still must be split into 2 parts to be sent over sms as it's length exceeds the limit for single sms",
189,
2,
153,
true,
},
{
"several parts in ucs",
"Привет! Это довольно длинное смс-сообщение. Хотя оно не имеет смысла, оно все равно состоит из двух частей",
106,
2,
67,
false,
},
{
"two positions chars in gsm, one sms",
"He[]o! This short message tells you ^thing, but costs 30€",
61,
1,
153,
true,
},
{
"two positions chars in ucs, one sms",
"Привет| Это короткое смс~сообщение. Но оно стоит 30€",
55,
1,
67,
false,
},
{
"two positions chars in gsm, several parts",
"He[]o! This is a very long message for sms service. Though it tells you nothing, it still must be split into 2 parts to be sent over sms as it~s length exceeds the limit for single sms",
187,
2,
153,
true,
},
{
"two positions chars in ucs, several parts",
"Привет| Это довольно длинное смс~сообщение. Оно не имеет смысла, но все равно состоит из двух частей и стоит 30€",
115,
2,
67,
false,
},
}
func TestSmsInfo(t *testing.T) {
for _, tc := range smsTexts {
t.Run(tc.description, func(t *testing.T) {
smsInfo := NewSmsInfo(tc.inputText)
if smsInfo.Text() != tc.inputText {
t.Errorf("Expected text: '%s', got: '%s'", tc.inputText, smsInfo.Text())
}
if smsInfo.Len() != tc.expectedLen {
t.Errorf("Expected text len: %d, got: %d", tc.expectedLen, smsInfo.Len())
}
if smsInfo.PartsCount() != tc.expectedPartsCount {
t.Errorf("Expected parts count: %d, got: %d", tc.expectedPartsCount, smsInfo.PartsCount())
}
if smsInfo.RunesPerPart() != tc.expectedRunesPerPart {
t.Errorf("Expected runes per part: %d, got: %d", tc.expectedRunesPerPart, smsInfo.RunesPerPart())
}
if smsInfo.IsGsm() != tc.expectedCharsetIsGsm {
t.Errorf("Expected isGsm to be %v, got: %v", tc.expectedCharsetIsGsm, smsInfo.IsGsm())
}
})
}
}