From adf624b433277a0106f5354bb7d62ab1a04f216b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 11:19:40 +0200 Subject: Add file support to expect --- crates/ra_ide/src/syntax_highlighting/tests.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index b7fad9719..f19628485 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -1,6 +1,7 @@ use std::fs; -use test_utils::{assert_eq_text, project_dir, read_text}; +use expect::{expect_file, ExpectFile}; +use test_utils::project_dir; use crate::{mock_analysis::single_file, FileRange, TextRange}; @@ -91,7 +92,7 @@ impl Option { } "# .trim(), - "crates/ra_ide/src/snapshots/highlighting.html", + expect_file!["crates/ra_ide/src/snapshots/highlighting.html"], false, ); } @@ -114,7 +115,7 @@ fn bar() { } "# .trim(), - "crates/ra_ide/src/snapshots/rainbow_highlighting.html", + expect_file!["crates/ra_ide/src/snapshots/rainbow_highlighting.html"], true, ); } @@ -167,7 +168,7 @@ fn main() { ); }"## .trim(), - "crates/ra_ide/src/snapshots/highlight_injection.html", + expect_file!["crates/ra_ide/src/snapshots/highlight_injection.html"], false, ); } @@ -250,7 +251,7 @@ fn main() { println!("{ничоси}", ничоси = 92); }"# .trim(), - "crates/ra_ide/src/snapshots/highlight_strings.html", + expect_file!["crates/ra_ide/src/snapshots/highlight_strings.html"], false, ); } @@ -278,7 +279,7 @@ fn main() { } "# .trim(), - "crates/ra_ide/src/snapshots/highlight_unsafe.html", + expect_file!["crates/ra_ide/src/snapshots/highlight_unsafe.html"], false, ); } @@ -354,7 +355,7 @@ macro_rules! noop { } "# .trim(), - "crates/ra_ide/src/snapshots/highlight_doctest.html", + expect_file!["crates/ra_ide/src/snapshots/highlight_doctest.html"], false, ); } @@ -362,11 +363,8 @@ macro_rules! noop { /// 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. -fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) { +fn check_highlighting(ra_fixture: &str, expect: ExpectFile, rainbow: bool) { let (analysis, file_id) = single_file(ra_fixture); - let dst_file = project_dir().join(snapshot); let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap(); - let expected_html = &read_text(&dst_file); - fs::write(dst_file, &actual_html).unwrap(); - assert_eq_text!(expected_html, actual_html); + expect.assert_eq(actual_html) } -- cgit v1.2.3