Skip to content

Commit

Permalink
Merge pull request #327 from dtolnay/testliteral
Browse files Browse the repository at this point in the history
Add more tests of Literal constructors
  • Loading branch information
dtolnay committed May 6, 2022
2 parents 8e794fc + 8725ff4 commit 4a3502c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test.rs
Expand Up @@ -106,16 +106,60 @@ fn literal_raw_string() {
"r\"\r\n\"".parse::<TokenStream>().unwrap();
}

#[test]
fn literal_byte_string() {
assert_eq!(Literal::byte_string(b"").to_string(), "b\"\"");
assert_eq!(
Literal::byte_string(b"\0\t\n\r\"\\2\x10").to_string(),
"b\"\\0\\t\\n\\r\\\"\\\\2\\x10\"",
);
}

#[test]
fn literal_character() {
assert_eq!(Literal::character('x').to_string(), "'x'");
assert_eq!(Literal::character('\'').to_string(), "'\\''");
assert_eq!(Literal::character('"').to_string(), "'\"'");
}

#[test]
fn literal_integer() {
assert_eq!(Literal::u8_suffixed(10).to_string(), "10u8");
assert_eq!(Literal::u16_suffixed(10).to_string(), "10u16");
assert_eq!(Literal::u32_suffixed(10).to_string(), "10u32");
assert_eq!(Literal::u64_suffixed(10).to_string(), "10u64");
assert_eq!(Literal::u128_suffixed(10).to_string(), "10u128");
assert_eq!(Literal::usize_suffixed(10).to_string(), "10usize");

assert_eq!(Literal::i8_suffixed(10).to_string(), "10i8");
assert_eq!(Literal::i16_suffixed(10).to_string(), "10i16");
assert_eq!(Literal::i32_suffixed(10).to_string(), "10i32");
assert_eq!(Literal::i64_suffixed(10).to_string(), "10i64");
assert_eq!(Literal::i128_suffixed(10).to_string(), "10i128");
assert_eq!(Literal::isize_suffixed(10).to_string(), "10isize");

assert_eq!(Literal::u8_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::u16_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::u32_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::u64_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::u128_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::usize_unsuffixed(10).to_string(), "10");

assert_eq!(Literal::i8_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::i16_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::i32_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::i64_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::i128_unsuffixed(10).to_string(), "10");
assert_eq!(Literal::isize_unsuffixed(10).to_string(), "10");
}

#[test]
fn literal_float() {
assert_eq!(Literal::f32_suffixed(10.0).to_string(), "10f32");
assert_eq!(Literal::f64_suffixed(10.0).to_string(), "10f64");

assert_eq!(Literal::f32_unsuffixed(10.0).to_string(), "10.0");
assert_eq!(Literal::f64_unsuffixed(10.0).to_string(), "10.0");
}

#[test]
Expand Down

0 comments on commit 4a3502c

Please sign in to comment.