Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jun 26, 2024
1 parent f089745 commit 46c5982
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 9 deletions.
71 changes: 66 additions & 5 deletions tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ output = "42"
hash = "837525fb91b88dbf02d9ef5a0b322f6943f93424b6e8fe6d26dd1be6d3311871"

[type_guards]
bytes = 63
cost = 1332
input = "()"
output = "5"
hash = "32ed6e4964102d7093ef350019dfd14c99a3ea9feac1f3502194384b8976f7c1"
parser_errors = []
compiler_errors = [
"unused function `bytes_guard` at 15:5",
"unused function `bytes32_guard` at 23:5",
"unused function `public_key_guard` at 33:5",
"unused function `inverted_guard` at 43:5",
"unused function `pair_guard` at 51:5",
]

[if_stmt]
bytes = 107
Expand Down Expand Up @@ -381,3 +384,61 @@ cost = 20323
input = "(((0x42840c6aebec47ce2e01629ce381b461c19695264281a7b1aab5d4ff54506775 1) (0x917b0e1ee2c8ad5755e1f97c4642ea653288acf816eee1b0d537dd8e01106711 2)) 3 100000)"
output = "((60 36) (73 0x0186a0) (g1_negate 0x42840c6aebec47ce2e01629ce381b461c19695264281a7b1aab5d4ff54506775 0x008235 (0x42840c6aebec47ce2e01629ce381b461c19695264281a7b1aab5d4ff54506775)) (g1_negate 0x917b0e1ee2c8ad5755e1f97c4642ea653288acf816eee1b0d537dd8e01106711 0x01046a (0x917b0e1ee2c8ad5755e1f97c4642ea653288acf816eee1b0d537dd8e01106711)))"
hash = "83edaa46ef48ec8bbc8be46b4dd0485ee870fed36f7e51fad3f714cda94bd14c"

[list_types]
parser_errors = []
compiler_errors = [
"unused let binding `empty` at 2:9",
"unused let binding `empty_hinted` at 3:9",
]

[pair_types]
bytes = 57
cost = 3035
input = "()"
output = "80"
hash = "91cecc8bd72dfaf559214ff324f9df7f45c652a96b8f5ae5e3b7fae0dd851014"

[nested_scopes]
bytes = 421
cost = 0
input = "()"
output = "()"
hash = "8d496dc7cdbc417db2132eda6894b29a91511f176e93a1ea943d210cd27822b2"
error = "()"

[birecursive_functions]
bytes = 195
cost = 12822
input = "()"
output = "()"
hash = "770bb2c0b2582924adf403e62374f8424a2ed510eef70b5f450eccab238a4911"

[implicit_return_if_stmt]
parser_errors = []
compiler_errors = [
"implicit return is not allowed in if statements, use an explicit return statement at 2:19",
"block missing return value at 10:19",
"implicit return is not allowed in if statements, use an explicit return statement at 10:19",
"block missing return value at 9:22",
"block missing return value at 16:19",
"implicit return is not allowed in if statements, use an explicit return statement at 16:19",
"unused function `another` at 9:5",
"unused function `yet_another` at 15:5",
"unused function `raise_ok` at 24:5",
]

[recursive_type_alias]
parser_errors = []
compiler_errors = [
"type aliases cannot reference themselves at 4:1",
"type aliases cannot reference themselves at 7:1",
"unused type alias `E` at 6:6",
]

[and_guard]
bytes = 63
cost = 1332
input = "()"
output = "5"
hash = "32ed6e4964102d7093ef350019dfd14c99a3ea9feac1f3502194384b8976f7c1"
26 changes: 26 additions & 0 deletions tests/errors/implicit_return_if_stmt.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fun main() -> Int {
if 1000 > 100 {
42
}

100
}

fun another() -> Int {
if 100 > 1000 {
assert true;
}
}

fun yet_another() -> Int {
if 100 > 1000 {
assert true;
assert false;
assert false;
}
100
}

fun raise_ok() -> Int {
raise;
}
11 changes: 11 additions & 0 deletions tests/errors/recursive_type_alias.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type A = B;
type B = C;
type C = D;
type D = A;

type E = F;
type F = E;

fun main() -> A {
true
}
23 changes: 23 additions & 0 deletions tests/functions/birecursive_functions.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fun main() -> Int {
a(5)
}

fun a(num: Int) -> Int {
if num > 0 {
b(num - 1)
} else {
c()
}
}

fun b(num: Int) -> Int {
if num > 0 {
a(num - 1)
} else {
0
}
}

fun c() -> Int {
52
}
19 changes: 19 additions & 0 deletions tests/functions/nested_scopes.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fun main(value: Int) -> Int {
fun inner_1(num: Int) -> Int {
outer_1() * value + num
}

fun inner_2(num: Int) -> Int {
outer_2(num, inner_1)
}

outer_1() + inner_1(inner_2(value)) * outer_2(value, inner_2)
}

fun outer_1() -> Int {
96
}

fun outer_2(num: Int, closure: fun(num: Int) -> Int) -> Int {
num * closure(num)
}
8 changes: 8 additions & 0 deletions tests/guards/and_guard.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fun main() -> Int {
let a = [1, 2, 3];
let b = [4, 5, 6];

assume !(a is Nil) && !(b is Nil);

a.first + b.first
}
57 changes: 53 additions & 4 deletions tests/guards/type_guards.rue
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
fun main() -> Int {
let a = [1, 2, 3];
let b = [4, 5, 6];
let items = [1, 2, 3];
let bytes = "Hello, world!";
sum(...items) + (bytes is Bytes32) as Int
}

fun sum(...nums: Int[]) -> Int {
if nums is (Int, Int[]) {
nums.first + sum(...nums.rest)
} else {
0
}
}

fun bytes_guard(value: Any) -> Bool {
if value is Bytes {
value.length > 1
} else {
false
}
}

assume !(a is Nil) && !(b is Nil);
fun bytes32_guard(value: Any) -> Bool {
assert value is Bytes;

if value is Bytes32 {
value.length > 1
} else {
false
}
}

fun public_key_guard(value: Any) -> Bool {
assert value is Bytes;

if value is PublicKey {
value.length > 1
} else {
false
}
}

fun inverted_guard(value: Any) -> Bool {
if !(value is (Any, Any)) {
value.length > 1
} else {
false
}
}

a.first + b.first
fun pair_guard(value: Any) -> Int {
if value is (Any, Any) {
pair_guard(value.first) + pair_guard(value.rest)
} else {
value as Int
}
}
15 changes: 15 additions & 0 deletions tests/types/list_types.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fun main() -> Int {
let empty = [];
let empty_hinted: Int[] = empty;

let items = [1, 2, 3];
let items_hinted: Int[] = items;

let spread = [...items];
let spread_hinted: Int[] = [...items];

let prepend = [0, ...items];
let prepend_hinted: Int[] = [0, ...items];

items[0] + items_hinted[1] + spread[2] + spread_hinted[0] + prepend[1] + prepend_hinted[2]
}
6 changes: 6 additions & 0 deletions tests/types/pair_types.rue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fun main() -> Int {
let pair = (20, 24);
let pair_hinted: (Int, Int) = pair;

pair.first + pair.rest + pair_hinted.first + pair_hinted.rest
}

0 comments on commit 46c5982

Please sign in to comment.