diff --git a/src/runestone.jl b/src/runestone.jl index 917849b..3dfef97 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -100,7 +100,7 @@ function format_float_literals(ctx::Context, node::Node) (?:(?:[1-9]\d*)|0) # Non-zero followed by any digit, or just a single zero \. # Decimal point (?:(?:\d*[1-9])|0) # Any digit with a final nonzero, or just a single zero - (?:[ef][+-]?[1-9]\d*)? + (?:[ef][+-]?(?:[1-9]\d*|0))? $ """x if occursin(r, str) diff --git a/test/runtests.jl b/test/runtests.jl index da2f74d..c7ab16f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -116,16 +116,15 @@ end ["1.0", "1.", "01.", "001.", "001.00", "1.00"] => "1.0", ["0.1", ".1", ".10", ".100", "00.100", "0.10"] => "0.1", ["1.1", "01.1", "1.10", "1.100", "001.100", "01.10"] => "1.1", - ["1e3", "01e3", "01.e3", "1.e3", "1.000e3", "01.00e3"] => "1.0e3", - ["1e+3", "01e+3", "01.e+3", "1.e+3", "1.000e+3", "01.00e+3"] => "1.0e+3", - ["1e-3", "01e-3", "01.e-3", "1.e-3", "1.000e-3", "01.00e-3"] => "1.0e-3", - ["1E3", "01E3", "01.E3", "1.E3", "1.000E3", "01.00E3"] => "1.0e3", - ["1E+3", "01E+3", "01.E+3", "1.E+3", "1.000E+3", "01.00E+3"] => "1.0e+3", - ["1E-3", "01E-3", "01.E-3", "1.E-3", "1.000E-3", "01.00E-3"] => "1.0e-3", - ["1f3", "01f3", "01.f3", "1.f3", "1.000f3", "01.00f3"] => "1.0f3", - ["1f+3", "01f+3", "01.f+3", "1.f+3", "1.000f+3", "01.00f+3"] => "1.0f+3", - ["1f-3", "01f-3", "01.f-3", "1.f-3", "1.000f-3", "01.00f-3"] => "1.0f-3", ] + for a in ("e", "E", "f"), b in ("", "+", "-"), c in ("3", "0", "12") + abc = a * b * c + abc′ = replace(abc, "E" => "e") + push!( + test_cases, + ["1$(abc)", "01$(abc)", "01.$(abc)", "1.$(abc)", "1.000$(abc)", "01.00$(abc)"] => "1.0$(abc′)", + ) + end mod = Module() for prefix in ("", "-", "+") for (as, b) in test_cases