aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_lit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_lit.rs')
-rw-r--r--tests/test_lit.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/test_lit.rs b/tests/test_lit.rs
index e995f228..099daf10 100644
--- a/tests/test_lit.rs
+++ b/tests/test_lit.rs
@@ -5,7 +5,7 @@ use proc_macro2::{Delimiter, Group, Literal, Span, TokenStream, TokenTree};
use quote::ToTokens;
use std::iter::FromIterator;
use std::str::FromStr;
-use syn::{Lit, LitFloat, LitInt};
+use syn::{Lit, LitFloat, LitInt, LitStr};
fn lit(s: &str) -> Lit {
match TokenStream::from_str(s)
@@ -43,6 +43,7 @@ fn strings() {
test_string("\"'\"", "'");
test_string("\"\"", "");
test_string("\"\\u{1F415}\"", "\u{1F415}");
+ test_string("\"\\u{1_2__3_}\"", "\u{123}");
test_string(
"\"contains\nnewlines\\\nescaped newlines\"",
"contains\nnewlinesescaped newlines",
@@ -151,6 +152,9 @@ fn ints() {
test_int("5", 5, "");
test_int("5u32", 5, "u32");
+ test_int("0E", 0, "E");
+ test_int("0ECMA", 0, "ECMA");
+ test_int("0o0A", 0, "A");
test_int("5_0", 50, "");
test_int("5_____0_____", 50, "");
test_int("0x7f", 127, "");
@@ -167,6 +171,7 @@ fn ints() {
test_int("0x_7F__u8", 127, "u8");
test_int("0b__10__0_1i8", 9, "i8");
test_int("0o__7__________________3u32", 59, "u32");
+ test_int("0e1\u{5c5}", 0, "e1\u{5c5}");
}
#[test]
@@ -192,6 +197,8 @@ fn floats() {
test_float("1.0__3e-12", 1.03e-12, "");
test_float("1.03e+12", 1.03e12, "");
test_float("9e99e99", 9e99, "e99");
+ test_float("1e_0", 1.0, "");
+ test_float("0.0ECMA", 0.0, "ECMA");
}
#[test]
@@ -208,6 +215,12 @@ fn negative() {
}
#[test]
+fn negative_overflow() {
+ assert!(syn::parse_str::<LitFloat>("-1.0e99f64").is_ok());
+ assert!(syn::parse_str::<LitFloat>("-1.0e999f64").is_err());
+}
+
+#[test]
fn suffix() {
fn get_suffix(token: &str) -> String {
let lit = syn::parse_str::<Lit>(token).unwrap();
@@ -247,3 +260,12 @@ fn test_deep_group_empty() {
snapshot!(tokens as Lit, @r#""hi""# );
}
+
+#[test]
+fn test_error() {
+ let err = syn::parse_str::<LitStr>("...").unwrap_err();
+ assert_eq!("expected string literal", err.to_string());
+
+ let err = syn::parse_str::<LitStr>("5").unwrap_err();
+ assert_eq!("expected string literal", err.to_string());
+}