You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
940 B

struct User {
username: string,
first_name: string,
last_name: string
}
// Creates a stub user
fn user_stub() {
let stub = new User {
username: "Foo Bar",
first_name: "Foo",
last_name: "Bar"
}
assert(stub.first_name)
assert(stub.last_name)
return stub
}
fn test_initialization() {
let foo = new User {
username: "Foo Bar",
first_name: "Bar",
last_name: "Bar"
}
assert(foo)
}
fn test_simple_field_access() {
let user: User = user_stub()
user.username = "Foo Bar"
}
fn test_field_access_in_function_call() {
let user: User = user_stub()
user.username = "Bar"
assert(user.username == "Bar")
}
fn test_field_access_on_function() {
assert(user_stub().first_name == "Foo")
}
fn main() {
test_initialization()
test_simple_field_access()
test_field_access_in_function_call()
test_field_access_on_function()
}