-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9333aa
commit 0133de5
Showing
6 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
test "If clause" { | ||
if true { | ||
assert(true) | ||
} else { | ||
assert(false) | ||
} | ||
} | ||
|
||
test "If expression" { | ||
let some = if 6 == 6 { "Something" } | ||
|
||
// TODO: Auto-unwrap optionals in comparisons to make this work | ||
// assert some == "Something" | ||
|
||
let nothing = if 6 == 7 { "Something" } | ||
|
||
// TODO: Introduce none keyword | ||
// assert nothing == none | ||
} | ||
|
||
test "If-Else expression" { | ||
let result = if 6 == 7 { "Correct" } else { "Wrong" } | ||
assert result == "Wrong" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
test "Logical AND" { | ||
let a = true | ||
let b = false | ||
|
||
assert(a and b == false) | ||
|
||
let a = true | ||
let b = true | ||
|
||
assert(a and b) | ||
} | ||
|
||
test "Logical OR" { | ||
let a = true | ||
let b = false | ||
|
||
assert(a or b) | ||
|
||
let a = false | ||
let b = false | ||
|
||
assert(a or b == false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
fn greet(name: String) -> String { | ||
"Hello, {name}!" | ||
} | ||
|
||
test "String interpolation" { | ||
assert "Hello, World!" == greet("World") | ||
assert "Hello, Galvan!" == greet("Galvan") | ||
} | ||
|
||
// TODO: String interpolation should be able to take any expression | ||
test "Interpolation with Integers" { | ||
let x = 3 | ||
let y = 7 | ||
let sum = x + y | ||
assert "3 + 7 = 10" == "{x} + {y} = {sum}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
type Dog { | ||
name: String | ||
age: Int | ||
} | ||
|
||
test "Create struct" { | ||
let dog = Dog(name: "Rex", age: 3) | ||
assert dog.name == "Rex" | ||
assert dog.age == 3 | ||
} | ||
|
||
fn shout_name(self: Dog) -> String { | ||
self.name.to_uppercase() | ||
} | ||
|
||
test "Call method" { | ||
let dog = Dog(name: "Rex", age: 3) | ||
assert dog.shout_name() == "REX" | ||
} | ||
|
||
fn happy_birthday(mut self: Dog) { | ||
self.age = self.age + 1 | ||
} | ||
|
||
test "Call method with mutation" { | ||
mut dog = Dog(name: "Rex", age: 3) | ||
dog.happy_birthday() | ||
assert dog.age == 4 | ||
} | ||
|
||
test "Mutate struct" { | ||
mut dog = Dog(name: "Rex", age: 3) | ||
dog.name = "Bello" | ||
assert dog.name == "Bello" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters