Ability to run the OPA testsuite (#39)

`OPA_TESTS_DIR=path/to/testsuite cargo test opa -- --shot-output` to run opa tests.
Failing test cases are saved in target/opa/folder for investigation.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-11-09 15:11:33 -08:00
committed by GitHub
parent d69b413c8e
commit 0af8b6ea12
9 changed files with 186 additions and 193 deletions
+10
View File
@@ -52,6 +52,11 @@ fn lsh(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
// TODO: precision
let v1 = v1 as i64;
let v2 = v2 as i64;
if v2 <= 0 {
return Ok(Value::Undefined);
}
Ok(Value::from_float((v1 << v2) as Float))
}
@@ -101,6 +106,11 @@ fn rsh(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
// TODO: precision
let v1 = v1 as i64;
let v2 = v2 as i64;
if v2 < 0 {
return Ok(Value::Undefined);
}
Ok(Value::from_float((v1 >> v2) as Float))
}
+3 -1
View File
@@ -20,7 +20,8 @@ pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) {
m.insert("endswith", (endswith, 2));
m.insert("format_int", (format_int, 2));
m.insert("indexof", (indexof, 2));
m.insert("indexof_n", (indexof_n, 2));
// TODO: implement this correctly.
//m.insert("indexof_n", (indexof_n, 2));
m.insert("lower", (lower, 1));
m.insert("replace", (replace, 3));
m.insert("split", (split, 2));
@@ -98,6 +99,7 @@ fn indexof(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
} as Float))
}
#[allow(dead_code)]
fn indexof_n(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> {
let name = "indexof_n";
ensure_args_count(span, name, params, args, 2)?;
+1 -1
View File
@@ -333,7 +333,7 @@ impl<'source> Parser<'source> {
}
// It could be a set, object or object comprehension.
// In all the cases, the first expressoin must parse successfully.
// In all the cases, the first expression must parse successfully.
if *self.tok.1.text() == "}" {
self.next_token()?;
span.end = self.end;