Skip to content

Commit f7de847

Browse files
committed
Add type checking tests for conditions
1 parent 4bd68c2 commit f7de847

File tree

9 files changed

+50
-1
lines changed

9 files changed

+50
-1
lines changed

tests/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ stack
77
comments
88
macros
99
dead-recursive-macro
10-
argv
10+
argv
11+
if-else
12+
else-less-if

tests/else-less-if-fail.porth

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34 35 + 69 = if 69 end print

tests/else-less-if-fail.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:i argc 0
2+
:b stdin 0
3+
4+
:i returncode 1
5+
:b stdout 0
6+
7+
:b stderr 274
8+
./tests/else-less-if-fail.porth:1:20: ERROR: else-less if block is not allowed to alter the types of the arguments on the data stack
9+
./tests/else-less-if-fail.porth:1:20: NOTE: Expected types: []
10+
./tests/else-less-if-fail.porth:1:20: NOTE: Actual types: [<DataType.INT: 1>]
11+

tests/else-less-if.porth

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
34 35 + 70 = if 69 print end
2+
34 35 + 69 = if 69 print end

tests/else-less-if.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:i argc 0
2+
:b stdin 0
3+
4+
:i returncode 0
5+
:b stdout 3
6+
69
7+
8+
:b stderr 0
9+

tests/if-else-fail.porth

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34 35 + 69 = if 69 print else 420 end

tests/if-else-fail.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:i argc 0
2+
:b stdin 0
3+
4+
:i returncode 1
5+
:b stdout 0
6+
7+
:b stderr 264
8+
./tests/if-else-fail.porth:1:35: ERROR: both branches of the if-block must produce the same types of the arguments on the data stack
9+
./tests/if-else-fail.porth:1:35: NOTE: Expected types: []
10+
./tests/if-else-fail.porth:1:35: NOTE: Actual types: [<DataType.INT: 1>]
11+

tests/if-else.porth

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
34 35 + 70 = if 69 else 420 end print
2+
34 35 + 69 = if 69 else 420 end print

tests/if-else.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:i argc 0
2+
:b stdin 0
3+
4+
:i returncode 0
5+
:b stdout 7
6+
420
7+
69
8+
9+
:b stderr 0
10+

0 commit comments

Comments
 (0)