Skip to content

Commit f7f6019

Browse files
committed
finished AllSyntax example
1 parent 7a6a8d0 commit f7f6019

File tree

5 files changed

+97
-5
lines changed

5 files changed

+97
-5
lines changed

ci_scripts/all_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ expect ci_scripts/expect_scripts/Parser.exp
3939

4040
$ROC test ./examples/PatternMatching/PatternMatching.roc
4141

42+
$ROC build ./examples/AllSyntax/main.roc
43+
expect ci_scripts/expect_scripts/AllSyntax.exp
44+
4245
$ROC build ./examples/RandomNumbers/main.roc
4346
expect ci_scripts/expect_scripts/RandomNumbers.exp
4447

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/expect
2+
3+
# uncomment line below for debugging
4+
# exp_internal 1
5+
6+
set timeout 7
7+
8+
source ./ci_scripts/expect_scripts/shared-code.exp
9+
10+
spawn ./examples/AllSyntax/main
11+
12+
set expected_output [normalize_output {
13+
\{diff: 5, div: 2, div_trunc: 2, eq: Bool.false, gt: Bool.true, gteq: Bool.true, lt: Bool.false, lteq: Bool.false, neg: -10, neq: Bool.true, prod: 50, rem: 0, sum: 15\}
14+
\{bool_and: Bool.false, bool_and_keyword: Bool.false, bool_or: Bool.true, bool_or_keyword: Bool.true, not_a: Bool.false\}
15+
"Pizza Roc"
16+
42
17+
Hello, Venus!This is a multiline string.
18+
You can call functions inside $... too: 2
19+
Unicode escape sequence:  
20+
"Success"
21+
Hello, world!
22+
Hello, world!
23+
Hello, world!
24+
Hello, world!
25+
Hello, world!
26+
(Ok \{\})
27+
"True"
28+
("Roc", 1)
29+
Red
30+
\[1, 2\]
31+
(TagFour 42)
32+
default
33+
("Roc", 1, 1, 2)
34+
\[./examples/AllSyntax/main.roc:116\] a = 42
35+
\[./examples/AllSyntax/main.roc:119\] 43 = 43
36+
\{\}
37+
}]
38+
39+
expect $expected_output {
40+
expect eof {
41+
check_exit_and_segfault
42+
}
43+
}
44+
puts stderr "\nError: output was different from expected value."
45+
exit 1

examples/AllSyntax/README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
TODO
1+
# All Syntax File
2+
3+
Demonstrates all Roc syntax in a single app file.
4+
5+
## Code
6+
```roc
7+
file:main.roc
8+
```
9+
10+
## Output
11+
12+
Run this from the directory that has `main.roc` in it:
13+
14+
```
15+
$ roc main.roc
16+
{diff: 5, div: 2, div_trunc: 2, eq: Bool.false, gt: Bool.true, gteq: Bool.true, lt: Bool.false, lteq: Bool.false, neg: -10, neq: Bool.true, prod: 50, rem: 0, sum: 15}
17+
{bool_and: Bool.false, bool_and_keyword: Bool.false, bool_or: Bool.true, bool_or_keyword: Bool.true, not_a: Bool.false}
18+
"Pizza Roc"
19+
42
20+
Hello, Venus!This is a multiline string.
21+
You can call functions inside $... too: 2
22+
Unicode escape sequence:  
23+
"Success"
24+
Hello, world!
25+
Hello, world!
26+
Hello, world!
27+
Hello, world!
28+
Hello, world!
29+
(Ok {})
30+
"True"
31+
("Roc", 1)
32+
Red
33+
[1, 2]
34+
(TagFour 42)
35+
default
36+
("Roc", 1, 1, 2)
37+
[examples/AllSyntax/main.roc:116] a = 42
38+
[examples/AllSyntax/main.roc:119] 43 = 43
39+
{}
40+
```
41+

examples/AllSyntax/main.roc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import cli.Arg exposing [Arg]
55

66
# Note: I tried to demonstrate all Roc syntax (possible in a single app file), but I probably forgot some things.
77

8-
# Note: Do not include this file in an LLM prompt, this file does not demonstrate best practices.
9-
108
number_operators : I64, I64 -> _
119
number_operators = |a, b|
1210
a_f64 = Num.to_f64(a)
@@ -128,10 +126,16 @@ dbg_expect = |{}|
128126
# Top level expect
129127
expect 0 == 0
130128

129+
# Values that are defined inside a multi-line expect get printed on failure
130+
expect
131+
expected = 43
132+
actual = 44
133+
134+
actual == expected
135+
131136
if_demo : Bool -> Str
132137
if_demo = |cond|
133138
# every if must have an else branch!
134-
135139
one_line_if = if cond then "True" else "False"
136140

137141
# multiline if
@@ -191,7 +195,6 @@ main! = |_args|
191195

192196
pizza_out = pizza_operator("Pizza ", "Roc")
193197
Stdout.line!("${Inspect.to_str(pizza_out)}")?
194-
195198
Stdout.line!("${Inspect.to_str(patterns([1, 2, 3, 4]))}")?
196199
Stdout.line!("${string_stuff}")?
197200
Stdout.line!("${Inspect.to_str(pattern_match_tag_union(Ok({})))}")?

examples/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You can find the source code for all of these at [github.com/roc-lang/examples](
1818
- [Multiple Roc Files](/MultipleRocFiles/README.html)
1919
- [JSON](/Json/README.html)
2020
- [Hello, Webserver!](/HelloWeb/README.html)
21+
- [All Syntax in 1 File](/examples/AllSyntax/README.html)
2122
- [Scripting](/Scripting/README.html)
2223
- [Terminal Commands](/Commands/README.html)
2324
- [Sort Strings](/SortStrings/README.html)

0 commit comments

Comments
 (0)