Browse Source

Fix floating point regex with zero exponent

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
8737a9238d
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 2
      src/runestone.jl
  2. 17
      test/runtests.jl

2
src/runestone.jl

@ -100,7 +100,7 @@ function format_float_literals(ctx::Context, node::Node) @@ -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)

17
test/runtests.jl

@ -116,16 +116,15 @@ end @@ -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

Loading…
Cancel
Save