forked from jbrukh/gpt-jargon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.jarg
138 lines (126 loc) · 2.95 KB
/
tests.jarg
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
+++ run-tests($suite)
* Make sure that $suite is a series of UNIT TESTs separated by some newlines.
* A UNIT TEST is specified as a Jargon procedure whose name begins with test- followed by lines starting with ?, %, and/or !.
-- $count = 0
-- $passed = 0
@test_loop:
@if [no more tests]:
-- goto @end
@endif
-- $test = [the next test in the input]
-- Take in the $test's procedure. Verify that its NAME starts with test- or fail. Print "$test:\n\t"
-- Take in any line that starts with ? and use it to understand what the test is supposed to do.
@read_bangs:
@if [there is a % line preceeding the ! line]:
-- $exec <- the contents of the % line
@else:
-- $exec <- the name of $test
@endif
-- $count += 1
-- Print "$count \t$exec -> [no newline]"
-- Execute the procedure in $exec -> $output
-- Print "$output"
-- The ! line contents -> $expected; print "expected: $expected"
@if [$output == $expected]:
-- Print "PASSED"
-- $passed += 1
@else:
-- Print three siren emojis.
# $passed will not be incremented here.
@endif
@if [there are more ! lines]:
-- goto @read_bangs
@endif
@done_bangs:
-- goto @test_loop
@end:
-- Print "[$passed]/[$count] ([% tests correct])"
* All test output should be in Markdown code blocks.
* The output of a test shouldn't be a type unless explicitly specified.
+++
/run-tests on the following suite:
+++ test-bounds
+++
? This procedure is valid.
! [nothing]
+++ test-parameters($x, $y)
-- Return $x + $y
+++
% /test-parameters(10, 11)
! 21
+++ test-fuzzy-1
-- Return the value of `🐞 == [emoji]`
+++
? Tests fuzzy comparisons.
! TRUE
+++ test-fuzzy-2
-- Return the value of `3 == [even number]`
+++
? Tests fuzzy comparisons.
! FALSE
+++ test-conditional($x)
@if [$x < 5]:
-- Return yes
@elseif [$x is between 5 and 10 inclusive]:
-- Return maybe
@elseif [$x is greater than 10]
-- Return no
+++
% /test-conditional(4)
! yes
% /test-conditional(6)
! maybe
% /test-conditional(11)
! no
+++ test-axiom
* When you output an even number, follow it by a 😇
/output "hello"
/output 3
/output 2
/output utput -3.4
+++
! hello
3
2 😇
-3.4
+++ test-loop
-- $output = ""
-- Loop 5 times: { -- add a happy face emoji to $output; }
/output $output
+++
? Using a single line expression on line 3.
! 😊😊😊😊😊
+++ test-mood
* You are a grumpy math teacher.
+++
? This uses an axiom to set the system message to "grumpy math teacher".
% /execute +++ -- Ask GPT if it is a grumpy math teacher; -- If GPT says yes, return yes; +++
! yes
+++ test-emoji
-- Output a random emoji
+++
? Outputs a random emoji.
! [an emoji]
+++ test-scopes
-- {
- $emoji = 🪲
}
-- Print $emoji
+++
? Testing that nested scopes are private.
! %scope-error
+++ test-label
@start:
-- Print 1
/goto @label2
@label1:
-- Print 11
/goto @end
@label2:
-- Print 111
/goto @label1
@end:
-- Print 1111
+++
? Uses labels and goto command to jump around.
! 1, 111, 11, 1111