Fix last of the tests with numeric literals
@@ -2,6 +2,7 @@ use super::{CompileResult, LiteralToken, Locatable, Token};
use crate::data::hir::LiteralValue;
use crate::data::lex::test::{cpp, cpp_no_newline};
use crate::intern::InternedStr;
+use shared_str::RcStr;
type LexType = CompileResult<Locatable<Token>>;
@@ -56,12 +57,20 @@ fn match_char(lexed: Option<LexType>, expected: u8) -> bool {
}
}
+fn match_data_eq(lexed: &Token, other: &Token) -> bool {
+ match (lexed, other) {
+ (Token::Literal(lexed), Token::Literal(other)) => {
+ lexed.clone().parse() == other.clone().parse()
+ }
+ (lexed, other) => lexed == other,
+ }
+}
fn match_all(lexed: &[LexType], expected: &[Token]) -> bool {
lexed
.iter()
.zip(expected)
.all(|(actual, expected)| match actual {
- Ok(token) => token.data == *expected,
+ Ok(token) => match_data_eq(&token.data, expected),
_ => false,
})
}
@@ -162,18 +171,26 @@ fn test_float_literals() {
for i in 0..10 {
assert_float(&format!("1{}e{}", "0".repeat(i), 10 - i), 1e10);
}
+ fn rcstr<S: ToString>(x: S) -> RcStr {
+ RcStr::from(x.to_string())
+ }
assert!(match_all(
&lex_all("-1"),
- &[Token::Minus, LiteralToken::Int(1).into()]
+ &[Token::Minus, LiteralToken::Int(rcstr(1)).into()]
));
assert!(match_all(
&lex_all("-1e10"),
- &[Token::Minus, LiteralToken::Float(10_000_000_000.0).into()]
+ &[
+ Token::Minus,
+ LiteralToken::Float(rcstr(10_000_000_000.0)).into()
+ ]
));
- assert!(match_data(lex("9223372036854775807u"), |lexed| lexed
- == Ok(
- &LiteralToken::UnsignedInt(9_223_372_036_854_775_807u64).into()
- )));
+ assert!(match_data(lex("9223372036854775807u"), |lexed| {
+ match_data_eq(
+ lexed.unwrap(),
+ &LiteralToken::UnsignedInt(rcstr(9_223_372_036_854_775_807u64)).into(),
+ )
+ }));
assert_float("0x.ep0", 0.875);
assert_float("0x.ep-0l", 0.875);
assert_float("0xe.p-4f", 0.875);
