8024: Added test case for highlighting trait items.

This commit is contained in:
Chetan Khilosiya 2021-03-31 00:30:01 +05:30
parent 56f624532a
commit d7dcd41801
2 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,67 @@
<style>
body { margin: 0; }
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
.lifetime { color: #DFAF8F; font-style: italic; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.string_literal { color: #CC9393; }
.field { color: #94BFF3; }
.function { color: #93E0E3; }
.function.unsafe { color: #BC8383; }
.operator.unsafe { color: #BC8383; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.builtin_type { color: #8CD0D3; }
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
.bool_literal { color: #BFE6EB; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.value_param { color: #DCDCCC; }
.variable { color: #DCDCCC; }
.format_specifier { color: #CC696B; }
.mutable { text-decoration: underline; }
.escape_sequence { color: #94BFF3; }
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
</style>
<pre><code><span class="keyword">struct</span> <span class="struct declaration">Cat</span><span class="semicolon">;</span>
<span class="keyword">trait</span> <span class="trait declaration">Animal</span> <span class="brace">{</span>
<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>
<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>
<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>
<span class="brace">}</span>
<span class="brace">}</span>
<span class="keyword">impl</span> <span class="trait">Animal</span> <span class="keyword">for</span> <span class="struct">Cat</span> <span class="brace">{</span>
<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>
<span class="brace">}</span>
<span class="keyword">impl</span> <span class="struct">Cat</span> <span class="brace">{</span>
<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>
<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>
<span class="brace">}</span>
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
<span class="keyword">let</span> <span class="variable declaration">cat</span> <span class="operator">=</span> <span class="struct">Cat</span><span class="semicolon">;</span>
<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>
<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>
<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>
<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>
<span class="brace">}</span>
</code></pre>

View File

@ -659,6 +659,43 @@ fn foo() {
);
}
#[test]
fn test_highlight_trait_items() {
check_highlighting(
r#"
struct Cat;
trait Animal {
const SOUND: &'static str;
fn make_sound(&self) {
println!("{}", Self::SOUND);
}
}
impl Animal for Cat {
const SOUND: &'static str = "Meow!";
}
impl Cat {
const SPEED: u32 = 2;
fn run() {}
}
fn main() {
let cat = Cat;
cat.make_sound();
let _sound = Cat::SOUND;
let _speed = Cat::SPEED;
Cat::run();
}
"#,
expect_file!["./test_data/highlight_trait_items.html"],
false,
);
}
/// Highlights the code given by the `ra_fixture` argument, renders the
/// result as HTML, and compares it with the HTML file given as `snapshot`.
/// Note that the `snapshot` file is overwritten by the rendered HTML.