Skip to content

Commit

Permalink
hardening with more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbittich committed Aug 23, 2024
1 parent 41d5888 commit 9aedc69
Showing 1 changed file with 184 additions and 0 deletions.
184 changes: 184 additions & 0 deletions adana-script/src/tests/struc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,187 @@ fn test_struc_access_key10() {
Primitive::String("whatever9".to_string())
);
}
#[test]
fn test_struc_access_key11() {
let mut ctx = BTreeMap::new();
let expr = r#"
settings = struct {
static: struct {},
middlewares: [
struct {
path: "/hello/:name",
handler: (req) => {
println(req)
return struct {
status: 200,
body: struct { response: """hello ${req.params.name}!""" },
headers: struct { "Content-Type": "application/json"}
}
},
method: "GET"
},
struct {
path: "/",
handler: (req) => {
println(req)
return "hello bro!"
},
method: "GET"
}
]
}
settings.middlewares[0].handler(struct {params: struct {name: "nordine"}})
"#;
let r = compute(expr, &mut ctx, "N/A").unwrap();
assert_eq!(
r,
Primitive::Struct(BTreeMap::from([
(
"body".to_string(),
Primitive::Struct(BTreeMap::from([(
"response".to_string(),
Primitive::String("hello nordine!".to_string())
),]))
),
("status".to_string(), Primitive::U8(200)),
(
"headers".to_string(),
Primitive::Struct(BTreeMap::from([(
"Content-Type".to_string(),
Primitive::String("application/json".to_string())
)]))
)
]))
);
}

#[test]
fn test_struc_access_key12() {
let mut ctx = BTreeMap::new();
let expr = r#"
handler = (req) => {
println(req)
return struct {
status: 200,
body: struct { response: """hello ${req.params.name}!""" },
headers: struct { "Content-Type": "application/json"}
}
}
handler(struct {params: struct {name: "nordine"}})
"#;
let r = compute(expr, &mut ctx, "N/A").unwrap();
assert_eq!(
r,
Primitive::Struct(BTreeMap::from([
(
"body".to_string(),
Primitive::Struct(BTreeMap::from([(
"response".to_string(),
Primitive::String("hello nordine!".to_string())
),]))
),
("status".to_string(), Primitive::U8(200)),
(
"headers".to_string(),
Primitive::Struct(BTreeMap::from([(
"Content-Type".to_string(),
Primitive::String("application/json".to_string())
)]))
)
]))
);
}

#[test]
fn test_struc_access_key13() {
let mut ctx = BTreeMap::new();
let expr = r#"
settings = struct {
static: struct {},
middlewares: [
struct {
path: "/hello/:name",
handler: (req) => {
println(req)
res= struct {
status: 200,
body: struct { response: """hello ${req.params.name}!""" },
headers: struct { "Content-Type": "application/json"}
}
return res
},
method: "GET"
},
struct {
path: "/",
handler: (req) => {
println(req)
return "hello bro!"
},
method: "GET"
}
]
}
settings.middlewares[0].handler(struct {params: struct {name: "nordine"}})
"#;
let r = compute(expr, &mut ctx, "N/A").unwrap();
assert_eq!(
r,
Primitive::Struct(BTreeMap::from([
(
"body".to_string(),
Primitive::Struct(BTreeMap::from([(
"response".to_string(),
Primitive::String("hello nordine!".to_string())
),]))
),
("status".to_string(), Primitive::U8(200)),
(
"headers".to_string(),
Primitive::Struct(BTreeMap::from([(
"Content-Type".to_string(),
Primitive::String("application/json".to_string())
)]))
)
]))
);
}
#[test]
fn test_struc_access_key14() {
let mut ctx = BTreeMap::new();
let expr = r#"
handler = (req) => {
println(req)
res= struct {
status: 200,
body: struct { response: """hello ${req.params.name}!""" },
headers: struct { "Content-Type": "application/json"}
}
return res
}
handler(struct {params: struct {name: "nordine"}})
"#;
let r = compute(expr, &mut ctx, "N/A").unwrap();
assert_eq!(
r,
Primitive::Struct(BTreeMap::from([
(
"body".to_string(),
Primitive::Struct(BTreeMap::from([(
"response".to_string(),
Primitive::String("hello nordine!".to_string())
),]))
),
("status".to_string(), Primitive::U8(200)),
(
"headers".to_string(),
Primitive::Struct(BTreeMap::from([(
"Content-Type".to_string(),
Primitive::String("application/json".to_string())
)]))
)
]))
);
}

0 comments on commit 9aedc69

Please sign in to comment.