Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added more tests to ctx #1

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}