Skip to content

Commit

Permalink
Add custom type to param tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dusty-phillips committed Sep 15, 2024
1 parent 6927d14 commit 0c362e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 13 additions & 1 deletion test/typecheck/function_params_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import glance
import gleam/option
import gleeunit/should
import glimpse/error
import glimpse/internal/typecheck/environment
import typecheck/helpers

pub fn int_param_test() {
Expand Down Expand Up @@ -36,7 +37,18 @@ pub fn string_param_test() {
|> should.equal(option.Some(glance.NamedType("String", option.None, [])))
}

pub fn incorrect_param_return_fails() {
pub fn incorrect_param_return_fails_test() {
helpers.error_function_typecheck("fn foo(a: String) -> Nil { a }")
|> should.equal(error.InvalidReturnType("foo", "String", "Nil"))
}

pub fn custom_type_param_test() {
let function_out =
helpers.ok_function_env_typecheck(
environment.new() |> environment.add_custom_type("MyType"),
"fn foo(my_type: MyType) -> MyType { my_type }",
)

function_out.return
|> should.equal(option.Some(glance.NamedType("MyType", option.None, [])))
}
11 changes: 9 additions & 2 deletions test/typecheck/helpers.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ pub fn glance_function(definition: String) -> glance.Function {
definition.definition
}

pub fn ok_function_typecheck(definition: String) -> glance.Function {
pub fn ok_function_env_typecheck(
env: Environment,
definition: String,
) -> glance.Function {
let function = glance_function(definition)
typecheck.function(environment.new(), function)
typecheck.function(env, function)
|> should.be_ok
}

pub fn ok_function_typecheck(definition: String) -> glance.Function {
ok_function_env_typecheck(environment.new(), definition)
}

pub fn error_function_typecheck(definition: String) -> error.TypeCheckError {
let function = glance_function(definition)
typecheck.function(environment.new(), function)
Expand Down

0 comments on commit 0c362e8

Please sign in to comment.