Writing tests for functions with optional return types
We have learned that test functions must not specify a return type. But we have also learned that test function properties can be marked with the symbol ?
when the test logic deals with functions with optional return types. To demonstrate this, consider the following greet
function:
fn greet(name string) ?string { if name != '' { return 'Hello $name!' } return error('name not provided') }
The greet
function returns a ?string
type. This means greet
will return a string value only when a non-empty name
is provided to it as an input argument. If the name
is an empty string, it will return an error with the message name not provided
. The following code shows the test case when the name
parameter is provided with a non-empty string:
fn test_greet_given_a_name...