diff --git a/examples/negative-after-op.ilo b/examples/negative-after-op.ilo new file mode 100644 index 00000000..58b38be0 --- /dev/null +++ b/examples/negative-after-op.ilo @@ -0,0 +1,24 @@ +-- Negative literals immediately after a binary operator. The lexer eats +-- `-0.05` as a single Number token, but a negative literal is itself a valid +-- second operand to a binary op, so `n;n;+a -3 +modn n:n>n;mod n -2 + +-- run: below -0.1 +-- out: 1 +-- run: below 0.1 +-- out: 0 +-- run: below -0.05 +-- out: 0 +-- run: shift 10 +-- out: 7 +-- run: shift -5 +-- out: -8 +-- run: modn 7 +-- out: 1 +-- run: modn 10 +-- out: 0 diff --git a/tests/regression_negative_literal_after_op.rs b/tests/regression_negative_literal_after_op.rs new file mode 100644 index 00000000..02621971 --- /dev/null +++ b/tests/regression_negative_literal_after_op.rs @@ -0,0 +1,131 @@ +// Regression tests for negative numeric literals appearing immediately after +// a binary operator or in a call/prefix-binop argument slot. +// +// The lexer eats a leading `-` as part of the Number token, so ` Command { + Command::new(env!("CARGO_BIN_EXE_ilo")) +} + +fn run(engine: &str, src: &str, args: &[&str]) -> String { + let mut cmd = ilo(); + cmd.arg(src).arg(engine); + for a in args { + cmd.arg(a); + } + let out = cmd.output().expect("failed to run ilo"); + assert!( + out.status.success(), + "ilo {engine} failed for `{src}` args={args:?}: stderr={}", + String::from_utf8_lossy(&out.stderr) + ); + String::from_utf8_lossy(&out.stdout).trim().to_string() +} + +const BELOW: &str = "f r:n>n;