Skip to content

Commit 49fbfff

Browse files
committed
Add ast::*Number::suffix tests unit tests
1 parent 931493e commit 49fbfff

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

crates/syntax/src/ast/token_ext.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,40 @@ impl Radix {
612612
}
613613
}
614614
}
615+
616+
#[cfg(test)]
617+
mod tests {
618+
use crate::ast::{make, FloatNumber, IntNumber};
619+
620+
fn check_float_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
621+
assert_eq!(FloatNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into());
622+
}
623+
624+
fn check_int_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
625+
assert_eq!(IntNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into());
626+
}
627+
628+
#[test]
629+
fn test_float_number_suffix() {
630+
check_float_suffix("123.0", None);
631+
check_float_suffix("123f32", "f32");
632+
check_float_suffix("123.0e", None);
633+
check_float_suffix("123.0e4", None);
634+
check_float_suffix("123.0ef32", "f32");
635+
check_float_suffix("123.0E4f32", "f32");
636+
check_float_suffix("1_2_3.0_f32", "f32");
637+
}
638+
639+
#[test]
640+
fn test_int_number_suffix() {
641+
check_int_suffix("123", None);
642+
check_int_suffix("123i32", "i32");
643+
check_int_suffix("1_0_1_l_o_l", "l_o_l");
644+
check_int_suffix("0b11", None);
645+
check_int_suffix("0o11", None);
646+
check_int_suffix("0xff", None);
647+
check_int_suffix("0b11u32", "u32");
648+
check_int_suffix("0o11u32", "u32");
649+
check_int_suffix("0xffu32", "u32");
650+
}
651+
}

0 commit comments

Comments
 (0)