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
use codebook::queries::LanguageType;
use super::utils::{assert_spelling, assert_spelling_at};
/// Anchor test for the tree-sitter (code) path: strict positional checking
/// via occurrence indices. The emoji in the comment and string sit BEFORE
/// most misspellings so multi-byte offset drift shifts the reported ranges
/// and fails the comparison. Occurrence indices count case-sensitive
/// substring matches: e.g. `Userr` occurs inside `GetUserr` because
/// camelCase splitting flags it at that sub-token range.
#[test]
fn test_go_location() {
let sample_text = r#"
package pacagename
import myfmt "fmt"
type Userr struct {
Namee string `json:"namme"`
}
type UserServicce interface {
GetUserr(id string) Userr
}
const MaxNameeSize = 100
func (u *Userr) GetUserr(prefixx string) Userr {
return Userr{Namee: prefixx + "Alice"}
}
func main() {
// I'm bad at speling 😀 alice
myfmt.Println("Hello, 🌍 Wolrd!")
var alicz = "Alicz"
myfmt.Println("Hellol, " + alicz)
var rsvp = "RSVP"
myfmt.Println("Hello, " + rsvp)
cokbookkk := "test valie"
myfmt.Println("Hello, " + cokbookkk)
outerr:
for imdex := 0; imdex < 10; imdex++ {
if imdex == 5 {
break outerr
}
}
itemns := []string{"firstt", "seconnd", "tihrd"}
for indexx, valuue := range itemns {
myfmt.Println(indexx, valuue)
}
myfmt.Println(itemns)
}"#;
assert_spelling_at(
LanguageType::Go,
sample_text,
&[
("pacagename", &[0]),
// Identifiers are flagged at their definition, not at usages.
("myfmt", &[0]),
// All 7 occurrences: type name, inside both GetUserr methods
// (camelCase split), receiver, return types, and struct literal.
("Userr", &[0, 1, 2, 3, 4, 5, 6]),
("prefixx", &[0]),
// Struct field definition and inside MaxNameeSize (camelCase
// split); the `Userr{Namee:` usage is not flagged.
("Namee", &[0, 1]),
("Servicce", &[0]),
("namme", &[0]),
// Labels are flagged at definition and at `break`.
("outerr", &[0, 1]),
("itemns", &[0]),
("indexx", &[0]),
("cokbookkk", &[0]),
("valie", &[0]),
("Wolrd", &[0]),
("Alicz", &[0]),
("alicz", &[0]),
("speling", &[0]),
("Hellol", &[0]),
("imdex", &[0]),
("firstt", &[0]),
("seconnd", &[0]),
("tihrd", &[0]),
("valuue", &[0]),
],
);
}
#[test]
fn test_go_imports_not_checked() {
let sample_text = r#"
package main
import (
"fmt"
"net/http"
"github.com/someuserr/mypackagee"
myfmt "github.com/anotherr/fmtpkg"
)
func main() {
fmt.Println("hello")
}"#;
assert_spelling(
LanguageType::Go,
sample_text,
// Import aliases are still checked.
&["myfmt"],
// Import path contents are not spell-checked.
&["someuserr", "mypackagee", "anotherr", "fmtpkg"],
);
}