test(parser): finish moving tests to their correct modules

This commit is contained in:
rvcas
2023-07-04 17:48:48 -04:00
parent 47567c5e6f
commit 5e8edcb340
42 changed files with 974 additions and 1388 deletions

View File

@@ -1,4 +1,3 @@
mod check;
mod format;
mod lexer;
mod parser;

View File

@@ -1,204 +0,0 @@
use crate::assert_module;
#[test]
fn custom_type() {
assert_module!(
r#"
type Option<a> {
Some(a, Int)
None
Wow { name: Int, age: Int }
}
"#
);
}
#[test]
fn opaque_type() {
assert_module!(
r#"
pub opaque type User {
name: _w
}
"#
);
}
#[test]
fn expect() {
assert_module!(
r#"
pub fn run() {
expect Some(x) = something.field
x.other_field
}
"#
);
}
#[test]
fn plus_binop() {
assert_module!(
r#"
pub fn add_one(a) -> Int {
a + 1
}
"#
);
}
#[test]
fn pipeline() {
assert_module!(
r#"
pub fn thing(thing a: Int) {
a + 2
|> add_one
|> add_one
}
"#
);
}
#[test]
fn block() {
assert_module!(
r#"
pub fn wow2(a: Int){
let b = {
let x = 4
x + 5
}
b
}
"#
);
}
#[test]
fn when() {
assert_module!(
r#"
pub fn wow2(a: Int){
when a is {
2 -> 3
1 | 4 | 5 -> {
let amazing = 5
amazing
}
3 -> 9
_ -> 4
}
}
"#
);
}
#[test]
fn field_access() {
assert_module!(
r#"
fn name(user: User) {
user.name
}
"#
);
}
#[test]
fn call() {
assert_module!(
r#"
fn calls() {
let x = add_one(3)
let map_add_x = list.map(_, fn (y) { x + y })
map_add_x([ 1, 2, 3 ])
}
"#
);
}
#[test]
fn parse_tuple() {
assert_module!(
r#"
fn foo() {
let tuple = (1, 2, 3, 4)
tuple.1st + tuple.2nd + tuple.3rd + tuple.4th
}
"#
);
}
#[test]
fn parse_tuple2() {
assert_module!(
r#"
fn foo() {
let a = foo(14)
(a, 42)
}
"#
);
}
#[test]
fn plain_bytearray_literals() {
assert_module!(
r#"
pub const my_policy_id = #[0, 170, 255]
"#
);
}
#[test]
fn base16_bytearray_literals() {
assert_module!(
r#"
pub const my_policy_id = #"00aaff"
pub fn foo() {
my_policy_id == #"00aaff"
}
"#
);
}
#[test]
fn function_invoke() {
assert_module!(
r#"
fn foo() {
let a = bar(42)
}
"#
);
}
#[test]
fn parse_unicode_offset_1() {
assert_module!(
r#"
fn foo() {
let x = "★"
x
}
"#
);
}
#[test]
fn parse_unicode_offset_2() {
assert_module!(
r#"
fn foo() {
let x = "*"
x
}
"#
);
}

View File

@@ -1,61 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub const my_policy_id = #\"00aaff\"\n\npub fn foo() {\n my_policy_id == #\"00aaff\"\n}\n"
---
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

@@ -1,98 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub fn wow2(a: Int){\n let b = {\n let x = 4\n\n x + 5\n }\n\n b\n}\n"
---
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

@@ -1,181 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn 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"
---
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

@@ -1,100 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\ntype Option<a> {\n Some(a, Int)\n None\n Wow { name: Int, age: Int }\n}\n"
---
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

@@ -1,70 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub fn run() {\n expect Some(x) = something.field\n x.other_field\n}\n"
---
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

@@ -1,52 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn name(user: User) {\n user.name\n}\n"
---
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

@@ -1,54 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn foo() {\n let a = bar(42)\n}\n"
---
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

@@ -1,45 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub opaque type User {\n name: _w\n}\n"
---
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

@@ -1,116 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn foo() {\n let tuple = (1, 2, 3, 4)\n tuple.1st + tuple.2nd + tuple.3rd + tuple.4th\n}\n"
---
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

@@ -1,75 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn foo() {\n let a = foo(14)\n (a, 42)\n}\n"
---
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

@@ -1,52 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn foo() {\n let x = \"★\"\n x\n}\n"
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 13..30,
expressions: [
Assignment {
location: 13..26,
value: ByteArray {
location: 21..26,
bytes: [
226,
152,
133,
],
preferred_format: Utf8String,
},
pattern: Var {
location: 17..18,
name: "x",
},
kind: Let,
annotation: None,
},
Var {
location: 29..30,
name: "x",
},
],
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 31,
can_error: true,
},
),
],
kind: Validator,
}

View File

@@ -1,50 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\nfn foo() {\n let x = \"*\"\n x\n}\n"
---
Module {
name: "",
docs: [],
type_info: (),
definitions: [
Fn(
Function {
arguments: [],
body: Sequence {
location: 13..28,
expressions: [
Assignment {
location: 13..24,
value: ByteArray {
location: 21..24,
bytes: [
42,
],
preferred_format: Utf8String,
},
pattern: Var {
location: 17..18,
name: "x",
},
kind: Let,
annotation: None,
},
Var {
location: 27..28,
name: "x",
},
],
},
doc: None,
location: 0..8,
name: "foo",
public: false,
return_annotation: None,
return_type: (),
end_position: 29,
can_error: true,
},
),
],
kind: Validator,
}

View File

@@ -1,72 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub fn thing(thing a: Int) {\n a + 2\n |> add_one\n |> add_one\n}\n"
---
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

@@ -1,35 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub const my_policy_id = #[0, 170, 255]\n"
---
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

@@ -1,59 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub fn add_one(a) -> Int {\n a + 1\n}\n"
---
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

@@ -1,162 +0,0 @@
---
source: crates/aiken-lang/src/tests/parser.rs
description: "Code:\n\npub 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"
---
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,
}