mirror of
https://github.com/hi-language/transpiler.git
synced 2026-01-13 16:18:04 +00:00
Feat: Add test for function declaration and invocation
This commit is contained in:
26
test/src/functions.hi
Normal file
26
test/src/functions.hi
Normal file
@@ -0,0 +1,26 @@
|
||||
// implicit return
|
||||
add: (a, b) {
|
||||
a + b
|
||||
}
|
||||
_(add(5, 3))
|
||||
|
||||
// explicit return
|
||||
greet: (name) {
|
||||
^ "Hello, " + name
|
||||
_("this should not print")
|
||||
}
|
||||
_(greet("Master"))
|
||||
|
||||
// arrow function
|
||||
multiply: (a, b) => a * b
|
||||
_(multiply(2, 4))
|
||||
|
||||
// block with side effects and return
|
||||
calculator: {
|
||||
add: (a, b) => a + b,
|
||||
subtract: (a, b) {
|
||||
_("Subtracting...")
|
||||
a - b
|
||||
}
|
||||
}
|
||||
_(calculator.subtract(10, 3))
|
||||
Reference in New Issue
Block a user