From c1b7c25c0095ac2bd8acf06f6834c734a42b4470 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sat, 8 May 2021 17:36:26 -0400 Subject: [PATCH] fix(numbers): Fix parsing of non-integer and non-decimal numbers (#13) --- src/parser.rs | 2 +- tests/examples.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index bd9b922..d90a1f0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -259,11 +259,11 @@ fn raw_string(input: &str) -> IResult<&str, &str, KdlParseError<&str>> { /// `number := decimal | hex | octal | binary` fn number(input: &str) -> IResult<&str, KdlValue, KdlParseError<&str>> { alt(( - map(integer, KdlValue::Int), map(hexadecimal, KdlValue::Int), map(octal, KdlValue::Int), map(binary, KdlValue::Int), map(float, KdlValue::Float), + map(integer, KdlValue::Int), ))(input) } diff --git a/tests/examples.rs b/tests/examples.rs index 95be07e..a8a5a52 100644 --- a/tests/examples.rs +++ b/tests/examples.rs @@ -57,6 +57,31 @@ macro_rules! nodes { () => { vec![] } } +const NUMBERS: &str = r#" +hex 0x32; +float 0.5; +binary 0b0110; +octal 0o755; +bignum 1_000_000; +scientific 1.234e-10; +"#; + +#[test] +fn test_numbers() { + let doc = parse_document(NUMBERS); + assert_eq!( + doc, + Ok(nodes! { + hex 0x32; + float 0.5; + binary 0b0110; + octal 0o755; + bignum 1_000_000; + scientific 1.234e-10; + }) + ); +} + #[test] fn test_ci() { let doc = parse_document(include_str!("../examples/ci.kdl"));