chore: refactor all parse tests to use assert_parse!

This commit is contained in:
Cainã Costa 2023-06-30 16:23:02 -03:00 committed by rvcas
parent f878ef7cef
commit 291dedf4e8
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
39 changed files with 4238 additions and 4720 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,110 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn such() -> Int {\n let add_one = fn (a: Int) -> Int { a + 1 }\n\n 2 |> add_one\n }\n "
info: anonymous_function
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 25..83,
expressions: [
Assignment {
location: 25..67,
value: Fn {
location: 39..67,
fn_style: Plain,
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "a",
location: 43..44,
is_validator_param: false,
},
location: 43..49,
annotation: Some(
Constructor {
location: 46..49,
module: None,
name: "Int",
arguments: [],
},
),
tipo: (),
},
],
body: BinOp {
location: 60..65,
name: AddInt,
left: Var {
location: 60..61,
name: "a",
},
right: Int {
location: 64..65,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
},
return_annotation: Some(
Constructor {
location: 54..57,
module: None,
name: "Int",
arguments: [],
},
),
},
pattern: Var {
location: 29..36,
name: "add_one",
},
kind: Let,
annotation: None,
},
PipeLine {
expressions: [
Int {
location: 71..72,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
Var {
location: 76..83,
name: "add_one",
},
],
one_liner: true,
},
],
},
doc: None,
location: 0..20,
name: "such",
public: true,
return_annotation: Some(
Constructor {
location: 17..20,
module: None,
name: "Int",
arguments: [],
},
),
return_type: (),
end_position: 84,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,62 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub const my_policy_id = #\"00aaff\"\n\n pub fn foo() {\n my_policy_id == #\"00aaff\"\n }\n "
info: base16_bytearray_literals
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
ModuleConstant(
ModuleConstant {
doc: None,
location: 0..34,
public: true,
name: "my_policy_id",
annotation: None,
value: ByteArray {
location: 25..34,
bytes: [
0,
170,
255,
],
preferred_format: HexadecimalString,
},
tipo: (),
},
),
Fn(
Function {
arguments: [],
body: BinOp {
location: 55..80,
name: Eq,
left: Var {
location: 55..67,
name: "my_policy_id",
},
right: ByteArray {
location: 71..80,
bytes: [
0,
170,
255,
],
preferred_format: HexadecimalString,
},
},
doc: None,
location: 36..48,
name: "foo",
public: true,
return_annotation: None,
return_type: (),
end_position: 81,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,99 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn wow2(a: Int){\n let b = {\n let x = 4\n\n x + 5\n }\n\n b\n }\n "
info: block
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "a",
location: 12..13,
is_validator_param: false,
},
location: 12..18,
annotation: Some(
Constructor {
location: 15..18,
module: None,
name: "Int",
arguments: [],
},
),
tipo: (),
},
],
body: Sequence {
location: 23..66,
expressions: [
Assignment {
location: 23..61,
value: Sequence {
location: 37..57,
expressions: [
Assignment {
location: 37..46,
value: Int {
location: 45..46,
value: "4",
base: Decimal {
numeric_underscore: false,
},
},
pattern: Var {
location: 41..42,
name: "x",
},
kind: Let,
annotation: None,
},
BinOp {
location: 52..57,
name: AddInt,
left: Var {
location: 52..53,
name: "x",
},
right: Int {
location: 56..57,
value: "5",
base: Decimal {
numeric_underscore: false,
},
},
},
],
},
pattern: Var {
location: 27..28,
name: "b",
},
kind: Let,
annotation: None,
},
Var {
location: 65..66,
name: "b",
},
],
},
doc: None,
location: 0..19,
name: "wow2",
public: true,
return_annotation: None,
return_type: (),
end_position: 67,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,182 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn calls() {\n let x = add_one(3)\n\n let map_add_x = list.map(_, fn (y) { x + y })\n\n map_add_x([ 1, 2, 3 ])\n }\n "
info: call
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 15..108,
expressions: [
Assignment {
location: 15..33,
value: Call {
arguments: [
CallArg {
label: None,
location: 31..32,
value: Int {
location: 31..32,
value: "3",
base: Decimal {
numeric_underscore: false,
},
},
},
],
fun: Var {
location: 23..30,
name: "add_one",
},
location: 23..33,
},
pattern: Var {
location: 19..20,
name: "x",
},
kind: Let,
annotation: None,
},
Assignment {
location: 37..82,
value: Fn {
location: 53..82,
fn_style: Capture,
arguments: [
Arg {
arg_name: Named {
name: "_capture__0",
label: "_capture__0",
location: 0..0,
is_validator_param: false,
},
location: 0..0,
annotation: None,
tipo: (),
},
],
body: Call {
arguments: [
CallArg {
label: None,
location: 62..63,
value: Var {
location: 62..63,
name: "_capture__0",
},
},
CallArg {
label: None,
location: 65..81,
value: Fn {
location: 65..81,
fn_style: Plain,
arguments: [
Arg {
arg_name: Named {
name: "y",
label: "y",
location: 69..70,
is_validator_param: false,
},
location: 69..70,
annotation: None,
tipo: (),
},
],
body: BinOp {
location: 74..79,
name: AddInt,
left: Var {
location: 74..75,
name: "x",
},
right: Var {
location: 78..79,
name: "y",
},
},
return_annotation: None,
},
},
],
fun: FieldAccess {
location: 53..61,
label: "map",
container: Var {
location: 53..57,
name: "list",
},
},
location: 53..82,
},
return_annotation: None,
},
pattern: Var {
location: 41..50,
name: "map_add_x",
},
kind: Let,
annotation: None,
},
Call {
arguments: [
CallArg {
label: None,
location: 96..107,
value: List {
location: 96..107,
elements: [
Int {
location: 98..99,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 101..102,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 104..105,
value: "3",
base: Decimal {
numeric_underscore: false,
},
},
],
tail: None,
},
},
],
fun: Var {
location: 86..95,
name: "map_add_x",
},
location: 86..108,
},
],
},
doc: None,
location: 0..10,
name: "calls",
public: false,
return_annotation: None,
return_type: (),
end_position: 109,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,24 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n use aiken\n\n // some comment\n // more comments"
info: can_handle_comments_at_end_of_file
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Use(
Use {
as_name: None,
location: 0..9,
module: [
"aiken",
],
package: (),
unqualified: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,58 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn create() {\n some_module.Thing(1, a)\n }\n "
info: cargo_create_unlabeled
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Call {
arguments: [
CallArg {
label: None,
location: 34..35,
value: Int {
location: 34..35,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
},
CallArg {
label: None,
location: 37..38,
value: Var {
location: 37..38,
name: "a",
},
},
],
fun: FieldAccess {
location: 16..33,
label: "Thing",
container: Var {
location: 16..27,
name: "some_module",
},
},
location: 16..39,
},
doc: None,
location: 0..11,
name: "create",
public: false,
return_annotation: None,
return_type: (),
end_position: 40,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,101 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n type Option<a> {\n Some(a, Int)\n None\n Wow { name: Int, age: Int }\n }\n "
info: custom_type
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
DataType(
DataType {
constructors: [
RecordConstructor {
location: 19..31,
name: "Some",
arguments: [
RecordConstructorArg {
label: None,
annotation: Var {
location: 24..25,
name: "a",
},
location: 24..25,
tipo: (),
doc: None,
},
RecordConstructorArg {
label: None,
annotation: Constructor {
location: 27..30,
module: None,
name: "Int",
arguments: [],
},
location: 27..30,
tipo: (),
doc: None,
},
],
doc: None,
sugar: false,
},
RecordConstructor {
location: 34..38,
name: "None",
arguments: [],
doc: None,
sugar: false,
},
RecordConstructor {
location: 41..68,
name: "Wow",
arguments: [
RecordConstructorArg {
label: Some(
"name",
),
annotation: Constructor {
location: 53..56,
module: None,
name: "Int",
arguments: [],
},
location: 47..56,
tipo: (),
doc: None,
},
RecordConstructorArg {
label: Some(
"age",
),
annotation: Constructor {
location: 63..66,
module: None,
name: "Int",
arguments: [],
},
location: 58..66,
tipo: (),
doc: None,
},
],
doc: None,
sugar: false,
},
],
doc: None,
location: 0..70,
name: "Option",
opaque: false,
parameters: [
"a",
],
public: false,
typed_parameters: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,110 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n validator {\n fn foo(datum, rdmr, ctx) {\n True\n }\n\n fn bar(rdmr, ctx) {\n True\n }\n }\n "
info: double_validator
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Validator(
Validator {
doc: None,
end_position: 90,
fun: Function {
arguments: [
Arg {
arg_name: Named {
name: "datum",
label: "datum",
location: 21..26,
is_validator_param: false,
},
location: 21..26,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "rdmr",
label: "rdmr",
location: 28..32,
is_validator_param: false,
},
location: 28..32,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "ctx",
label: "ctx",
location: 34..37,
is_validator_param: false,
},
location: 34..37,
annotation: None,
tipo: (),
},
],
body: Var {
location: 45..49,
name: "True",
},
doc: None,
location: 14..38,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 52,
can_error: true,
},
other_fun: Some(
Function {
arguments: [
Arg {
arg_name: Named {
name: "rdmr",
label: "rdmr",
location: 64..68,
is_validator_param: false,
},
location: 64..68,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "ctx",
label: "ctx",
location: 70..73,
is_validator_param: false,
},
location: 70..73,
annotation: None,
tipo: (),
},
],
body: Var {
location: 81..85,
name: "True",
},
doc: None,
location: 57..74,
name: "bar",
public: false,
return_annotation: None,
return_type: (),
end_position: 88,
can_error: true,
},
),
location: 0..9,
params: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,37 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn run() {}\n "
info: empty_function
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Trace {
kind: Todo,
location: 0..15,
then: ErrorTerm {
location: 0..15,
},
text: String {
location: 0..15,
value: "aiken::todo",
},
},
doc: None,
location: 0..12,
name: "run",
public: true,
return_annotation: None,
return_type: (),
end_position: 14,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,71 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn run() {\n expect Some(x) = something.field\n x.other_field\n }\n "
info: expect
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 19..69,
expressions: [
Assignment {
location: 19..51,
value: FieldAccess {
location: 36..51,
label: "field",
container: Var {
location: 36..45,
name: "something",
},
},
pattern: Constructor {
is_record: false,
location: 26..33,
name: "Some",
arguments: [
CallArg {
label: None,
location: 31..32,
value: Var {
location: 31..32,
name: "x",
},
},
],
module: None,
constructor: (),
with_spread: false,
tipo: (),
},
kind: Expect,
annotation: None,
},
FieldAccess {
location: 56..69,
label: "other_field",
container: Var {
location: 56..57,
name: "x",
},
},
],
},
doc: None,
location: 0..12,
name: "run",
public: true,
return_annotation: None,
return_type: (),
end_position: 70,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,54 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n !test invalid_inputs() {\n expect True = False\n\n False\n }\n "
info: test_fail
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Test(
Function {
arguments: [],
body: Sequence {
location: 27..55,
expressions: [
Assignment {
location: 27..46,
value: Var {
location: 41..46,
name: "False",
},
pattern: Constructor {
is_record: false,
location: 34..38,
name: "True",
arguments: [],
module: None,
constructor: (),
with_spread: false,
tipo: (),
},
kind: Expect,
annotation: None,
},
Var {
location: 50..55,
name: "False",
},
],
},
doc: None,
location: 0..22,
name: "invalid_inputs",
public: false,
return_annotation: None,
return_type: (),
end_position: 56,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,53 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn name(user: User) {\n user.name\n }\n "
info: field_access
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "user",
label: "user",
location: 8..12,
is_validator_param: false,
},
location: 8..18,
annotation: Some(
Constructor {
location: 14..18,
module: None,
name: "User",
arguments: [],
},
),
tipo: (),
},
],
body: FieldAccess {
location: 24..33,
label: "name",
container: Var {
location: 24..28,
name: "user",
},
},
doc: None,
location: 0..19,
name: "name",
public: false,
return_annotation: None,
return_type: (),
end_position: 34,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,202 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo_1() {\n let a = bar\n (40)\n }\n\n fn foo_2() {\n let a = bar\n {40}\n }\n\n fn foo_3() {\n let a = (40+2)\n }\n\n fn foo_4() {\n let a = bar(42)\n (a + 14) * 42\n }\n "
info: function_ambiguous_sequence
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 15..32,
expressions: [
Assignment {
location: 15..26,
value: Var {
location: 23..26,
name: "bar",
},
pattern: Var {
location: 19..20,
name: "a",
},
kind: Let,
annotation: None,
},
Int {
location: 30..32,
value: "40",
base: Decimal {
numeric_underscore: false,
},
},
],
},
doc: None,
location: 0..10,
name: "foo_1",
public: false,
return_annotation: None,
return_type: (),
end_position: 34,
can_error: true,
},
),
Fn(
Function {
arguments: [],
body: Sequence {
location: 52..69,
expressions: [
Assignment {
location: 52..63,
value: Var {
location: 60..63,
name: "bar",
},
pattern: Var {
location: 56..57,
name: "a",
},
kind: Let,
annotation: None,
},
Int {
location: 67..69,
value: "40",
base: Decimal {
numeric_underscore: false,
},
},
],
},
doc: None,
location: 37..47,
name: "foo_2",
public: false,
return_annotation: None,
return_type: (),
end_position: 71,
can_error: true,
},
),
Fn(
Function {
arguments: [],
body: Assignment {
location: 89..103,
value: BinOp {
location: 98..102,
name: AddInt,
left: Int {
location: 98..100,
value: "40",
base: Decimal {
numeric_underscore: false,
},
},
right: Int {
location: 101..102,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
},
pattern: Var {
location: 93..94,
name: "a",
},
kind: Let,
annotation: None,
},
doc: None,
location: 74..84,
name: "foo_3",
public: false,
return_annotation: None,
return_type: (),
end_position: 104,
can_error: true,
},
),
Fn(
Function {
arguments: [],
body: Sequence {
location: 122..153,
expressions: [
Assignment {
location: 122..137,
value: Call {
arguments: [
CallArg {
label: None,
location: 134..136,
value: Int {
location: 134..136,
value: "42",
base: Decimal {
numeric_underscore: false,
},
},
},
],
fun: Var {
location: 130..133,
name: "bar",
},
location: 130..137,
},
pattern: Var {
location: 126..127,
name: "a",
},
kind: Let,
annotation: None,
},
BinOp {
location: 141..153,
name: MultInt,
left: BinOp {
location: 141..147,
name: AddInt,
left: Var {
location: 141..142,
name: "a",
},
right: Int {
location: 145..147,
value: "14",
base: Decimal {
numeric_underscore: false,
},
},
},
right: Int {
location: 151..153,
value: "42",
base: Decimal {
numeric_underscore: false,
},
},
},
],
},
doc: None,
location: 107..117,
name: "foo_4",
public: false,
return_annotation: None,
return_type: (),
end_position: 154,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,37 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo() {}\n "
info: function_def
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Trace {
kind: Todo,
location: 0..11,
then: ErrorTerm {
location: 0..11,
},
text: String {
location: 0..11,
value: "aiken::todo",
},
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 10,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,55 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo() {\n let a = bar(42)\n }\n "
info: function_invoke
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Assignment {
location: 15..30,
value: Call {
arguments: [
CallArg {
label: None,
location: 27..29,
value: Int {
location: 27..29,
value: "42",
base: Decimal {
numeric_underscore: false,
},
},
},
],
fun: Var {
location: 23..26,
name: "bar",
},
location: 23..30,
},
pattern: Var {
location: 19..20,
name: "a",
},
kind: Let,
annotation: None,
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 31,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,110 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn ifs() {\n if True {\n 1 + 1\n } else if a < 4 {\n 5\n } else if a || b {\n 6\n } else {\n 3\n }\n }\n "
info: if_expression
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: If {
location: 13..106,
branches: [
IfBranch {
condition: Var {
location: 16..20,
name: "True",
},
body: BinOp {
location: 27..32,
name: AddInt,
left: Int {
location: 27..28,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
right: Int {
location: 31..32,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
},
location: 16..36,
},
IfBranch {
condition: BinOp {
location: 45..50,
name: LtInt,
left: Var {
location: 45..46,
name: "a",
},
right: Int {
location: 49..50,
value: "4",
base: Decimal {
numeric_underscore: false,
},
},
},
body: Int {
location: 57..58,
value: "5",
base: Decimal {
numeric_underscore: false,
},
},
location: 45..62,
},
IfBranch {
condition: BinOp {
location: 71..77,
name: Or,
left: Var {
location: 71..72,
name: "a",
},
right: Var {
location: 76..77,
name: "b",
},
},
body: Int {
location: 84..85,
value: "6",
base: Decimal {
numeric_underscore: false,
},
},
location: 71..89,
},
],
final_else: Int {
location: 101..102,
value: "3",
base: Decimal {
numeric_underscore: false,
},
},
},
doc: None,
location: 0..8,
name: "ifs",
public: false,
return_annotation: None,
return_type: (),
end_position: 107,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,25 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n use std/list\n "
info: import
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Use(
Use {
as_name: None,
location: 0..12,
module: [
"std",
"list",
],
package: (),
unqualified: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,27 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n use std/tx as t\n "
info: import_alias
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Use(
Use {
as_name: Some(
"t",
),
location: 0..15,
module: [
"std",
"tx",
],
package: (),
unqualified: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,37 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo() {\n #[ 0x01, 0xa2, 0x03 ]\n }\n "
info: int_parsing_hex_bytes
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: ByteArray {
location: 13..34,
bytes: [
1,
162,
3,
],
preferred_format: ArrayOfBytes(
Hexadecimal,
),
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 35,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,137 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn wow(a: Int) {\n let x =\n a + 2\n |> add_one\n |> add_one\n\n let thing = [ 1, 2, a ]\n\n let idk = thing\n\n y\n }\n "
info: let_bindings
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "a",
location: 11..12,
is_validator_param: false,
},
location: 11..17,
annotation: Some(
Constructor {
location: 14..17,
module: None,
name: "Int",
arguments: [],
},
),
tipo: (),
},
],
body: Sequence {
location: 23..121,
expressions: [
Assignment {
location: 23..70,
value: PipeLine {
expressions: [
BinOp {
location: 35..40,
name: AddInt,
left: Var {
location: 35..36,
name: "a",
},
right: Int {
location: 39..40,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
},
Var {
location: 48..55,
name: "add_one",
},
Var {
location: 63..70,
name: "add_one",
},
],
one_liner: false,
},
pattern: Var {
location: 27..28,
name: "x",
},
kind: Let,
annotation: None,
},
Assignment {
location: 74..97,
value: List {
location: 86..97,
elements: [
Int {
location: 88..89,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 91..92,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
Var {
location: 94..95,
name: "a",
},
],
tail: None,
},
pattern: Var {
location: 78..83,
name: "thing",
},
kind: Let,
annotation: None,
},
Assignment {
location: 101..116,
value: Var {
location: 111..116,
name: "thing",
},
pattern: Var {
location: 105..108,
name: "idk",
},
kind: Let,
annotation: None,
},
Var {
location: 120..121,
name: "y",
},
],
},
doc: None,
location: 0..18,
name: "wow",
public: true,
return_annotation: None,
return_type: (),
end_position: 122,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,46 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub opaque type User {\n name: _w\n }\n "
info: opaque_type
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
DataType(
DataType {
constructors: [
RecordConstructor {
location: 21..35,
name: "User",
arguments: [
RecordConstructorArg {
label: Some(
"name",
),
annotation: Hole {
location: 31..33,
name: "_w",
},
location: 25..33,
tipo: (),
doc: None,
},
],
doc: None,
sugar: true,
},
],
doc: None,
location: 0..35,
name: "User",
opaque: true,
parameters: [],
public: true,
typed_parameters: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,117 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo() {\n let tuple = (1, 2, 3, 4)\n tuple.1st + tuple.2nd + tuple.3rd + tuple.4th\n }\n "
info: parse_tuple
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 13..85,
expressions: [
Assignment {
location: 13..37,
value: Tuple {
location: 25..37,
elems: [
Int {
location: 26..27,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 29..30,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 32..33,
value: "3",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 35..36,
value: "4",
base: Decimal {
numeric_underscore: false,
},
},
],
},
pattern: Var {
location: 17..22,
name: "tuple",
},
kind: Let,
annotation: None,
},
BinOp {
location: 40..85,
name: AddInt,
left: BinOp {
location: 40..73,
name: AddInt,
left: BinOp {
location: 40..61,
name: AddInt,
left: TupleIndex {
location: 40..49,
index: 0,
tuple: Var {
location: 40..45,
name: "tuple",
},
},
right: TupleIndex {
location: 52..61,
index: 1,
tuple: Var {
location: 52..57,
name: "tuple",
},
},
},
right: TupleIndex {
location: 64..73,
index: 2,
tuple: Var {
location: 64..69,
name: "tuple",
},
},
},
right: TupleIndex {
location: 76..85,
index: 3,
tuple: Var {
location: 76..81,
name: "tuple",
},
},
},
],
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 86,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,76 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo() {\n let a = foo(14)\n (a, 42)\n }\n "
info: parse_tuple2
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 13..38,
expressions: [
Assignment {
location: 13..28,
value: Call {
arguments: [
CallArg {
label: None,
location: 25..27,
value: Int {
location: 25..27,
value: "14",
base: Decimal {
numeric_underscore: false,
},
},
},
],
fun: Var {
location: 21..24,
name: "foo",
},
location: 21..28,
},
pattern: Var {
location: 17..18,
name: "a",
},
kind: Let,
annotation: None,
},
Tuple {
location: 31..38,
elems: [
Var {
location: 32..33,
name: "a",
},
Int {
location: 35..37,
value: "42",
base: Decimal {
numeric_underscore: false,
},
},
],
},
],
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 39,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,83 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn foo() {\n let i = 1_234_567\n let j = 1_000_000\n let k = -10_000\n }\n "
info: test_parsing_numeric_underscore
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 17..76,
expressions: [
Assignment {
location: 17..34,
value: Int {
location: 25..34,
value: "1234567",
base: Decimal {
numeric_underscore: true,
},
},
pattern: Var {
location: 21..22,
name: "i",
},
kind: Let,
annotation: None,
},
Assignment {
location: 39..56,
value: Int {
location: 47..56,
value: "1000000",
base: Decimal {
numeric_underscore: true,
},
},
pattern: Var {
location: 43..44,
name: "j",
},
kind: Let,
annotation: None,
},
Assignment {
location: 61..76,
value: UnOp {
op: Negate,
location: 69..76,
value: Int {
location: 70..76,
value: "10000",
base: Decimal {
numeric_underscore: true,
},
},
},
pattern: Var {
location: 65..66,
name: "k",
},
kind: Let,
annotation: None,
},
],
},
doc: None,
location: 2..10,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 77,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,73 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn thing(thing a: Int) {\n a + 2\n |> add_one\n |> add_one\n }\n "
info: pipeline
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "thing",
location: 13..20,
is_validator_param: false,
},
location: 13..25,
annotation: Some(
Constructor {
location: 22..25,
module: None,
name: "Int",
arguments: [],
},
),
tipo: (),
},
],
body: PipeLine {
expressions: [
BinOp {
location: 31..36,
name: AddInt,
left: Var {
location: 31..32,
name: "a",
},
right: Int {
location: 35..36,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
},
Var {
location: 42..49,
name: "add_one",
},
Var {
location: 55..62,
name: "add_one",
},
],
one_liner: false,
},
doc: None,
location: 0..26,
name: "thing",
public: true,
return_annotation: None,
return_type: (),
end_position: 63,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,36 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub const my_policy_id = #[0, 170, 255]\n "
info: plain_bytearray_literals
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
ModuleConstant(
ModuleConstant {
doc: None,
location: 0..39,
public: true,
name: "my_policy_id",
annotation: None,
value: ByteArray {
location: 25..39,
bytes: [
0,
170,
255,
],
preferred_format: ArrayOfBytes(
Decimal {
numeric_underscore: false,
},
),
},
tipo: (),
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,60 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn add_one(a) -> Int {\n a + 1\n }\n "
info: plus_binop
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "a",
location: 15..16,
is_validator_param: false,
},
location: 15..16,
annotation: None,
tipo: (),
},
],
body: BinOp {
location: 29..34,
name: AddInt,
left: Var {
location: 29..30,
name: "a",
},
right: Int {
location: 33..34,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
},
doc: None,
location: 0..24,
name: "add_one",
public: true,
return_annotation: Some(
Constructor {
location: 21..24,
module: None,
name: "Int",
arguments: [],
},
),
return_type: (),
end_position: 35,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,36 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub type Me = Option<String>\n "
info: pub_type_alias
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
TypeAlias(
TypeAlias {
alias: "Me",
annotation: Constructor {
location: 14..28,
module: None,
name: "Option",
arguments: [
Constructor {
location: 21..27,
module: None,
name: "String",
arguments: [],
},
],
},
doc: None,
location: 0..28,
parameters: [],
public: true,
tipo: (),
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,75 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn create() {\n User { name: \"Aiken\", age, thing: 2 }\n }\n "
info: record_create_labeled
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Call {
arguments: [
CallArg {
label: Some(
"name",
),
location: 23..36,
value: ByteArray {
location: 29..36,
bytes: [
65,
105,
107,
101,
110,
],
preferred_format: Utf8String,
},
},
CallArg {
label: Some(
"age",
),
location: 38..41,
value: Var {
location: 38..41,
name: "age",
},
},
CallArg {
label: Some(
"thing",
),
location: 43..51,
value: Int {
location: 50..51,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
},
],
fun: Var {
location: 16..20,
name: "User",
},
location: 16..53,
},
doc: None,
location: 0..11,
name: "create",
public: false,
return_annotation: None,
return_type: (),
end_position: 54,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,79 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn create() {\n some_module.User { name: \"Aiken\", age, thing: 2 }\n }\n "
info: record_create_labeled_with_field_access
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Call {
arguments: [
CallArg {
label: Some(
"name",
),
location: 35..48,
value: ByteArray {
location: 41..48,
bytes: [
65,
105,
107,
101,
110,
],
preferred_format: Utf8String,
},
},
CallArg {
label: Some(
"age",
),
location: 50..53,
value: Var {
location: 50..53,
name: "age",
},
},
CallArg {
label: Some(
"thing",
),
location: 55..63,
value: Int {
location: 62..63,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
},
],
fun: FieldAccess {
location: 16..32,
label: "User",
container: Var {
location: 16..27,
name: "some_module",
},
},
location: 16..65,
},
doc: None,
location: 0..11,
name: "create",
public: false,
return_annotation: None,
return_type: (),
end_position: 66,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,109 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n fn update_name(user: User, name: ByteArray) -> User {\n User { ..user, name: \"Aiken\", age }\n }\n "
info: record_update
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "user",
label: "user",
location: 15..19,
is_validator_param: false,
},
location: 15..25,
annotation: Some(
Constructor {
location: 21..25,
module: None,
name: "User",
arguments: [],
},
),
tipo: (),
},
Arg {
arg_name: Named {
name: "name",
label: "name",
location: 27..31,
is_validator_param: false,
},
location: 27..42,
annotation: Some(
Constructor {
location: 33..42,
module: None,
name: "ByteArray",
arguments: [],
},
),
tipo: (),
},
],
body: RecordUpdate {
location: 56..91,
constructor: Var {
location: 56..60,
name: "User",
},
spread: RecordUpdateSpread {
base: Var {
location: 65..69,
name: "user",
},
location: 63..69,
},
arguments: [
UntypedRecordUpdateArg {
label: "name",
location: 71..84,
value: ByteArray {
location: 77..84,
bytes: [
65,
105,
107,
101,
110,
],
preferred_format: Utf8String,
},
},
UntypedRecordUpdateArg {
label: "age",
location: 86..89,
value: Var {
location: 86..89,
name: "age",
},
},
],
},
doc: None,
location: 0..51,
name: "update_name",
public: false,
return_annotation: Some(
Constructor {
location: 47..51,
module: None,
name: "User",
arguments: [],
},
),
return_type: (),
end_position: 92,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,40 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n type RoyaltyToken = (PolicyId, AssetName)\n "
info: tuple_type_alias
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
TypeAlias(
TypeAlias {
alias: "RoyaltyToken",
annotation: Tuple {
location: 20..41,
elems: [
Constructor {
location: 21..29,
module: None,
name: "PolicyId",
arguments: [],
},
Constructor {
location: 31..40,
module: None,
name: "AssetName",
arguments: [],
},
],
},
doc: None,
location: 0..41,
parameters: [],
public: false,
tipo: (),
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,36 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n type Thing = Option<Int>\n "
info: type_alias
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
TypeAlias(
TypeAlias {
alias: "Thing",
annotation: Constructor {
location: 13..24,
module: None,
name: "Option",
arguments: [
Constructor {
location: 20..23,
module: None,
name: "Int",
arguments: [],
},
],
},
doc: None,
location: 0..24,
parameters: [],
public: false,
tipo: (),
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,57 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n use aiken\n\n pub fn go() -> aiken.Option<Int> {\n False\n }\n "
info: type_annotation_with_module_prefix
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Use(
Use {
as_name: None,
location: 0..9,
module: [
"aiken",
],
package: (),
unqualified: [],
},
),
Fn(
Function {
arguments: [],
body: Var {
location: 48..53,
name: "False",
},
doc: None,
location: 11..43,
name: "go",
public: true,
return_annotation: Some(
Constructor {
location: 26..43,
module: Some(
"aiken",
),
name: "Option",
arguments: [
Constructor {
location: 39..42,
module: None,
name: "Int",
arguments: [],
},
],
},
),
return_type: (),
end_position: 54,
can_error: true,
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,42 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n use std/address.{Address as A, thing as w}\n "
info: unqualified_imports
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Use(
Use {
as_name: None,
location: 0..42,
module: [
"std",
"address",
],
package: (),
unqualified: [
UnqualifiedImport {
location: 17..29,
name: "Address",
as_name: Some(
"A",
),
layer: Value,
},
UnqualifiedImport {
location: 31..41,
name: "thing",
as_name: Some(
"w",
),
layer: Value,
},
],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,71 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n validator {\n fn foo(datum, rdmr, ctx) {\n True\n }\n }\n "
info: validator
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Validator(
Validator {
doc: None,
end_position: 54,
fun: Function {
arguments: [
Arg {
arg_name: Named {
name: "datum",
label: "datum",
location: 21..26,
is_validator_param: false,
},
location: 21..26,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "rdmr",
label: "rdmr",
location: 28..32,
is_validator_param: false,
},
location: 28..32,
annotation: None,
tipo: (),
},
Arg {
arg_name: Named {
name: "ctx",
label: "ctx",
location: 34..37,
is_validator_param: false,
},
location: 34..37,
annotation: None,
tipo: (),
},
],
body: Var {
location: 45..49,
name: "True",
},
doc: None,
location: 14..38,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 52,
can_error: true,
},
other_fun: None,
location: 0..9,
params: [],
},
),
],
kind: Validator,
}

View File

@ -0,0 +1,163 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "\n pub fn wow2(a: Int){\n when a is {\n 2 -> 3\n 1 | 4 | 5 -> {\n let amazing = 5\n amazing\n }\n 3 -> 9\n _ -> 4\n }\n }\n "
info: when
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [
Arg {
arg_name: Named {
name: "a",
label: "a",
location: 12..13,
is_validator_param: false,
},
location: 12..18,
annotation: Some(
Constructor {
location: 15..18,
module: None,
name: "Int",
arguments: [],
},
),
tipo: (),
},
],
body: When {
location: 23..132,
subject: Var {
location: 28..29,
name: "a",
},
clauses: [
UntypedClause {
location: 39..45,
patterns: [
Int {
location: 39..40,
value: "2",
base: Decimal {
numeric_underscore: false,
},
},
],
guard: None,
then: Int {
location: 44..45,
value: "3",
base: Decimal {
numeric_underscore: false,
},
},
},
UntypedClause {
location: 50..106,
patterns: [
Int {
location: 50..51,
value: "1",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 54..55,
value: "4",
base: Decimal {
numeric_underscore: false,
},
},
Int {
location: 58..59,
value: "5",
base: Decimal {
numeric_underscore: false,
},
},
],
guard: None,
then: Sequence {
location: 71..100,
expressions: [
Assignment {
location: 71..86,
value: Int {
location: 85..86,
value: "5",
base: Decimal {
numeric_underscore: false,
},
},
pattern: Var {
location: 75..82,
name: "amazing",
},
kind: Let,
annotation: None,
},
Var {
location: 93..100,
name: "amazing",
},
],
},
},
UntypedClause {
location: 111..117,
patterns: [
Int {
location: 111..112,
value: "3",
base: Decimal {
numeric_underscore: false,
},
},
],
guard: None,
then: Int {
location: 116..117,
value: "9",
base: Decimal {
numeric_underscore: false,
},
},
},
UntypedClause {
location: 122..128,
patterns: [
Discard {
name: "_",
location: 122..123,
},
],
guard: None,
then: Int {
location: 127..128,
value: "4",
base: Decimal {
numeric_underscore: false,
},
},
},
],
},
doc: None,
location: 0..19,
name: "wow2",
public: true,
return_annotation: None,
return_type: (),
end_position: 133,
can_error: true,
},
),
],
kind: Validator,
}