test(parser): finish moving tests to their correct modules
This commit is contained in:
@@ -92,3 +92,32 @@ fn labeled_constructor_type_args(
|
||||
.allow_trailing()
|
||||
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_definition;
|
||||
|
||||
#[test]
|
||||
fn custom_type() {
|
||||
assert_definition!(
|
||||
r#"
|
||||
type Option<a> {
|
||||
Some(a, Int)
|
||||
None
|
||||
Wow { name: Int, age: Int }
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_type() {
|
||||
assert_definition!(
|
||||
r#"
|
||||
pub opaque type User {
|
||||
name: _w
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/definition/data_type.rs
|
||||
description: "Code:\n\ntype Option<a> {\n Some(a, Int)\n None\n Wow { name: Int, age: Int }\n}\n"
|
||||
---
|
||||
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: [],
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/definition/data_type.rs
|
||||
description: "Code:\n\npub opaque type User {\n name: _w\n}\n"
|
||||
---
|
||||
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: [],
|
||||
},
|
||||
)
|
||||
@@ -50,6 +50,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn let_bindings() {
|
||||
assert_expr!(r#"let thing = [ 1, 2, a ]"#);
|
||||
assert_expr!("let thing = [ 1, 2, a ]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expect() {
|
||||
assert_expr!("expect Some(x) = something.field");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,3 +18,21 @@ pub fn parser(
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn block_basic() {
|
||||
assert_expr!(
|
||||
r#"
|
||||
let b = {
|
||||
let x = 4
|
||||
|
||||
x + 5
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,3 +12,23 @@ pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
||||
preferred_format,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn bytearray_basic() {
|
||||
assert_expr!("#[0, 170, 255]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytearray_base16() {
|
||||
assert_expr!("#\"00aaff\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytearray_utf8_encoded() {
|
||||
assert_expr!("\"aiken\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,3 +364,42 @@ pub fn parser(
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn plus_binop() {
|
||||
assert_expr!("a + 1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pipeline() {
|
||||
assert_expr!(
|
||||
r#"
|
||||
a + 2
|
||||
|> add_one
|
||||
|> add_one
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_access() {
|
||||
assert_expr!("user.name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn function_invoke() {
|
||||
assert_expr!(
|
||||
r#"
|
||||
let x = add_one(3)
|
||||
|
||||
let map_add_x = list.map(_, fn (y) { x + y })
|
||||
|
||||
map_add_x([ 1, 2, 3 ])
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
49
crates/aiken-lang/src/parser/expr/snapshots/block_basic.snap
Normal file
49
crates/aiken-lang/src/parser/expr/snapshots/block_basic.snap
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/block.rs
|
||||
description: "Code:\n\nlet b = {\n let x = 4\n\n x + 5\n}\n"
|
||||
---
|
||||
Assignment {
|
||||
location: 0..32,
|
||||
value: Sequence {
|
||||
location: 12..30,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 12..21,
|
||||
value: Int {
|
||||
location: 20..21,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
pattern: Var {
|
||||
location: 16..17,
|
||||
name: "x",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
BinOp {
|
||||
location: 25..30,
|
||||
name: AddInt,
|
||||
left: Var {
|
||||
location: 25..26,
|
||||
name: "x",
|
||||
},
|
||||
right: Int {
|
||||
location: 29..30,
|
||||
value: "5",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
pattern: Var {
|
||||
location: 4..5,
|
||||
name: "b",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/bytearray.rs
|
||||
description: "Code:\n\n#\"00aaff\""
|
||||
---
|
||||
ByteArray {
|
||||
location: 0..9,
|
||||
bytes: [
|
||||
0,
|
||||
170,
|
||||
255,
|
||||
],
|
||||
preferred_format: HexadecimalString,
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/bytearray.rs
|
||||
description: "Code:\n\n#[0, 170, 255]"
|
||||
---
|
||||
ByteArray {
|
||||
location: 0..14,
|
||||
bytes: [
|
||||
0,
|
||||
170,
|
||||
255,
|
||||
],
|
||||
preferred_format: ArrayOfBytes(
|
||||
Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
),
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/bytearray.rs
|
||||
description: "Code:\n\n\"aiken\""
|
||||
---
|
||||
ByteArray {
|
||||
location: 0..7,
|
||||
bytes: [
|
||||
97,
|
||||
105,
|
||||
107,
|
||||
101,
|
||||
110,
|
||||
],
|
||||
preferred_format: Utf8String,
|
||||
}
|
||||
36
crates/aiken-lang/src/parser/expr/snapshots/expect.snap
Normal file
36
crates/aiken-lang/src/parser/expr/snapshots/expect.snap
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Code:\n\nexpect Some(x) = something.field"
|
||||
---
|
||||
Assignment {
|
||||
location: 0..32,
|
||||
value: FieldAccess {
|
||||
location: 17..32,
|
||||
label: "field",
|
||||
container: Var {
|
||||
location: 17..26,
|
||||
name: "something",
|
||||
},
|
||||
},
|
||||
pattern: Constructor {
|
||||
is_record: false,
|
||||
location: 7..14,
|
||||
name: "Some",
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 12..13,
|
||||
value: Var {
|
||||
location: 12..13,
|
||||
name: "x",
|
||||
},
|
||||
},
|
||||
],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
tipo: (),
|
||||
},
|
||||
kind: Expect,
|
||||
annotation: None,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/mod.rs
|
||||
description: "Code:\n\nuser.name"
|
||||
---
|
||||
FieldAccess {
|
||||
location: 0..9,
|
||||
label: "name",
|
||||
container: Var {
|
||||
location: 0..4,
|
||||
name: "user",
|
||||
},
|
||||
}
|
||||
160
crates/aiken-lang/src/parser/expr/snapshots/function_invoke.snap
Normal file
160
crates/aiken-lang/src/parser/expr/snapshots/function_invoke.snap
Normal file
@@ -0,0 +1,160 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/mod.rs
|
||||
description: "Code:\n\nlet x = add_one(3)\n\nlet map_add_x = list.map(_, fn (y) { x + y })\n\nmap_add_x([ 1, 2, 3 ])\n"
|
||||
---
|
||||
Sequence {
|
||||
location: 0..89,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 0..18,
|
||||
value: Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 16..17,
|
||||
value: Int {
|
||||
location: 16..17,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: Var {
|
||||
location: 8..15,
|
||||
name: "add_one",
|
||||
},
|
||||
location: 8..18,
|
||||
},
|
||||
pattern: Var {
|
||||
location: 4..5,
|
||||
name: "x",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
Assignment {
|
||||
location: 20..65,
|
||||
value: Fn {
|
||||
location: 36..65,
|
||||
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: 45..46,
|
||||
value: Var {
|
||||
location: 45..46,
|
||||
name: "_capture__0",
|
||||
},
|
||||
},
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 48..64,
|
||||
value: Fn {
|
||||
location: 48..64,
|
||||
fn_style: Plain,
|
||||
arguments: [
|
||||
Arg {
|
||||
arg_name: Named {
|
||||
name: "y",
|
||||
label: "y",
|
||||
location: 52..53,
|
||||
is_validator_param: false,
|
||||
},
|
||||
location: 52..53,
|
||||
annotation: None,
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
body: BinOp {
|
||||
location: 57..62,
|
||||
name: AddInt,
|
||||
left: Var {
|
||||
location: 57..58,
|
||||
name: "x",
|
||||
},
|
||||
right: Var {
|
||||
location: 61..62,
|
||||
name: "y",
|
||||
},
|
||||
},
|
||||
return_annotation: None,
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: FieldAccess {
|
||||
location: 36..44,
|
||||
label: "map",
|
||||
container: Var {
|
||||
location: 36..40,
|
||||
name: "list",
|
||||
},
|
||||
},
|
||||
location: 36..65,
|
||||
},
|
||||
return_annotation: None,
|
||||
},
|
||||
pattern: Var {
|
||||
location: 24..33,
|
||||
name: "map_add_x",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 77..88,
|
||||
value: List {
|
||||
location: 77..88,
|
||||
elements: [
|
||||
Int {
|
||||
location: 79..80,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 82..83,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 85..86,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
tail: None,
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: Var {
|
||||
location: 67..76,
|
||||
name: "map_add_x",
|
||||
},
|
||||
location: 67..89,
|
||||
},
|
||||
],
|
||||
}
|
||||
95
crates/aiken-lang/src/parser/expr/snapshots/parse_tuple.snap
Normal file
95
crates/aiken-lang/src/parser/expr/snapshots/parse_tuple.snap
Normal file
@@ -0,0 +1,95 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/tuple.rs
|
||||
description: "Code:\n\nlet tuple = (1, 2, 3, 4)\ntuple.1st + tuple.2nd + tuple.3rd + tuple.4th\n"
|
||||
---
|
||||
Sequence {
|
||||
location: 0..70,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 0..24,
|
||||
value: Tuple {
|
||||
location: 12..24,
|
||||
elems: [
|
||||
Int {
|
||||
location: 13..14,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 16..17,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 19..20,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 22..23,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
pattern: Var {
|
||||
location: 4..9,
|
||||
name: "tuple",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
BinOp {
|
||||
location: 25..70,
|
||||
name: AddInt,
|
||||
left: BinOp {
|
||||
location: 25..58,
|
||||
name: AddInt,
|
||||
left: BinOp {
|
||||
location: 25..46,
|
||||
name: AddInt,
|
||||
left: TupleIndex {
|
||||
location: 25..34,
|
||||
index: 0,
|
||||
tuple: Var {
|
||||
location: 25..30,
|
||||
name: "tuple",
|
||||
},
|
||||
},
|
||||
right: TupleIndex {
|
||||
location: 37..46,
|
||||
index: 1,
|
||||
tuple: Var {
|
||||
location: 37..42,
|
||||
name: "tuple",
|
||||
},
|
||||
},
|
||||
},
|
||||
right: TupleIndex {
|
||||
location: 49..58,
|
||||
index: 2,
|
||||
tuple: Var {
|
||||
location: 49..54,
|
||||
name: "tuple",
|
||||
},
|
||||
},
|
||||
},
|
||||
right: TupleIndex {
|
||||
location: 61..70,
|
||||
index: 3,
|
||||
tuple: Var {
|
||||
location: 61..66,
|
||||
name: "tuple",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/tuple.rs
|
||||
description: "Code:\n\nlet a = foo(14)\n(a, 42)\n"
|
||||
---
|
||||
Sequence {
|
||||
location: 0..23,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 0..15,
|
||||
value: Call {
|
||||
arguments: [
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 12..14,
|
||||
value: Int {
|
||||
location: 12..14,
|
||||
value: "14",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
fun: Var {
|
||||
location: 8..11,
|
||||
name: "foo",
|
||||
},
|
||||
location: 8..15,
|
||||
},
|
||||
pattern: Var {
|
||||
location: 4..5,
|
||||
name: "a",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
Tuple {
|
||||
location: 16..23,
|
||||
elems: [
|
||||
Var {
|
||||
location: 17..18,
|
||||
name: "a",
|
||||
},
|
||||
Int {
|
||||
location: 20..22,
|
||||
value: "42",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
32
crates/aiken-lang/src/parser/expr/snapshots/pipeline.snap
Normal file
32
crates/aiken-lang/src/parser/expr/snapshots/pipeline.snap
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/mod.rs
|
||||
description: "Code:\n\na + 2\n|> add_one\n|> add_one\n"
|
||||
---
|
||||
PipeLine {
|
||||
expressions: [
|
||||
BinOp {
|
||||
location: 0..5,
|
||||
name: AddInt,
|
||||
left: Var {
|
||||
location: 0..1,
|
||||
name: "a",
|
||||
},
|
||||
right: Int {
|
||||
location: 4..5,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
Var {
|
||||
location: 9..16,
|
||||
name: "add_one",
|
||||
},
|
||||
Var {
|
||||
location: 20..27,
|
||||
name: "add_one",
|
||||
},
|
||||
],
|
||||
one_liner: false,
|
||||
}
|
||||
19
crates/aiken-lang/src/parser/expr/snapshots/plus_binop.snap
Normal file
19
crates/aiken-lang/src/parser/expr/snapshots/plus_binop.snap
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/mod.rs
|
||||
description: "Code:\n\na + 1"
|
||||
---
|
||||
BinOp {
|
||||
location: 0..5,
|
||||
name: AddInt,
|
||||
left: Var {
|
||||
location: 0..1,
|
||||
name: "a",
|
||||
},
|
||||
right: Int {
|
||||
location: 4..5,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/string.rs
|
||||
description: "Code:\n\n@\"aiken\""
|
||||
---
|
||||
String {
|
||||
location: 0..8,
|
||||
value: "aiken",
|
||||
}
|
||||
@@ -31,3 +31,13 @@ pub fn flexible(expr: UntypedExpr) -> UntypedExpr {
|
||||
_ => expr,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn string_basic() {
|
||||
assert_expr!("@\"aiken\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,3 +21,28 @@ pub fn parser(
|
||||
elems,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn parse_tuple() {
|
||||
assert_expr!(
|
||||
r#"
|
||||
let tuple = (1, 2, 3, 4)
|
||||
tuple.1st + tuple.2nd + tuple.3rd + tuple.4th
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_tuple2() {
|
||||
assert_expr!(
|
||||
r#"
|
||||
let a = foo(14)
|
||||
(a, 42)
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,3 +28,25 @@ pub fn parser(
|
||||
clauses,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::assert_expr;
|
||||
|
||||
#[test]
|
||||
fn when_basic() {
|
||||
assert_expr!(
|
||||
r#"
|
||||
when a is {
|
||||
2 if x > 1 -> 3
|
||||
1 | 4 | 5 -> {
|
||||
let amazing = 5
|
||||
amazing
|
||||
}
|
||||
3 -> 9
|
||||
_ -> 4
|
||||
}
|
||||
"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
140
crates/aiken-lang/src/parser/expr/when/snapshots/when_basic.snap
Normal file
140
crates/aiken-lang/src/parser/expr/when/snapshots/when_basic.snap
Normal file
@@ -0,0 +1,140 @@
|
||||
---
|
||||
source: crates/aiken-lang/src/parser/expr/when/mod.rs
|
||||
description: "Code:\n\nwhen a is {\n 2 if x > 1 -> 3\n 1 | 4 | 5 -> {\n let amazing = 5\n amazing\n }\n 3 -> 9\n _ -> 4\n}\n"
|
||||
---
|
||||
When {
|
||||
location: 0..102,
|
||||
subject: Var {
|
||||
location: 5..6,
|
||||
name: "a",
|
||||
},
|
||||
clauses: [
|
||||
UntypedClause {
|
||||
location: 14..29,
|
||||
patterns: [
|
||||
Int {
|
||||
location: 14..15,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
guard: Some(
|
||||
GtInt {
|
||||
location: 19..24,
|
||||
left: Var {
|
||||
location: 19..20,
|
||||
tipo: (),
|
||||
name: "x",
|
||||
},
|
||||
right: Constant(
|
||||
Int {
|
||||
location: 23..24,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
then: Int {
|
||||
location: 28..29,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
UntypedClause {
|
||||
location: 32..82,
|
||||
patterns: [
|
||||
Int {
|
||||
location: 32..33,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 36..37,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
location: 40..41,
|
||||
value: "5",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
guard: None,
|
||||
then: Sequence {
|
||||
location: 51..78,
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 51..66,
|
||||
value: Int {
|
||||
location: 65..66,
|
||||
value: "5",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
pattern: Var {
|
||||
location: 55..62,
|
||||
name: "amazing",
|
||||
},
|
||||
kind: Let,
|
||||
annotation: None,
|
||||
},
|
||||
Var {
|
||||
location: 71..78,
|
||||
name: "amazing",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
UntypedClause {
|
||||
location: 85..91,
|
||||
patterns: [
|
||||
Int {
|
||||
location: 85..86,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
guard: None,
|
||||
then: Int {
|
||||
location: 90..91,
|
||||
value: "9",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
UntypedClause {
|
||||
location: 94..100,
|
||||
patterns: [
|
||||
Discard {
|
||||
name: "_",
|
||||
location: 94..95,
|
||||
},
|
||||
],
|
||||
guard: None,
|
||||
then: Int {
|
||||
location: 99..100,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user