mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Wrap float literals in their own node
This commit is contained in:
parent
2d5d16f18c
commit
502c519e7d
13 changed files with 113 additions and 49 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue