Add proc macro Literal parse test
This commit is contained in:
parent
faad7e209d
commit
965bce4834
@ -9,12 +9,16 @@
|
||||
extern crate proc_macro;
|
||||
|
||||
mod cmp;
|
||||
mod parse;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn run(input: TokenStream) -> TokenStream {
|
||||
assert!(input.is_empty());
|
||||
|
||||
cmp::test();
|
||||
parse::test();
|
||||
|
||||
TokenStream::new()
|
||||
}
|
||||
|
23
src/test/ui/proc-macro/auxiliary/api/parse.rs
Normal file
23
src/test/ui/proc-macro/auxiliary/api/parse.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use proc_macro::Literal;
|
||||
|
||||
pub fn test() {
|
||||
test_parse_literal();
|
||||
}
|
||||
|
||||
fn test_parse_literal() {
|
||||
assert_eq!("1".parse::<Literal>().unwrap().to_string(), "1");
|
||||
assert_eq!("1.0".parse::<Literal>().unwrap().to_string(), "1.0");
|
||||
assert_eq!("'a'".parse::<Literal>().unwrap().to_string(), "'a'");
|
||||
assert_eq!("\"\n\"".parse::<Literal>().unwrap().to_string(), "\"\n\"");
|
||||
assert_eq!("b\"\"".parse::<Literal>().unwrap().to_string(), "b\"\"");
|
||||
assert_eq!("r##\"\"##".parse::<Literal>().unwrap().to_string(), "r##\"\"##");
|
||||
assert_eq!("10ulong".parse::<Literal>().unwrap().to_string(), "10ulong");
|
||||
|
||||
assert!("0 1".parse::<Literal>().is_err());
|
||||
assert!("'a".parse::<Literal>().is_err());
|
||||
assert!(" 0".parse::<Literal>().is_err());
|
||||
assert!("0 ".parse::<Literal>().is_err());
|
||||
assert!("/* comment */0".parse::<Literal>().is_err());
|
||||
assert!("0/* comment */".parse::<Literal>().is_err());
|
||||
assert!("0// comment".parse::<Literal>().is_err());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user