Skip to content

Commit

Permalink
test: added more tests to ctx (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hebertcisco authored Jul 1, 2024
1 parent ef8c026 commit cd905fd
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/unit_tests/ctx_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,57 @@ pub fn drill_deep_test() {
|> should.be_ok
|> should.equal(ctx.Str(expected_string))
}

pub fn get_property_success_test() {
let ctx =
ctx.Dict([
ctx.Prop("name", ctx.Str("Alice")),
ctx.Prop("age", ctx.Int(30)),
ctx.Prop("height", ctx.Float(5.9)),
])
ctx_utils.get_property(0, ["name"], ctx)
|> should.be_ok
|> should.equal("Alice")

ctx_utils.get_property(0, ["age"], ctx)
|> should.be_ok
|> should.equal("30")

ctx_utils.get_property(0, ["height"], ctx)
|> should.be_ok
|> should.equal("5.9")
}

pub fn get_property_error_test() {
let ctx = ctx.Dict([ctx.Prop("name", ctx.Str("Alice"))])
ctx_utils.get_property(0, ["unknown"], ctx)
|> should.be_error

ctx_utils.get_property(0, ["name", "subprop"], ctx)
|> should.be_error
}

pub fn get_list_success_test() {
let ctx =
ctx.Dict([ctx.Prop("items", ctx.List([ctx.Str("item1"), ctx.Str("item2")]))])
ctx_utils.get_list(0, ["items"], ctx)
|> should.be_ok
}

pub fn get_list_error_test() {
let ctx = ctx.Dict([ctx.Prop("name", ctx.Str("Alice"))])
ctx_utils.get_list(0, ["name"], ctx)
|> should.be_error
}

pub fn get_bool_success_test() {
let ctx = ctx.Dict([ctx.Prop("active", ctx.Bool(True))])
ctx_utils.get_bool(0, ["active"], ctx)
|> should.be_ok
}

pub fn get_bool_error_test() {
let ctx = ctx.Dict([ctx.Prop("name", ctx.Str("Alice"))])
ctx_utils.get_bool(0, ["name"], ctx)
|> should.be_error
}

0 comments on commit cd905fd

Please sign in to comment.