mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Lock down ACI tests and more OPA test folders (#54)
Borrowed from rego-cpp Significantly (> 10 times) faster execution. $ cargo test -r --test aci aci/mount_device passed 9.597958ms aci/mount_overlay passed 10.159208ms aci/scratch_mount passed 8.598875ms aci/create_container passed 10.237292ms aci/shutdown_container passed 6.904084ms aci/scratch_unmount passed 6.530875ms aci/unmount_overlay passed 5.958875ms aci/unmount_device passed 5.657834ms aci/load_fragment passed 6.049917ms Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
639ba72c90
commit
bb0ca29753
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use crate::ast::{Expr, Ref};
|
||||
use crate::builtins::regex::regex_match;
|
||||
use crate::builtins::utils::{ensure_args_count, ensure_set};
|
||||
use crate::builtins::BuiltinFcn;
|
||||
use crate::lexer::Span;
|
||||
@@ -20,6 +21,7 @@ lazy_static! {
|
||||
m.insert("all", (all, 1));
|
||||
m.insert("any", (any, 1));
|
||||
m.insert("set_diff", (set_diff, 2));
|
||||
m.insert("re_match", (regex_match, 2));
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ pub mod deprecated;
|
||||
mod encoding;
|
||||
pub mod numbers;
|
||||
mod objects;
|
||||
mod regex;
|
||||
mod semver;
|
||||
pub mod sets;
|
||||
mod strings;
|
||||
@@ -45,7 +46,7 @@ lazy_static! {
|
||||
sets::register(&mut m);
|
||||
objects::register(&mut m);
|
||||
strings::register(&mut m);
|
||||
//regex::register(&mut m);
|
||||
regex::register(&mut m);
|
||||
//glob::register(&mut m);
|
||||
bitwise::register(&mut m);
|
||||
conversions::register(&mut m);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use crate::ast::{Expr, Ref};
|
||||
use crate::builtins;
|
||||
use crate::builtins::utils::{ensure_args_count, ensure_string};
|
||||
use crate::lexer::Span;
|
||||
use crate::value::Value;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use regex::Regex;
|
||||
|
||||
pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) {
|
||||
m.insert("regex.is_valid", (is_valid, 1));
|
||||
m.insert("regex.match", (regex_match, 2));
|
||||
m.insert("regex.split", (regex_split, 2));
|
||||
}
|
||||
|
||||
fn is_valid(span: &Span, params: &[Ref<Expr>], args: &[Value]) -> Result<Value> {
|
||||
let name = "regex.is_valid";
|
||||
ensure_args_count(span, name, params, args, 1)?;
|
||||
Ok(ensure_string(name, ¶ms[0], &args[0])
|
||||
.map_or(Value::Bool(false), |p| Value::Bool(Regex::new(&p).is_ok())))
|
||||
}
|
||||
|
||||
pub fn regex_match(span: &Span, params: &[Ref<Expr>], args: &[Value]) -> Result<Value> {
|
||||
let name = "regex.match";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
let pattern = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
let value = ensure_string(name, ¶ms[1], &args[1])?;
|
||||
|
||||
let pattern = Regex::new(&pattern).or_else(|_| bail!(span.error("invalid regex")))?;
|
||||
Ok(Value::Bool(pattern.is_match(&value)))
|
||||
}
|
||||
|
||||
pub fn regex_split(span: &Span, params: &[Ref<Expr>], args: &[Value]) -> Result<Value> {
|
||||
let name = "regex.split";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
let pattern = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
let value = ensure_string(name, ¶ms[1], &args[1])?;
|
||||
|
||||
let pattern = Regex::new(&pattern).or_else(|_| bail!(span.error("invalid regex")))?;
|
||||
Ok(Value::from_array(
|
||||
pattern
|
||||
.split(&value)
|
||||
.map(|s| Value::String(s.into()))
|
||||
.collect::<Vec<Value>>(),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user