-
-
Couldn't load subscription status.
- Fork 44
Open
Description
Here's some test code:
use kdl::KdlDocument;
use miette::Context;
#[test]
fn long_int_v1() -> miette::Result<()> {
let mut str = String::from("- ");
for i in 1..1000 {
str += "1";
KdlDocument::parse_v1(&str).with_context(|| format!("failed with {i} digits"))?;
}
Ok(())
}
#[test]
fn long_int_v2() -> miette::Result<()> {
let mut str = String::from("- ");
for i in 1..1000 {
str += "1";
KdlDocument::parse_v2(&str).with_context(|| format!("failed with {i} digits"))?;
}
Ok(())
}
#[test]
fn long_float_v1() -> miette::Result<()> {
let mut str = String::from("- 0.");
for i in 1..1000 {
str += "1";
KdlDocument::parse_v1(&str).with_context(|| format!("failed with {i} digits"))?;
}
Ok(())
}
#[test]
fn long_float_v2() -> miette::Result<()> {
let mut str = String::from("- 0.");
for i in 1..1000 {
str += "1";
KdlDocument::parse_v2(&str).with_context(|| format!("failed with {i} digits"))?;
}
Ok(())
}and its output:
---- long_int_v1 stdout ----
Error: × failed with 20 digits
╰─▶ Failed to parse KDL document
Error:
× Expected valid node terminator.
╭────
1 │ - 11111111111111111111
· ─┬
· ╰── parsed node
╰────
help: Nodes can only be terminated by `;` or a valid line ending.
---- long_int_v2 stdout ----
Error: × failed with 40 digits
╰─▶ Failed to parse KDL document
Error:
× Expected end of document
╭────
1 │ - 1111111111111111111111111111111111111111
· ┬
· ╰── not EOF
╰────
Error:
× Found invalid node name
╭────
1 │ - 1111111111111111111111111111111111111111
· ───────────────────┬───────────────────
· ╰── not node name
╰────
help: This can be any string type, including a quoted, raw, or multiline string, as well as a plain identifier string.
---- long_float_v1 stdout ----
Error: × failed with 20 digits
╰─▶ Failed to parse KDL document
Error:
× number too large to fit in target type
╭────
1 │ - 0.11111111111111111111
· ─┬
· ╰── invalid float
╰────
help: Floating point numbers must be base 10, and have numbers after the decimal point.
---- long_float_v2 stdout ----
Error: × failed with 40 digits
╰─▶ Failed to parse KDL document
Error:
× Non-digit character found after the '.' of a float
╭────
1 │ - 0.1111111111111111111111111111111111111111
· ─────────────────────┬────────────────────
· ╰── not float
╰────Just 20 or 40 digits, and the document fails to parse, depending on if it's parsing in v1 or v2 mode. This is very odd to me. I would expect all of these to be parsed into the closest floating point value (and for very large values, i'd expect to be rounded to infinity), while keeping the literal value_repr in the resulting document.
I find the long_float_v2 error particularly amusing. It's lying.
Metadata
Metadata
Assignees
Labels
No labels