Running it
What CI runs and the output it checks, byte for byte.
dawn run examples/basics/fizzbuzz.dawn
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
examples/basics/fizzbuzz.dawn
# FizzBuzz: match guards, string interpolation and a `for` over a range.
#
# Run: dawn run examples/basics/fizzbuzz.dawn
fn shout(n: Int) -> String =
match n {
x if x % 15 == 0 -> "FizzBuzz"
x if x % 3 == 0 -> "Fizz"
x if x % 5 == 0 -> "Buzz"
x -> "${x}"
}
pub fn main() -> Unit !io = {
for i in 1..21 {
println(shout(i))
}
}
test "the divisible-by-fifteen arm has to come first" {
assert shout(15) == "FizzBuzz"
assert shout(9) == "Fizz"
assert shout(10) == "Buzz"
assert shout(7) == "7"
}