diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlight_trait_items.html | 67 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 37 |
2 files changed, 104 insertions, 0 deletions
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_trait_items.html b/crates/ide/src/syntax_highlighting/test_data/highlight_trait_items.html new file mode 100644 index 000000000..85274a61f --- /dev/null +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_trait_items.html | |||
@@ -0,0 +1,67 @@ | |||
1 | |||
2 | <style> | ||
3 | body { margin: 0; } | ||
4 | pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } | ||
5 | |||
6 | .lifetime { color: #DFAF8F; font-style: italic; } | ||
7 | .label { color: #DFAF8F; font-style: italic; } | ||
8 | .comment { color: #7F9F7F; } | ||
9 | .documentation { color: #629755; } | ||
10 | .intra_doc_link { font-style: italic; } | ||
11 | .injected { opacity: 0.65 ; } | ||
12 | .struct, .enum { color: #7CB8BB; } | ||
13 | .enum_variant { color: #BDE0F3; } | ||
14 | .string_literal { color: #CC9393; } | ||
15 | .field { color: #94BFF3; } | ||
16 | .function { color: #93E0E3; } | ||
17 | .function.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | ||
19 | .parameter { color: #94BFF3; } | ||
20 | .text { color: #DCDCCC; } | ||
21 | .type { color: #7CB8BB; } | ||
22 | .builtin_type { color: #8CD0D3; } | ||
23 | .type_param { color: #DFAF8F; } | ||
24 | .attribute { color: #94BFF3; } | ||
25 | .numeric_literal { color: #BFEBBF; } | ||
26 | .bool_literal { color: #BFE6EB; } | ||
27 | .macro { color: #94BFF3; } | ||
28 | .module { color: #AFD8AF; } | ||
29 | .value_param { color: #DCDCCC; } | ||
30 | .variable { color: #DCDCCC; } | ||
31 | .format_specifier { color: #CC696B; } | ||
32 | .mutable { text-decoration: underline; } | ||
33 | .escape_sequence { color: #94BFF3; } | ||
34 | .keyword { color: #F0DFAF; font-weight: bold; } | ||
35 | .keyword.unsafe { color: #BC8383; font-weight: bold; } | ||
36 | .control { font-style: italic; } | ||
37 | |||
38 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } | ||
39 | </style> | ||
40 | <pre><code><span class="keyword">struct</span> <span class="struct declaration">Cat</span><span class="semicolon">;</span> | ||
41 | |||
42 | <span class="keyword">trait</span> <span class="trait declaration">Animal</span> <span class="brace">{</span> | ||
43 | <span class="keyword">const</span> <span class="constant declaration associated trait">SOUND</span><span class="colon">:</span> <span class="operator">&</span><span class="lifetime">'static</span> <span class="builtin_type">str</span><span class="semicolon">;</span> | ||
44 | |||
45 | <span class="keyword">fn</span> <span class="function declaration associated trait">make_sound</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span> | ||
46 | <span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"{}"</span><span class="comma">,</span> Self<span class="colon">:</span><span class="colon">:</span>SOUND<span class="parenthesis">)</span><span class="semicolon">;</span> | ||
47 | <span class="brace">}</span> | ||
48 | <span class="brace">}</span> | ||
49 | |||
50 | <span class="keyword">impl</span> <span class="trait">Animal</span> <span class="keyword">for</span> <span class="struct">Cat</span> <span class="brace">{</span> | ||
51 | <span class="keyword">const</span> <span class="constant declaration associated trait">SOUND</span><span class="colon">:</span> <span class="operator">&</span><span class="lifetime">'static</span> <span class="builtin_type">str</span> <span class="operator">=</span> <span class="string_literal">"Meow!"</span><span class="semicolon">;</span> | ||
52 | <span class="brace">}</span> | ||
53 | |||
54 | <span class="keyword">impl</span> <span class="struct">Cat</span> <span class="brace">{</span> | ||
55 | <span class="keyword">const</span> <span class="constant declaration associated">SPEED</span><span class="colon">:</span> <span class="builtin_type">u32</span> <span class="operator">=</span> <span class="numeric_literal">2</span><span class="semicolon">;</span> | ||
56 | |||
57 | <span class="keyword">fn</span> <span class="function declaration static associated">run</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | ||
58 | <span class="brace">}</span> | ||
59 | |||
60 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> | ||
61 | <span class="keyword">let</span> <span class="variable declaration">cat</span> <span class="operator">=</span> <span class="struct">Cat</span><span class="semicolon">;</span> | ||
62 | <span class="variable">cat</span><span class="operator">.</span><span class="function associated trait">make_sound</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | ||
63 | <span class="keyword">let</span> <span class="variable declaration">_sound</span> <span class="operator">=</span> <span class="struct">Cat</span><span class="operator">::</span><span class="constant associated trait">SOUND</span><span class="semicolon">;</span> | ||
64 | <span class="keyword">let</span> <span class="variable declaration">_speed</span> <span class="operator">=</span> <span class="struct">Cat</span><span class="operator">::</span><span class="constant associated">SPEED</span><span class="semicolon">;</span> | ||
65 | <span class="struct">Cat</span><span class="operator">::</span><span class="function static associated">run</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | ||
66 | <span class="brace">}</span> | ||
67 | </code></pre> \ No newline at end of file | ||
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 369ae0972..7b3b5caf9 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -659,6 +659,43 @@ fn foo() { | |||
659 | ); | 659 | ); |
660 | } | 660 | } |
661 | 661 | ||
662 | #[test] | ||
663 | fn test_highlight_trait_items() { | ||
664 | check_highlighting( | ||
665 | r#" | ||
666 | struct Cat; | ||
667 | |||
668 | trait Animal { | ||
669 | const SOUND: &'static str; | ||
670 | |||
671 | fn make_sound(&self) { | ||
672 | println!("{}", Self::SOUND); | ||
673 | } | ||
674 | } | ||
675 | |||
676 | impl Animal for Cat { | ||
677 | const SOUND: &'static str = "Meow!"; | ||
678 | } | ||
679 | |||
680 | impl Cat { | ||
681 | const SPEED: u32 = 2; | ||
682 | |||
683 | fn run() {} | ||
684 | } | ||
685 | |||
686 | fn main() { | ||
687 | let cat = Cat; | ||
688 | cat.make_sound(); | ||
689 | let _sound = Cat::SOUND; | ||
690 | let _speed = Cat::SPEED; | ||
691 | Cat::run(); | ||
692 | } | ||
693 | "#, | ||
694 | expect_file!["./test_data/highlight_trait_items.html"], | ||
695 | false, | ||
696 | ); | ||
697 | } | ||
698 | |||
662 | /// Highlights the code given by the `ra_fixture` argument, renders the | 699 | /// Highlights the code given by the `ra_fixture` argument, renders the |
663 | /// result as HTML, and compares it with the HTML file given as `snapshot`. | 700 | /// result as HTML, and compares it with the HTML file given as `snapshot`. |
664 | /// Note that the `snapshot` file is overwritten by the rendered HTML. | 701 | /// Note that the `snapshot` file is overwritten by the rendered HTML. |