Skip to content

Commit

Permalink
Include wild card test
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Sep 30, 2024
1 parent d099f6b commit 906b5ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
10 changes: 7 additions & 3 deletions golem-rib/src/interpreter/rib_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ mod interpreter_tests {
use crate::interpreter::rib_interpreter::interpreter_tests::internal;
use crate::{compiler, Expr};
use golem_wasm_ast::analysis::{
AnalysedType, TypeList, TypeOption, TypeResult, TypeStr, TypeU64,
AnalysedType, TypeList, TypeOption, TypeResult, TypeStr, TypeU64, TypeU8,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -1920,8 +1920,10 @@ mod interpreter_tests {
let err_record_result = function-err-record(input);
let h = match err_record_result { ok(success_rec) => success_rec.b[0], err(failure_rec) => "${failure_rec.d}" };
let i = match err_record_result { ok(_) => 1u8, err(_) => 0u8 };
let j = match ok_record_result { ok(_) => 1u8, err(_) => 0u8 };
{ a : a, b : b, c: c, d: d, e: e, f: f, g: g, h: h}
{ a : a, b : b, c: c, d: d, e: e, f: f, g: g, h: h, i: i, j: j}
"#;

let expr = Expr::from_text(expr).unwrap();
Expand Down Expand Up @@ -2108,8 +2110,10 @@ mod interpreter_tests {
("f", AnalysedType::Str(TypeStr)),
("g", AnalysedType::Str(TypeStr)),
("h", AnalysedType::Str(TypeStr)),
("i", AnalysedType::U8(TypeU8)),
("j", AnalysedType::U8(TypeU8)),
]),
r#" { a : "bId", b : "bTitle2", c : "bStreet", d: 200, e: "success", f: "failure", g: "bar", h : "fuuz" }"#,
r#" { a : "bId", b : "bTitle2", c : "bStreet", d: 200, e: "success", f: "failure", g: "bar", h : "fuuz", i: 0, j: 1 }"#,
);
assert_eq!(result.get_val().unwrap(), expected_result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl WorkerNameCompiled {
worker_name: &Expr,
exports: &Vec<AnalysedExport>,
) -> Result<Self, String> {
let worker_name_compiled = rib::compile(worker_name, exports)?;
let worker_name_compiled = rib::compile_with_limited_globals(worker_name, exports, Some(vec!["request".to_string()]))?;

Ok(WorkerNameCompiled {
worker_name: worker_name.clone(),
Expand All @@ -76,7 +76,7 @@ impl IdempotencyKeyCompiled {
idempotency_key: &Expr,
exports: &Vec<AnalysedExport>,
) -> Result<Self, String> {
let idempotency_key_compiled = rib::compile(idempotency_key, exports)?;
let idempotency_key_compiled = rib::compile_with_limited_globals(idempotency_key, exports, Some(vec!["request".to_string()]))?;

Ok(IdempotencyKeyCompiled {
idempotency_key: idempotency_key.clone(),
Expand All @@ -98,7 +98,7 @@ impl ResponseMappingCompiled {
response_mapping: &ResponseMapping,
exports: &Vec<AnalysedExport>,
) -> Result<Self, String> {
let response_compiled = rib::compile(&response_mapping.0, exports)?;
let response_compiled = rib::compile_with_limited_globals(&response_mapping.0, exports, Some(vec!["request".to_string()]))?;

Ok(ResponseMappingCompiled {
response_rib_expr: response_mapping.0.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,27 +627,6 @@ mod tests {

assert!(error_message.contains("Types do not match. Inferred to be both Str and Bool"));
}

#[tokio::test]
async fn test_evaluation_with_pattern_match_with_err_construction() {
let noop_executor = DefaultEvaluator::noop();

let expr = rib::from_string(
"${let xyz: u64 = 2; match err(\"afsal\") { ok(_) => ok(\"1\"), err(msg) => err(xyz) }}",
)
.unwrap();

let result = noop_executor
.evaluate_pure_expr(&expr)
.await
.map(|v| v.get_val().unwrap());

let expected =
create_error_result(TypeAnnotatedValue::U64(2), Some(AnalysedType::Str(TypeStr)))
.unwrap();

assert_eq!(result, Ok(expected));
}

#[tokio::test]
async fn test_evaluation_with_pattern_match_with_wild_card() {
Expand Down

0 comments on commit 906b5ef

Please sign in to comment.