diff options
author | Lukas Wirth <[email protected]> | 2020-11-28 15:22:28 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-11-28 15:22:28 +0000 |
commit | 49fbfffb48a5926cd4a01ca6b23f656a84fec830 (patch) | |
tree | 9f74fa205723cac42485c313b9026d2e25377a72 /crates | |
parent | 931493e949ce369775bccfcca24878c73e1509c2 (diff) |
Add ast::*Number::suffix tests unit tests
Diffstat (limited to 'crates')
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 754ca8c62..0c178039e 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -612,3 +612,40 @@ impl Radix { | |||
612 | } | 612 | } |
613 | } | 613 | } |
614 | } | 614 | } |
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 | } | ||