Fix decimal parsing (#4838)

This commit is contained in:
Mees Delzenne 2024-09-19 16:14:32 +02:00 committed by GitHub
parent 99db7f2a82
commit 491b549f1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View file

@ -82,9 +82,16 @@ pub fn numeric(lexer: &mut Lexer, start: Token) -> Result<Numeric, SyntaxError>
match start.kind {
t!("-") | t!("+") => number(lexer, start).map(Numeric::Number),
TokenKind::Digits => match lexer.reader.peek() {
Some(b'n' | b'm' | b's' | b'h' | b'y' | b'd' | b'w') => {
Some(b'n' | b'm' | b's' | b'h' | b'y' | b'w') => {
duration(lexer, start).map(Numeric::Duration)
}
Some(b'd') => {
if lexer.reader.peek1() == Some(b'e') {
number(lexer, start).map(Numeric::Number)
} else {
duration(lexer, start).map(Numeric::Duration)
}
}
Some(x) if !x.is_ascii() => duration(lexer, start).map(Numeric::Duration),
_ => number(lexer, start).map(Numeric::Number),
},

View file

@ -9,6 +9,11 @@ mod stmt;
mod streaming;
mod value;
#[test]
fn parse_large_test_file() {
test_parse!(parse_query, include_str!("../../../../test.surql")).unwrap();
}
#[test]
fn multiple_semicolons() {
let res = test_parse!(parse_query, r#";;"#).unwrap();

View file

@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use reblessive::Stack;
use rust_decimal::Decimal;
use crate::{
sql::{
@ -156,6 +157,12 @@ fn parse_i64() {
assert_eq!(res, Value::Number(Number::Int(i64::MAX)));
}
#[test]
fn parse_decimal() {
let res = test_parse!(parse_value_field, r#" 0dec "#).unwrap();
assert_eq!(res, Value::Number(Number::Decimal(Decimal::ZERO)));
}
#[test]
fn constant_lowercase() {
let out = test_parse!(parse_value_field, r#" math::pi "#).unwrap();