aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting/tests.rs')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs58
1 files changed, 43 insertions, 15 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 021f8e7e2..b4d56a7a0 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -7,18 +7,6 @@ use crate::{
7 FileRange, TextRange, 7 FileRange, TextRange,
8}; 8};
9 9
10/// Highlights the code given by the `ra_fixture` argument, renders the
11/// result as HTML, and compares it with the HTML file given as `snapshot`.
12/// Note that the `snapshot` file is overwritten by the rendered HTML.
13fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) {
14 let (analysis, file_id) = single_file(ra_fixture);
15 let dst_file = project_dir().join(snapshot);
16 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
17 let expected_html = &read_text(&dst_file);
18 fs::write(dst_file, &actual_html).unwrap();
19 assert_eq_text!(expected_html, actual_html);
20}
21
22#[test] 10#[test]
23fn test_highlighting() { 11fn test_highlighting() {
24 check_highlighting( 12 check_highlighting(
@@ -55,6 +43,12 @@ def_fn! {
55 } 43 }
56} 44}
57 45
46macro_rules! noop {
47 ($expr:expr) => {
48 $expr
49 }
50}
51
58// comment 52// comment
59fn main() { 53fn main() {
60 println!("Hello, {}!", 92); 54 println!("Hello, {}!", 92);
@@ -73,10 +67,14 @@ fn main() {
73 // Do nothing 67 // Do nothing
74 } 68 }
75 69
70 noop!(noop!(1));
71
76 let mut x = 42; 72 let mut x = 42;
77 let y = &mut x; 73 let y = &mut x;
78 let z = &y; 74 let z = &y;
79 75
76 let Foo { x: z, y } = Foo { x: z, y };
77
80 y; 78 y;
81} 79}
82 80
@@ -248,6 +246,10 @@ fn main() {
248 246
249 println!(r"Hello, {}!", "world"); 247 println!(r"Hello, {}!", "world");
250 248
249 // escape sequences
250 println!("Hello\nWorld");
251 println!("\u{48}\x65\x6C\x6C\x6F World");
252
251 println!("{\x41}", A = 92); 253 println!("{\x41}", A = 92);
252 println!("{ничоси}", ничоси = 92); 254 println!("{ничоси}", ничоси = 92);
253}"# 255}"#
@@ -289,7 +291,13 @@ fn main() {
289fn test_highlight_doctest() { 291fn test_highlight_doctest() {
290 check_highlighting( 292 check_highlighting(
291 r#" 293 r#"
294struct Foo {
295 bar: bool,
296}
297
292impl Foo { 298impl Foo {
299 pub const bar: bool = true;
300
293 /// Constructs a new `Foo`. 301 /// Constructs a new `Foo`.
294 /// 302 ///
295 /// # Examples 303 /// # Examples
@@ -299,7 +307,7 @@ impl Foo {
299 /// let mut foo: Foo = Foo::new(); 307 /// let mut foo: Foo = Foo::new();
300 /// ``` 308 /// ```
301 pub const fn new() -> Foo { 309 pub const fn new() -> Foo {
302 Foo { } 310 Foo { bar: true }
303 } 311 }
304 312
305 /// `bar` method on `Foo`. 313 /// `bar` method on `Foo`.
@@ -307,11 +315,15 @@ impl Foo {
307 /// # Examples 315 /// # Examples
308 /// 316 ///
309 /// ``` 317 /// ```
318 /// use x::y;
319 ///
310 /// let foo = Foo::new(); 320 /// let foo = Foo::new();
311 /// 321 ///
312 /// // calls bar on foo 322 /// // calls bar on foo
313 /// assert!(foo.bar()); 323 /// assert!(foo.bar());
314 /// 324 ///
325 /// let bar = foo.bar || Foo::bar;
326 ///
315 /// /* multi-line 327 /// /* multi-line
316 /// comment */ 328 /// comment */
317 /// 329 ///
@@ -321,9 +333,13 @@ impl Foo {
321 /// 333 ///
322 /// ``` 334 /// ```
323 /// 335 ///
324 /// ``` 336 /// ```rust,no_run
325 /// let foobar = Foo::new().bar(); 337 /// let foobar = Foo::new().bar();
326 /// ``` 338 /// ```
339 ///
340 /// ```sh
341 /// echo 1
342 /// ```
327 pub fn foo(&self) -> bool { 343 pub fn foo(&self) -> bool {
328 true 344 true
329 } 345 }
@@ -332,5 +348,17 @@ impl Foo {
332 .trim(), 348 .trim(),
333 "crates/ra_ide/src/snapshots/highlight_doctest.html", 349 "crates/ra_ide/src/snapshots/highlight_doctest.html",
334 false, 350 false,
335 ) 351 );
352}
353
354/// Highlights the code given by the `ra_fixture` argument, renders the
355/// result as HTML, and compares it with the HTML file given as `snapshot`.
356/// Note that the `snapshot` file is overwritten by the rendered HTML.
357fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) {
358 let (analysis, file_id) = single_file(ra_fixture);
359 let dst_file = project_dir().join(snapshot);
360 let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
361 let expected_html = &read_text(&dst_file);
362 fs::write(dst_file, &actual_html).unwrap();
363 assert_eq_text!(expected_html, actual_html);
336} 364}