]> git.lizzy.rs Git - rust.git/blob - ui_test/src/comments/tests.rs
Document all the things
[rust.git] / ui_test / src / comments / tests.rs
1 use std::path::Path;
2
3 use super::Comments;
4
5 use crate::tests::init;
6 use color_eyre::eyre::{bail, Result};
7
8 #[test]
9 fn parse_simple_comment() -> Result<()> {
10     init();
11     let s = r"
12 use std::mem;
13
14 fn main() {
15     let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR encountered a dangling reference (address $HEX is unallocated)
16 }
17     ";
18     let comments = Comments::parse(Path::new("<dummy>"), s)?;
19     println!("parsed comments: {:#?}", comments);
20     assert_eq!(comments.error_matches[0].definition_line, 5);
21     assert_eq!(comments.error_matches[0].revision, None);
22     assert_eq!(
23         comments.error_matches[0].matched,
24         "encountered a dangling reference (address $HEX is unallocated)"
25     );
26     Ok(())
27 }
28
29 #[test]
30 fn parse_slash_slash_at() -> Result<()> {
31     init();
32     let s = r"
33 //@  error-pattern:  foomp
34 use std::mem;
35
36     ";
37     let comments = Comments::parse(Path::new("<dummy>"), s)?;
38     println!("parsed comments: {:#?}", comments);
39     assert_eq!(comments.error_pattern, Some(("foomp".to_string(), 2)));
40     Ok(())
41 }
42
43 #[test]
44 fn parse_slash_slash_at_fail() -> Result<()> {
45     init();
46     let s = r"
47 //@  error-pattern  foomp
48 use std::mem;
49
50     ";
51     match Comments::parse(Path::new("<dummy>"), s) {
52         Ok(_) => bail!("expected parsing to fail"),
53         Err(_) => Ok(()),
54     }
55 }