-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpressions_test.fun
More file actions
executable file
·78 lines (63 loc) · 1.58 KB
/
expressions_test.fun
File metadata and controls
executable file
·78 lines (63 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*/
/*
* Expression Testing Suite
*
* Contains comprehensive tests for:
* - Operator precedence rules
* - Arithmetic expression evaluation
* - Logical expressions (AND, OR)
* - Conditional expressions (`if`, `else`)
* - Expression short-circuiting behavior
*/
// Expressions test: arithmetic, precedence, comparisons, logical ops, unary, parentheses.
print("=== Expressions test start ===")
// Typed declarations
number a = 2
number b = 3
number n = 10
string s = "Have fun!"
boolean flag = true
// Arithmetic and precedence
number sum = a + b * 5 - 1
print(sum) // expect 2 + 3*5 - 1 = 16
number calc = (a + b) * (b - a + 1)
print(calc) // expect (2+3)*(3-2+1) = 5*2 = 10
// Unary operators
number neg = -n
print(neg) // expect -10
number modv = n % 3
print(modv) // expect 1
// Booleans and logical ops
print(!false) // expect 1 (true)
print(true && false) // expect 0 (false)
print(true || false) // expect 1 (true)
// Comparisons and strings
print(n > 5) // expect 1
print(s != "") // expect 1
// Mixed logical/relational
print(a < b && n >= 10) // expect 1
print((a + b) == 5 && flag) // expect 1
print("=== Expressions test end ===")
/* Expected output:
=== Expressions test start ===
16
10
-10
1
true
false
true
1
true
true
true
=== Expressions test end ===
*/