Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
plywood/repos/plywood/src/apps/CrowbarTest/AllCrowbarTests.txt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
443 lines (349 sloc)
7.93 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ------------------------------------------------------------ | |
| fn test() { | |
| a = 1 | |
| b = 1 | |
| while a < 100 { | |
| print(a) | |
| t = a | |
| a = b | |
| b = b + t | |
| } | |
| } | |
| result: | |
| 1 | |
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 8 | |
| 13 | |
| 21 | |
| 34 | |
| 55 | |
| 89 | |
| ------------------------------------------------------------ | |
| fn gcd(a, b) { | |
| if a % b == 0 | |
| return b | |
| else | |
| return gcd(b, a % b) | |
| } | |
| fn test() { | |
| print(gcd(36, 96)) | |
| } | |
| result: | |
| 12 | |
| ------------------------------------------------------------ | |
| { | |
| result: | |
| (1, 1) error: unexpected '{' | |
| ------------------------------------------------------------ | |
| < | |
| fn foo() { | |
| } > | |
| result: | |
| (1, 1) error: unexpected '<' | |
| (3, 3) error: unexpected '>' | |
| ------------------------------------------------------------ | |
| fn () { | |
| } | |
| result: | |
| (1, 4) error: expected function name after 'fn'; got '(' | |
| ------------------------------------------------------------ | |
| fn % () { | |
| } | |
| fn foo() { | |
| } | |
| + | |
| result: | |
| (1, 4) error: expected function name after 'fn'; got '%' | |
| (5, 1) error: unexpected '+' | |
| ------------------------------------------------------------ | |
| fn foo { | |
| } | |
| result: | |
| (1, 8) error: expected '(' after function name 'foo'; got '{' | |
| ------------------------------------------------------------ | |
| fn foo | |
| result: | |
| (2, 1) error: expected '(' after function name 'foo'; got end-of-file | |
| ------------------------------------------------------------ | |
| fn foo % | |
| fn bar $ | |
| result: | |
| (1, 8) error: expected '(' after function name 'foo'; got '%' | |
| (2, 8) error: expected '(' after function name 'bar'; got '$' | |
| ------------------------------------------------------------ | |
| fn foo(%) { | |
| } | |
| result: | |
| (1, 8) error: expected function parameter; got '%' | |
| ------------------------------------------------------------ | |
| fn foo(% { | |
| } | |
| fn bar($) { | |
| } | |
| result: | |
| (1, 8) error: expected function parameter; got '%' | |
| (3, 8) error: expected function parameter; got '$' | |
| ------------------------------------------------------------ | |
| fn foo(a b) { | |
| } | |
| result: | |
| (1, 10) error: expected ',' or ')' after parameter 'a'; got 'b' | |
| ------------------------------------------------------------ | |
| fn foo(a { | |
| } | |
| fn bar(a b { | |
| } | |
| result: | |
| (1, 10) error: expected ',' or ')' after parameter 'a'; got '{' | |
| ------------------------------------------------------------ | |
| fn foo(a) | |
| result: | |
| (2, 1) error: expected '{' after parameter list; got end-of-file | |
| ------------------------------------------------------------ | |
| fn foo() | |
| fn bar() { | |
| } | |
| + | |
| result: | |
| (2, 1) error: expected '{' after parameter list; got 'fn' | |
| (4, 1) error: unexpected '+' | |
| ------------------------------------------------------------ | |
| fn foo(a) { | |
| result: | |
| (2, 1) error: unexpected end-of-file inside function | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| if true { | |
| result: | |
| (3, 1) error: unexpected end-of-file inside if-statement | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| if true | |
| x = 3 | |
| } | |
| result: | |
| (3, 9) error: body of if-statement must be enclosed in curly braces unless it's a break, continue or return statement | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| while true { | |
| result: | |
| (3, 1) error: unexpected end-of-file inside while-loop | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| while true | |
| x = 3 | |
| } | |
| result: | |
| (3, 9) error: body of while-loop must be enclosed in curly braces unless it's a break, continue or return statement | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print(1 > 2) | |
| print(true || false) | |
| print(true && false) | |
| } | |
| result: | |
| false | |
| true | |
| false | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| return && | |
| } | |
| result: | |
| (2, 12) error: expected an expression; got '&&' | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| bar(a b) | |
| bar(a, , b) | |
| } | |
| result: | |
| (2, 11) error: expected ',' or ')' after argument; got 'b' | |
| (3, 12) error: expected an expression; got ',' | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| / | |
| a = 0 $ | |
| } | |
| result: | |
| (2, 5) error: expected a statement; got '/' | |
| (3, 11) error: unexpected '$' after assignment | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print(1 + 2 * 3) | |
| print((1 + 2) * 3) | |
| print(1 + (2 * 3)) | |
| print(2 * (1 + ((5 + 4) / 3))) | |
| } | |
| result: | |
| 7 | |
| 9 | |
| 7 | |
| 8 | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| // Line breaks are significant outside parentheses, so this is an error: | |
| return 1 + | |
| 2 | |
| } | |
| result: | |
| (3, 15) error: expected an expression; got end-of-line | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| // Line breaks are ignored inside parentheses, so this is OK: | |
| return (1 + | |
| 2) | |
| } | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| return (1 + | |
| } | |
| result: | |
| (3, 1) error: expected an expression; got '}' | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| return (1 2) | |
| } | |
| result: | |
| (2, 15) error: expected ')' to match the '(' at (2, 12); got '2' | |
| (2, 16) error: unexpected ')' after expression | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print("Hello world!") | |
| } | |
| result: | |
| Hello world! | |
| ------------------------------------------------------------ | |
| fn test() { | |
| left = "Yeah, well, you know, that's just, " | |
| right = "like, your opinion, man." | |
| print(left + right) | |
| print("/" * 20) | |
| } | |
| result: | |
| Yeah, well, you know, that's just, like, your opinion, man. | |
| //////////////////// | |
| ------------------------------------------------------------ | |
| fn test() { | |
| color = "red" | |
| print("Roses are ${color}.") | |
| action = "evaluate" | |
| kind = "complex" | |
| print("You can ${action + " ${kind} expressions"} inside string literals.") | |
| } | |
| result: | |
| Roses are red. | |
| You can evaluate complex expressions inside string literals. | |
| ------------------------------------------------------------ | |
| fn somefunc() { | |
| return 42 | |
| } | |
| fn test() { | |
| print("The answer is ${somefunc()}.") | |
| } | |
| result: | |
| The answer is 42. | |
| ------------------------------------------------------------ | |
| fn foo() { | |
| return "a" | |
| } | |
| fn test() { | |
| print(foo()) | |
| } | |
| result: | |
| a | |
| ------------------------------------------------------------ | |
| fn somefunc(x) { | |
| if x > 3 | |
| return "go" | |
| else | |
| return "${x} ${somefunc(x + 1)}" | |
| } | |
| fn test() { | |
| print(somefunc(1)) | |
| } | |
| result: | |
| 1 2 3 go | |
| ------------------------------------------------------------ | |
| fn test() { | |
| true + false | |
| } | |
| result: | |
| error: 'bool' does not support binary operator '+' | |
| (2, 10) in function 'test' | |
| ------------------------------------------------------------ | |
| fn test() { | |
| false.foo | |
| } | |
| result: | |
| error: 'bool' does not support property lookup | |
| (2, 11) in function 'test' | |
| ------------------------------------------------------------ | |
| fn test() { | |
| 3() | |
| } | |
| result: | |
| error: cannot call 'u32' as a function | |
| (2, 6) in function 'test' | |
| ------------------------------------------------------------ | |
| fn foo(x) { | |
| if x > 0 { | |
| foo(x - 1) | |
| } else { | |
| bar() | |
| } | |
| } | |
| fn test() { | |
| foo(3) | |
| } | |
| result: | |
| error: cannot resolve identifier 'bar' | |
| (5, 9) in function 'foo' | |
| (3, 12) called from 'foo' | |
| (3, 12) called from 'foo' | |
| (3, 12) called from 'foo' | |
| (10, 8) called from 'test' | |
| ------------------------------------------------------------ | |
| fn somefunc(x) { | |
| if x > 3 | |
| return bar | |
| else | |
| return "${x} ${somefunc(x + 1)}" | |
| } | |
| fn test() { | |
| print(somefunc(1)) | |
| } | |
| result: | |
| error: cannot resolve identifier 'bar' | |
| (3, 16) in function 'somefunc' | |
| (5, 32) called from 'somefunc' | |
| (5, 32) called from 'somefunc' | |
| (5, 32) called from 'somefunc' | |
| (9, 19) called from 'test' | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print(-false) | |
| } | |
| result: | |
| error: 'bool' does not support unary operator '-' | |
| (2, 11) in function 'test' | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print(!true) | |
| } | |
| result: | |
| false | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print(~1) | |
| } | |
| result: | |
| 4294967294 | |
| ------------------------------------------------------------ | |
| fn test() { | |
| print(!5) | |
| } | |
| result: | |
| 0 | |