From dba2288a13c8a4575a71c59e694d702fde5eea2c Mon Sep 17 00:00:00 2001 From: femshima <49227365+femshima@users.noreply.github.com> Date: Sun, 14 Jun 2026 13:53:24 +0900 Subject: [PATCH] parse negative position --- crates/jlabel-question/src/parse_position.rs | 1 + crates/jlabel-question/src/position.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/jlabel-question/src/parse_position.rs b/crates/jlabel-question/src/parse_position.rs index cd4f5fc..cd67169 100644 --- a/crates/jlabel-question/src/parse_position.rs +++ b/crates/jlabel-question/src/parse_position.rs @@ -333,6 +333,7 @@ mod tests { assert_eq!(estimate_position("*_xx-*"), Ok((Undefined(E4), "xx"))); assert_eq!(estimate_position("*_xx@*"), Ok((Undefined(F4), "xx"))); assert_eq!(estimate_position("*_xx_*"), Ok((Undefined(G4), "xx"))); + assert_eq!(estimate_position("*/A:-1?+*"), Ok((SignedRange(A1), "-1?"))); } #[test] diff --git a/crates/jlabel-question/src/position.rs b/crates/jlabel-question/src/position.rs index 859af52..5bd67d9 100644 --- a/crates/jlabel-question/src/position.rs +++ b/crates/jlabel-question/src/position.rs @@ -125,8 +125,11 @@ fn range_i8>(s: S) -> Result, ParseError> { let d = s[..s.len() - 1] .parse::() .map_err(ParseError::FailWildcard)?; - debug_assert!(d >= 0); - d * 10..(d + 1) * 10 + if d >= 0 { + d * 10..(d + 1) * 10 + } else { + (d - 1) * 10 + 1..d * 10 + 1 + } } s => { let d = s.parse::().map_err(ParseError::FailLiteral)?; @@ -391,7 +394,7 @@ mod tests { assert_eq!(range_i8("-?"), Ok(-9..0)); assert_eq!(range_i8("-??"), Ok(-99..-9)); - // assert_eq!(range_i8("-1?"), Ok(-19..-9)); + assert_eq!(range_i8("-1?"), Ok(-19..-9)); } #[test]