about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-07-08 20:24:29 -0700
committerDavid Tolnay <dtolnay@gmail.com>2021-07-18 14:08:34 -0700
commit55ff45a5c25c49e665a9459b8d6ea03ae2c44476 (patch)
tree454ce7299b38c0e9552a98c023a5a0ab5a271ebf /src
parent331da5820cfeb937dcdd76192d97a5fc4dd115c8 (diff)
Support negative numbers in Literal::from_str
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/proc-macro/auxiliary/api/parse.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/test/ui/proc-macro/auxiliary/api/parse.rs b/src/test/ui/proc-macro/auxiliary/api/parse.rs
index 4105236b7f2..a304c5e81a4 100644
--- a/src/test/ui/proc-macro/auxiliary/api/parse.rs
+++ b/src/test/ui/proc-macro/auxiliary/api/parse.rs
@@ -1,9 +1,15 @@
 use proc_macro::Literal;
 
 pub fn test() {
+    test_display_literal();
     test_parse_literal();
 }
 
+fn test_display_literal() {
+    assert_eq!(Literal::isize_unsuffixed(-10).to_string(), "- 10");
+    assert_eq!(Literal::isize_suffixed(-10).to_string(), "- 10isize");
+}
+
 fn test_parse_literal() {
     assert_eq!("1".parse::<Literal>().unwrap().to_string(), "1");
     assert_eq!("1.0".parse::<Literal>().unwrap().to_string(), "1.0");
@@ -12,7 +18,10 @@ fn test_parse_literal() {
     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_eq!("-10ulong".parse::<Literal>().unwrap().to_string(), "- 10ulong");
 
+    assert!("true".parse::<Literal>().is_err());
+    assert!(".8".parse::<Literal>().is_err());
     assert!("0 1".parse::<Literal>().is_err());
     assert!("'a".parse::<Literal>().is_err());
     assert!(" 0".parse::<Literal>().is_err());
@@ -20,4 +29,6 @@ fn test_parse_literal() {
     assert!("/* comment */0".parse::<Literal>().is_err());
     assert!("0/* comment */".parse::<Literal>().is_err());
     assert!("0// comment".parse::<Literal>().is_err());
+    assert!("- 10".parse::<Literal>().is_err());
+    assert!("-'x'".parse::<Literal>().is_err());
 }