Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/token_ext.rs')
-rw-r--r--crates/syntax/src/ast/token_ext.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 4b6dc236b5..5f2e7231d9 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -321,7 +321,7 @@ impl ast::IntNumber {
}
}
-impl ast::FloatNumber {
+impl ast::FloatNumberPart {
pub fn suffix(&self) -> Option<&str> {
let text = self.text();
let mut indices = text.char_indices();
@@ -355,14 +355,24 @@ impl Radix {
#[cfg(test)]
mod tests {
- use crate::ast::{self, make, FloatNumber, IntNumber};
+ use crate::ast::{self, make};
fn check_float_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
- assert_eq!(FloatNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into());
+ let suffix = match make::literal(lit).kind() {
+ ast::LiteralKind::FloatNumber(f) => f.suffix(),
+ // `1f32` lexes as an INT_NUMBER
+ ast::LiteralKind::IntNumber(i) => i.suffix().map(|s| s.to_string()),
+ e => unreachable!("{e:?}"),
+ };
+ assert_eq!(suffix.as_deref(), expected.into());
}
fn check_int_suffix<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
- assert_eq!(IntNumber { syntax: make::tokens::literal(lit) }.suffix(), expected.into());
+ let i = match make::literal(lit).kind() {
+ ast::LiteralKind::IntNumber(i) => i,
+ _ => unreachable!(),
+ };
+ assert_eq!(i.suffix(), expected.into());
}
#[test]
@@ -390,12 +400,11 @@ mod tests {
}
fn check_string_value<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
- assert_eq!(
- ast::String { syntax: make::tokens::literal(&format!("\"{}\"", lit)) }
- .value()
- .as_deref(),
- expected.into()
- );
+ let s = match make::literal(&format!("\"{}\"", lit)).kind() {
+ ast::LiteralKind::String(s) => s,
+ _ => unreachable!(),
+ };
+ assert_eq!(s.value().as_deref(), expected.into());
}
#[test]