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
|
package rustlang
import (
"strings"
"testing"
"rickub.com/turbo-editors/turbo-core/syntax"
)
// TestTheLanguagesReferenceIsTrue holds docs/*/reference/languages.md to the
// scanner. Every row of its Rust table that no other test here covers is
// checked, so a reference claim and the code cannot drift apart quietly.
//
// The MAX_SIZE case is the one that documents a limitation rather than a
// feature: the leading-capital rule colours a SCREAMING_SNAKE_CASE constant as
// a type, the reference says so, and this is what stops somebody "fixing" it
// without also fixing the sentence.
func TestTheLanguagesReferenceIsTrue(t *testing.T) {
tests := []struct {
src string
word string
want syntax.Class
}{
{"//! module doc", "//! module doc", syntax.ClassComment},
{"/// item doc", "/// item doc", syntax.ClassComment},
{`let s = br##"a"#b"##;`, `br##"a"#b"##`, syntax.ClassString},
{"for i in 0..=10 {}", "..=", syntax.ClassOperator},
{"let x = std::mem::swap;", "::", syntax.ClassPunctuation},
{"let x: u8 = 1;", ":", syntax.ClassPunctuation},
{"async fn f() {}", "async", syntax.ClassKeyword},
{"let x = become;", "become", syntax.ClassKeyword},
{"let v: Vec<u8> = vec![];", "vec!", syntax.ClassBuiltin},
{"#![no_std]", "#![no_std]", syntax.ClassAttribute},
{"let n = 0o77;", "0o77", syntax.ClassNumber},
{"let n = 3.0f64;", "3.0f64", syntax.ClassNumber},
{"let c = b'x';", "b'x'", syntax.ClassChar},
{"fn f<'a>() {}", "'a", syntax.ClassType},
{"let x = MAX_SIZE;", "MAX_SIZE", syntax.ClassType},
}
for _, test := range tests {
t.Run(test.word, func(t *testing.T) {
index := strings.Index(test.src, test.word)
if index < 0 {
t.Fatalf("%q not in %q", test.word, test.src)
}
got, ok := classAt(Highlight(test.src), 0, index)
if !ok || got != test.want {
t.Errorf("%q in %q is %v (covered %v), want %v", test.word, test.src, got, ok, test.want)
}
})
}
}
|