Repository navigation
Expand file tree
/
Copy pathutils_test.go
More file actions
70 lines (63 loc) Β· 1.8 KB
/
Copy pathutils_test.go
File metadata and controls
70 lines (63 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package wrap
import "testing"
func TestIsASCII(t *testing.T) {
tests := []struct {
name string
input string
expected bool
}{
{"empty string", "", true},
{"ASCII only", "hello world 123!@#", true},
{"non-ASCII at end", "hello δΈη", false},
{"non-ASCII at start", "ζ₯ζ¬ hello", false},
{"all non-ASCII", "ζ₯ζ¬θͺ", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isASCII(tt.input); got != tt.expected {
t.Errorf("isASCII(%q) = %v, want %v", tt.input, got, tt.expected)
}
})
}
}
func TestRuneIndexToByte(t *testing.T) {
tests := []struct {
name string
input string
runeIndex int
expected int
}{
{"ASCII runeIndex < len", "abcdef", 3, 3},
{"ASCII runeIndex >= len", "abc", 5, 3},
{"non-ASCII runeIndex < len", "ζ₯ζ¬θͺ", 2, 6},
{"non-ASCII runeIndex >= len", "ζ₯ζ¬", 5, 6},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := runeIndexToByte(tt.input, tt.runeIndex); got != tt.expected {
t.Errorf("runeIndexToByte(%q, %d) = %d, want %d", tt.input, tt.runeIndex, got, tt.expected)
}
})
}
}
func TestRuneIndexToByteWithShortCheck(t *testing.T) {
tests := []struct {
name string
input string
runeIndex int
expected int
}{
{"ASCII runeIndex <= len", "abcdef", 3, 3},
{"ASCII runeIndex > len", "abc", 5, -1},
{"non-ASCII runeIndex <= len", "ζ₯ζ¬θͺ", 2, 6},
{"non-ASCII runeIndex > len, not enough runes", "ζ₯ζ¬", 10, -1},
{"non-ASCII loop terminates early", "ζ₯", 2, -1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := runeIndexToByteWithShortCheck(tt.input, tt.runeIndex); got != tt.expected {
t.Errorf("runeIndexToByteWithShortCheck(%q, %d) = %d, want %d", tt.input, tt.runeIndex, got, tt.expected)
}
})
}
}