test(parser): type alias, anon fn, record update and more
This commit is contained in:
@@ -1,31 +1,5 @@
|
||||
use crate::assert_module;
|
||||
|
||||
#[test]
|
||||
fn type_annotation_with_module_prefix() {
|
||||
assert_module!(
|
||||
r#"
|
||||
use aiken
|
||||
|
||||
pub fn go() -> aiken.Option<Int> {
|
||||
False
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fail() {
|
||||
assert_module!(
|
||||
r#"
|
||||
!test invalid_inputs() {
|
||||
expect True = False
|
||||
|
||||
False
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_type() {
|
||||
assert_module!(
|
||||
@@ -50,33 +24,6 @@ fn opaque_type() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_alias() {
|
||||
assert_module!(
|
||||
r#"
|
||||
type Thing = Option<Int>
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pub_type_alias() {
|
||||
assert_module!(
|
||||
r#"
|
||||
pub type Me = Option<String>
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_function() {
|
||||
assert_module!(
|
||||
r#"
|
||||
pub fn run() {}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect() {
|
||||
assert_module!(
|
||||
@@ -113,26 +60,6 @@ fn pipeline() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn let_bindings() {
|
||||
assert_module!(
|
||||
r#"
|
||||
pub fn wow(a: Int) {
|
||||
let x =
|
||||
a + 2
|
||||
|> add_one
|
||||
|> add_one
|
||||
|
||||
let thing = [ 1, 2, a ]
|
||||
|
||||
let idk = thing
|
||||
|
||||
y
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block() {
|
||||
assert_module!(
|
||||
@@ -169,19 +96,6 @@ fn when() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn anonymous_function() {
|
||||
assert_module!(
|
||||
r#"
|
||||
pub fn such() -> Int {
|
||||
let add_one = fn (a: Int) -> Int { a + 1 }
|
||||
|
||||
2 |> add_one
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_access() {
|
||||
assert_module!(
|
||||
@@ -208,17 +122,6 @@ fn call() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_update() {
|
||||
assert_module!(
|
||||
r#"
|
||||
fn update_name(user: User, name: ByteArray) -> User {
|
||||
User { ..user, name: "Aiken", age }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_create_labeled() {
|
||||
assert_module!(
|
||||
@@ -344,15 +247,6 @@ fn function_ambiguous_sequence() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuple_type_alias() {
|
||||
assert_module!(
|
||||
r#"
|
||||
type RoyaltyToken = (PolicyId, AssetName)
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_class_binop() {
|
||||
assert_module!(
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\npub fn such() -> Int {\n let add_one = fn (a: Int) -> Int { a + 1 }\n\n 2 |> add_one\n}\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\npub fn run() {}\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\n!test invalid_inputs() {\n expect True = False\n\n False\n}\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\npub 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"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\npub type Me = Option<String>\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nfn update_name(user: User, name: ByteArray) -> User {\n User { ..user, name: \"Aiken\", age }\n}\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\ntype RoyaltyToken = (PolicyId, AssetName)\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\ntype Thing = Option<Int>\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/tests/parser.rs
|
||||
description: "Code:\n\nuse aiken\n\npub fn go() -> aiken.Option<Int> {\n False\n}\n"
|
||||
---
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user