]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/proc-macro/auxiliary/api/parse.rs
27391f8311176cdb17fdac88f274734228a87a2a
1 // ignore-tidy-linelength
3 use proc_macro
::Literal
;
6 test_display_literal();
10 fn test_display_literal() {
11 assert_eq
!(Literal
::isize_unsuffixed(-10).to_string(), "-10");
12 assert_eq
!(Literal
::isize_suffixed(-10).to_string(), "-10isize");
13 assert_eq
!(Literal
::f32_unsuffixed(-10.0).to_string(), "-10.0");
14 assert_eq
!(Literal
::f32_suffixed(-10.0).to_string(), "-10f32");
15 assert_eq
!(Literal
::f64_unsuffixed(-10.0).to_string(), "-10.0");
16 assert_eq
!(Literal
::f64_suffixed(-10.0).to_string(), "-10f64");
18 Literal
::f64_unsuffixed(1e100
).to_string(),
19 "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0",
23 Literal
::string("a \t ❤ ' \" \u{1}").to_string(),
24 "\"a \\t ❤ ' \\\" \\u{1}\"",
26 assert_eq
!(Literal
::character('a'
).to_string(), "'a'");
27 assert_eq
!(Literal
::character('
\t'
).to_string(), "'\\t'");
28 assert_eq
!(Literal
::character('❤'
).to_string(), "'❤'");
29 assert_eq
!(Literal
::character('
\''
).to_string(), "'\\''");
30 assert_eq
!(Literal
::character('
"').to_string(), "'
\"'
");
31 assert_eq!(Literal::character('\u{1}').to_string(), "'
\\u{1}'
");
34 fn test_parse_literal() {
35 assert_eq!("1".parse::<Literal>().unwrap().to_string(), "1");
36 assert_eq!("1.0".parse::<Literal>().unwrap().to_string(), "1.0");
37 assert_eq!("'a'
".parse::<Literal>().unwrap().to_string(), "'a'
");
38 assert_eq!("\"\n\"".parse::<Literal>().unwrap().to_string(), "\"\n\"");
39 assert_eq!("b
\"\"".parse::<Literal>().unwrap().to_string(), "b
\"\"");
40 assert_eq!("r
##\"\"##".parse::<Literal>().unwrap().to_string(), "r##\"\"##");
41 assert_eq!("10ulong".parse::<Literal>().unwrap().to_string(), "10ulong");
42 assert_eq!("-10ulong".parse::<Literal>().unwrap().to_string(), "-10ulong");
44 assert!("true".parse::<Literal>().is_err());
45 assert!(".8".parse::<Literal>().is_err());
46 assert!("0 1".parse::<Literal>().is_err());
47 assert!("'a".parse::<Literal>().is_err());
48 assert!(" 0".parse::<Literal>().is_err());
49 assert!("0 ".parse::<Literal>().is_err());
50 assert!("/* comment */0".parse::<Literal>().is_err());
51 assert!("0/* comment */".parse::<Literal>().is_err());
52 assert!("0// comment".parse::<Literal>().is_err());
53 assert
!("- 10".parse
::<Literal
>().is_err());
54 assert
!("-'x'".parse
::<Literal
>().is_err());