-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontext_test.go
More file actions
62 lines (57 loc) · 1.99 KB
/
Copy pathcontext_test.go
File metadata and controls
62 lines (57 loc) · 1.99 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
package main
import "testing"
func TestLooksLikeContext(t *testing.T) {
cases := []struct {
in string
want bool
why string
}{
// Should skip (looks like URL/email/path/identifier)
{"https://example.com", true, "URL with :/"},
{"user@gmail.com", true, "email"},
{"/var/log", true, "path"},
{"C:\\Users", true, "windows path"},
{"github.com/zlopixatel/bzz", true, "slash + dots"},
{"user_name", true, "snake_case"},
{"my_var_1", true, "snake_case digit"},
{"version1.2", true, "digit + dot"},
{"node_modules/lodash", true, "underscore + slash"},
{"google.com.au", true, "two dots tld"},
{"v1.2.3", true, "version triplet"},
// Should NOT skip (normal word, even with one hyphen or single dot at end)
{"", false, "empty"},
{"hello", false, "plain word"},
{"ghbdtn", false, "plain QWERTY-RU candidate"},
{"co-op", false, "single hyphen"},
{"don't", false, "apostrophe inside"},
{"hello,", false, "trailing comma (handled elsewhere)"},
}
for _, c := range cases {
got := looksLikeContext(c.in)
if got != c.want {
t.Errorf("looksLikeContext(%q) = %v, want %v (%s)", c.in, got, c.want, c.why)
}
}
}
// TestShouldSkipWord_SingleLetterBypass verifies that single-letter QWERTY
// codes mapped to Russian letters bypass MinWordLength=2.
func TestShouldSkipWord_SingleLetterBypass(t *testing.T) {
cfg := &Config{MinWordLength: 2}
cases := map[string]bool{ // word → expect skip
// single letters that map to Russian (bypass MinWordLength)
"z": false, "f": false, "d": false, "j": false,
"r": false, "c": false, "b": false, "e": false,
// single letters that don't map (no bypass → skipped by MinWordLength)
"a": true, "q": true, "x": true,
// empty / longer words: empty is shorter than 2 → skipped
"": true,
// digits / punct: not in singleLetterRu → skipped
"1": true, "?": true,
}
for word, want := range cases {
got, _ := shouldSkipWord(cfg, nil, word)
if got != want {
t.Errorf("shouldSkipWord(%q) skip=%v, want %v", word, got, want)
}
}
}