0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 21:49:51 +01:00
posthog/hogvm/__tests__/functions.hog

86 lines
1.6 KiB
Plaintext
Raw Normal View History

print('-- test functions --')
2024-08-30 11:51:36 +02:00
fun add(a, b) {
return a + b
}
print(add)
2024-08-30 11:51:36 +02:00
fun add2(a, b) {
let c := a + b
return c
}
print(add2)
2024-08-30 11:51:36 +02:00
fun mult(a, b) {
return a * b
}
print(mult)
2024-08-30 11:51:36 +02:00
fun noArgs() {
let url := 'basdfasdf'
let second := 2 + 3
return second
}
print(noArgs)
2024-08-30 11:51:36 +02:00
fun empty() {}
fun empty2() {}
fun empty3() {}
fun noReturn() {
let a := 1
let b := 2
let c := a + b
}
2024-08-30 11:51:36 +02:00
fun emptyReturn() {
return
}
2024-08-30 11:51:36 +02:00
fun emptyReturnBeforeOtherStuff() {
return
; 2 + 2
}
2024-08-30 11:51:36 +02:00
fun emptyReturnBeforeOtherStuffNoSemicolon() {
// This will return 4 because whitespace is omitted
return
2 + 2
}
2024-08-30 11:51:36 +02:00
fun ifThenReturn() {
2024-06-21 18:22:39 +02:00
// make sure this is not a placeholder {return}
if (false) {
return
}
return 4
}
print(add(3, 4))
print(add(3, 4) + 100 + add(1, 1))
print(noArgs() ?? -1)
print(empty() ?? -1)
print(empty2() ?? -1)
print(empty3() ?? -1)
print(noReturn() ?? -1)
print(emptyReturn() ?? -1)
print(emptyReturnBeforeOtherStuff() ?? -1)
print(emptyReturnBeforeOtherStuffNoSemicolon() ?? -1)
2024-06-21 18:22:39 +02:00
print(ifThenReturn() ?? -1)
print(mult(add(3, 4) + 100 + add(2, 1), 2))
print(mult(add2(3, 4) + 100 + add2(2, 1), 10))
// Call functions with different argument counts
2024-08-30 11:51:36 +02:00
fun printArgs(arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
print(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
}
let printArgs2 := (arg1, arg2, arg3, arg4, arg5, arg6, arg7) -> {
print(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
}
printArgs(1, 2, 3, 4, 5, 6, 7)
printArgs2(1, 2, 3, 4, 5, 6, 7)
printArgs(1, 2, 3, 4, 5, 6)
printArgs2(1, 2, 3, 4, 5, 6)
printArgs(1, 2, 3, 4, 5)
printArgs2(1, 2, 3, 4, 5)
printArgs()
printArgs2()