| 📦 Turbo Rust 713ea5c k33g 11h ago | 1 | package rustlang |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "rickub.com/turbo-editors/turbo-core/syntax" |
| 8 | ) |
| 9 | |
| 10 | // TestTheLanguagesReferenceIsTrue holds docs/*/reference/languages.md to the |
| 11 | // scanner. Every row of its Rust table that no other test here covers is |
| 12 | // checked, so a reference claim and the code cannot drift apart quietly. |
| 13 | // |
| 14 | // The MAX_SIZE case is the one that documents a limitation rather than a |
| 15 | // feature: the leading-capital rule colours a SCREAMING_SNAKE_CASE constant as |
| 16 | // a type, the reference says so, and this is what stops somebody "fixing" it |
| 17 | // without also fixing the sentence. |
| 18 | func TestTheLanguagesReferenceIsTrue(t *testing.T) { |
| 19 | tests := []struct { |
| 20 | src string |
| 21 | word string |
| 22 | want syntax.Class |
| 23 | }{ |
| 24 | {"//! module doc", "//! module doc", syntax.ClassComment}, |
| 25 | {"/// item doc", "/// item doc", syntax.ClassComment}, |
| 26 | {`let s = br##"a"#b"##;`, `br##"a"#b"##`, syntax.ClassString}, |
| 27 | {"for i in 0..=10 {}", "..=", syntax.ClassOperator}, |
| 28 | {"let x = std::mem::swap;", "::", syntax.ClassPunctuation}, |
| 29 | {"let x: u8 = 1;", ":", syntax.ClassPunctuation}, |
| 30 | {"async fn f() {}", "async", syntax.ClassKeyword}, |
| 31 | {"let x = become;", "become", syntax.ClassKeyword}, |
| 32 | {"let v: Vec<u8> = vec![];", "vec!", syntax.ClassBuiltin}, |
| 33 | {"#![no_std]", "#![no_std]", syntax.ClassAttribute}, |
| 34 | {"let n = 0o77;", "0o77", syntax.ClassNumber}, |
| 35 | {"let n = 3.0f64;", "3.0f64", syntax.ClassNumber}, |
| 36 | {"let c = b'x';", "b'x'", syntax.ClassChar}, |
| 37 | {"fn f<'a>() {}", "'a", syntax.ClassType}, |
| 38 | {"let x = MAX_SIZE;", "MAX_SIZE", syntax.ClassType}, |
| 39 | } |
| 40 | |
| 41 | for _, test := range tests { |
| 42 | t.Run(test.word, func(t *testing.T) { |
| 43 | index := strings.Index(test.src, test.word) |
| 44 | if index < 0 { |
| 45 | t.Fatalf("%q not in %q", test.word, test.src) |
| 46 | } |
| 47 | got, ok := classAt(Highlight(test.src), 0, index) |
| 48 | if !ok || got != test.want { |
| 49 | t.Errorf("%q in %q is %v (covered %v), want %v", test.word, test.src, got, ok, test.want) |
| 50 | } |
| 51 | }) |
| 52 | } |
| 53 | } |