Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(xpath): apply a single leading minus sign

Iainafc28fc39414
diff --git a/moli-xpath/src/parser.rs b/moli-xpath/src/parser.rs
index d4acd5040..d56d8f63e 100644
--- a/moli-xpath/src/parser.rs
+++ b/moli-xpath/src/parser.rs
@@ -138,7 +138,7 @@ where
result = self.parse_union_expression()?;
- if negations > 1 {
+ if negations > 0 {
if negations % 2 == 0 {
result = Expression::Function(CoreFunction::Number(Some(Box::new(result))))
} else {
@@ -829,4 +829,15 @@ mod tests {
Err(e) => panic!("Failed to parse '{}': {:?}", test_case, e),
}
}
+
+ #[test]
+ fn parse_single_unary_minus() {
+ let expected = Expression::Negate(Box::new(Expression::Literal(Literal::Decimal(1.5))));
+ match parse("-1.5", Some(DummyNamespaceResolver), true) {
+ Ok(result) => {
+ assert_eq!(result, expected, "{:?} was parsed incorrectly", "-1.5");
+ }
+ Err(e) => panic!("Failed to parse '{}': {:?}", "-1.5", e),
+ }
+ }
}