Get rid of Meta from tests

This commit is contained in:
greg 2019-09-20 10:10:57 -07:00
parent 71b3365de2
commit fd3922d866

View File

@ -59,8 +59,7 @@ macro_rules! decl {
macro_rules! ex { macro_rules! ex {
($expr_type:expr) => { Expression::new(ItemIdStore::new_id(), $expr_type) }; ($expr_type:expr) => { Expression::new(ItemIdStore::new_id(), $expr_type) };
(m $expr_type:expr) => { Meta::new(Expression::new(ItemIdStore::new_id(), $expr_type)) }; ($expr_type:expr, $type_anno:expr) => { Expression::with_anno(ItemIdStore::new_id(), $expr_type, $type_anno) };
(m $expr_type:expr, $type_anno:expr) => { Meta::new(Expression::with_anno(ItemIdStore::new_id(), $expr_type, $type_anno)) };
(s $expr_text:expr) => { (s $expr_text:expr) => {
{ {
let tokens: Vec<crate::tokenizing::Token> = tokenize($expr_text); let tokens: Vec<crate::tokenizing::Token> = tokenize($expr_text);
@ -81,16 +80,15 @@ macro_rules! prefexp {
($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_str($op).unwrap(), bx!(Expression::new(ItemIdStore::new_id(), $lhs).into())) } ($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_str($op).unwrap(), bx!(Expression::new(ItemIdStore::new_id(), $lhs).into())) }
} }
macro_rules! exst { macro_rules! exst {
($expr_type:expr) => { Meta::new(Statement { id: ItemIdStore::new_id(), kind: StatementKind::Expression(Expression::new(ItemIdStore::new_id(), $expr_type).into())}) }; ($expr_type:expr) => { Statement { id: ItemIdStore::new_id(), kind: StatementKind::Expression(Expression::new(ItemIdStore::new_id(), $expr_type).into())} };
($expr_type:expr, $type_anno:expr) => { Meta::new(Statement { id: ItemIdStore::new_id(), kind: StatementKind::Expression(Expression::with_anno(ItemIdStore::new_id(), $expr_type, $type_anno).into())}) }; ($expr_type:expr, $type_anno:expr) => { Statement { id: ItemIdStore::new_id(), kind: StatementKind::Expression(Expression::with_anno(ItemIdStore::new_id(), $expr_type, $type_anno).into())} };
($op:expr, $lhs:expr, $rhs:expr) => { Meta::new( ($op:expr, $lhs:expr, $rhs:expr) => { Statement { id: ItemIdStore::new_id(), ,kind: StatementKind::Expression(ex!(binexp!($op, $lhs, $rhs)))}
Statement { id: ItemIdStore::new_id(), ,kind: StatementKind::Expression(ex!(binexp!($op, $lhs, $rhs)))} };
)};
(s $statement_text:expr) => { (s $statement_text:expr) => {
{ {
let tokens: Vec<crate::tokenizing::Token> = tokenize($statement_text); let tokens: Vec<crate::tokenizing::Token> = tokenize($statement_text);
let mut parser = super::Parser::new(tokens); let mut parser = super::Parser::new(tokens);
Meta::new(parser.statement().unwrap()) parser.statement().unwrap()
} }
} }
} }
@ -170,15 +168,15 @@ fn parsing_identifiers() {
]) ])
} }
*/ */
parse_test_wrap_ast!("a[b,c]", exst!(Index { indexee: bx!(ex!(m val!("a"))), indexers: vec![ex!(m val!("b")), ex!(m val!("c"))]} )); parse_test_wrap_ast!("a[b,c]", exst!(Index { indexee: bx!(ex!(val!("a"))), indexers: vec![ex!(val!("b")), ex!(val!("c"))]} ));
parse_test_wrap_ast!("None", exst!(val!("None"))); parse_test_wrap_ast!("None", exst!(val!("None")));
parse_test_wrap_ast!("Pandas { a: x + y }", parse_test_wrap_ast!("Pandas { a: x + y }",
exst!(NamedStruct { name: Meta::new(qname!(Pandas)), fields: vec![(rc!(a), ex!(m binexp!("+", val!("x"), val!("y"))))]}) exst!(NamedStruct { name: qname!(Pandas), fields: vec![(rc!(a), ex!(binexp!("+", val!("x"), val!("y"))))]})
); );
parse_test_wrap_ast! { "Pandas { a: n, b: q, }", parse_test_wrap_ast! { "Pandas { a: n, b: q, }",
exst!(NamedStruct { name: Meta::new(qname!(Pandas)), fields: exst!(NamedStruct { name: qname!(Pandas), fields:
vec![(rc!(a), ex!(m val!("n"))), (rc!(b), ex!(m val!("q")))] vec![(rc!(a), ex!(val!("n"))), (rc!(b), ex!(val!("q")))]
} }
) )
}; };
@ -189,14 +187,14 @@ fn parsing_identifiers() {
fn qualified_identifiers() { fn qualified_identifiers() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"let q_q = Yolo::Swaggins", "let q_q = Yolo::Swaggins",
Meta::new(decl!(Binding { name: rc!(q_q), constant: true, type_anno: None, decl!(Binding { name: rc!(q_q), constant: true, type_anno: None,
expr: Meta::new(Expression::new(ItemIdStore::new_id(), Value(qname!(Yolo, Swaggins)))), expr: Expression::new(ItemIdStore::new_id(), Value(qname!(Yolo, Swaggins))),
})) })
} }
parse_test_wrap_ast! { parse_test_wrap_ast! {
"thing::item::call()", "thing::item::call()",
exst!(Call { f: bx![ex!(m Value(qname!(thing, item, call)))], arguments: vec![] }) exst!(Call { f: bx![ex!(Value(qname!(thing, item, call)))], arguments: vec![] })
} }
} }
@ -224,36 +222,36 @@ fn parsing_complicated_operators() {
#[test] #[test]
fn parsing_functions() { fn parsing_functions() {
parse_test_wrap_ast!("fn oi()", Meta::new(decl!(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None })))); parse_test_wrap_ast!("fn oi()", decl!(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None })));
parse_test_wrap_ast!("oi()", exst!(Call { f: bx!(ex!(m val!("oi"))), arguments: vec![] })); parse_test_wrap_ast!("oi()", exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] }));
parse_test_wrap_ast!("oi(a, 2 + 2)", exst!(Call parse_test_wrap_ast!("oi(a, 2 + 2)", exst!(Call
{ f: bx!(ex!(m val!("oi"))), { f: bx!(ex!(val!("oi"))),
arguments: vec![inv!(ex!(m val!("a"))), inv!(ex!(m binexp!("+", NatLiteral(2), NatLiteral(2)))).into()] arguments: vec![inv!(ex!(val!("a"))), inv!(ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))).into()]
})); }));
parse_error!("a(b,,c)"); parse_error!("a(b,,c)");
parse_test_wrap_ast!("fn a(b, c: Int): Int", Meta::new(decl!( parse_test_wrap_ast!("fn a(b, c: Int): Int", decl!(
FuncSig(Signature { name: rc!(a), operator: false, params: vec![ FuncSig(Signature { name: rc!(a), operator: false, params: vec![
FormalParam { name: rc!(b), anno: None, default: None }, FormalParam { name: rc!(b), anno: None, default: None },
FormalParam { name: rc!(c), anno: Some(ty!("Int")), default: None } FormalParam { name: rc!(c), anno: Some(ty!("Int")), default: None }
], type_anno: Some(ty!("Int")) })))); ], type_anno: Some(ty!("Int")) })));
parse_test_wrap_ast!("fn a(x) { x() }", Meta::new(decl!( parse_test_wrap_ast!("fn a(x) { x() }", decl!(
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), anno: None, default: None }], type_anno: None }, FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), anno: None, default: None }], type_anno: None },
vec![exst!(Call { f: bx!(ex!(m val!("x"))), arguments: vec![] })])))); vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])));
parse_test_wrap_ast!("fn a(x) {\n x() }", Meta::new(decl!( parse_test_wrap_ast!("fn a(x) {\n x() }", decl!(
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), anno: None, default: None }], type_anno: None }, FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), anno: None, default: None }], type_anno: None },
vec![exst!(Call { f: bx!(ex!(m val!("x"))), arguments: vec![] })])))); vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])));
let multiline = r#" let multiline = r#"
fn a(x) { fn a(x) {
x() x()
} }
"#; "#;
parse_test_wrap_ast!(multiline, Meta::new(decl!( parse_test_wrap_ast!(multiline, decl!(
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), default: None, anno: None }], type_anno: None }, FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), default: None, anno: None }], type_anno: None },
vec![exst!(Call { f: bx!(ex!(m val!("x"))), arguments: vec![] })])))); vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])));
let multiline2 = r#" let multiline2 = r#"
fn a(x) { fn a(x) {
@ -261,21 +259,21 @@ x()
} }
"#; "#;
parse_test_wrap_ast!(multiline2, Meta::new(decl!( parse_test_wrap_ast!(multiline2, decl!(
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), default: None, anno: None }], type_anno: None }, FuncDecl(Signature { name: rc!(a), operator: false, params: vec![FormalParam { name: rc!(x), default: None, anno: None }], type_anno: None },
vec![exst!(s "x()")])))); vec![exst!(s "x()")])));
} }
#[test] #[test]
fn functions_with_default_args() { fn functions_with_default_args() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"fn func(x: Int, y: Int = 4) { }", "fn func(x: Int, y: Int = 4) { }",
Meta::new(decl!( decl!(
FuncDecl(Signature { name: rc!(func), operator: false, type_anno: None, params: vec![ FuncDecl(Signature { name: rc!(func), operator: false, type_anno: None, params: vec![
FormalParam { name: rc!(x), default: None, anno: Some(ty!("Int")) }, FormalParam { name: rc!(x), default: None, anno: Some(ty!("Int")) },
FormalParam { name: rc!(y), default: Some(Meta::new(ex!(s "4"))), anno: Some(ty!("Int")) } FormalParam { name: rc!(y), default: Some(ex!(s "4")), anno: Some(ty!("Int")) }
]}, vec![]) ]}, vec![])
)) )
}; };
} }
@ -292,11 +290,11 @@ fn parsing_strings() {
#[test] #[test]
fn parsing_types() { fn parsing_types() {
parse_test_wrap_ast!("type Yolo = Yolo", Meta::new(decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: false} ))); parse_test_wrap_ast!("type Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: false} ));
parse_test_wrap_ast!("type mut Yolo = Yolo", Meta::new(decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: true} ))); parse_test_wrap_ast!("type mut Yolo = Yolo", decl!(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: true} ));
parse_test_wrap_ast!("type alias Sex = Drugs", Meta::new(decl!(TypeAlias(rc!(Sex), rc!(Drugs))))); parse_test_wrap_ast!("type alias Sex = Drugs", decl!(TypeAlias(rc!(Sex), rc!(Drugs))));
parse_test_wrap_ast!("type Sanchez = Miguel | Alejandro(Int, Option<a>) | Esperanza { a: Int, b: String }", parse_test_wrap_ast!("type Sanchez = Miguel | Alejandro(Int, Option<a>) | Esperanza { a: Int, b: String }",
Meta::new(decl!(TypeDecl { decl!(TypeDecl {
name: tys!("Sanchez"), name: tys!("Sanchez"),
body: TypeBody(vec![ body: TypeBody(vec![
UnitStruct(rc!(Miguel)), UnitStruct(rc!(Miguel)),
@ -313,27 +311,27 @@ fn parsing_types() {
} }
]), ]),
mutable: false mutable: false
}))); }));
parse_test_wrap_ast! { parse_test_wrap_ast! {
"type Jorge<a> = Diego | Kike(a)", "type Jorge<a> = Diego | Kike(a)",
Meta::new(decl!(TypeDecl{ decl!(TypeDecl{
name: TypeSingletonName { name: rc!(Jorge), params: vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })] }, name: TypeSingletonName { name: rc!(Jorge), params: vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })] },
body: TypeBody(vec![UnitStruct(rc!(Diego)), TupleStruct(rc!(Kike), vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })])]), body: TypeBody(vec![UnitStruct(rc!(Diego)), TupleStruct(rc!(Kike), vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })])]),
mutable: false mutable: false
} }
)) )
}; };
} }
#[test] #[test]
fn parsing_bindings() { fn parsing_bindings() {
parse_test_wrap_ast!("let mut a = 10", Meta::new(decl!(Binding { name: rc!(a), constant: false, type_anno: None, expr: ex!(m NatLiteral(10)) } ))); parse_test_wrap_ast!("let mut a = 10", decl!(Binding { name: rc!(a), constant: false, type_anno: None, expr: ex!(NatLiteral(10)) } ));
parse_test_wrap_ast!("let a = 2 + 2", Meta::new(decl!(Binding { name: rc!(a), constant: true, type_anno: None, expr: ex!(m binexp!("+", NatLiteral(2), NatLiteral(2))) }) )); parse_test_wrap_ast!("let a = 2 + 2", decl!(Binding { name: rc!(a), constant: true, type_anno: None, expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) }));
parse_test_wrap_ast!("let a: Nat = 2 + 2", Meta::new(decl!( parse_test_wrap_ast!("let a: Nat = 2 + 2", decl!(
Binding { name: rc!(a), constant: true, type_anno: Some(Singleton(TypeSingletonName { name: rc!(Nat), params: vec![] })), Binding { name: rc!(a), constant: true, type_anno: Some(Singleton(TypeSingletonName { name: rc!(Nat), params: vec![] })),
expr: Meta::new(ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))) } expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) }
))); ));
} }
#[test] #[test]
@ -342,11 +340,11 @@ fn parsing_block_expressions() {
"if a() then { b(); c() }", exst!( "if a() then { b(); c() }", exst!(
IfExpression { IfExpression {
discriminator: bx! { discriminator: bx! {
Discriminator::Simple(ex!(m Call { f: bx!(ex!(m val!("a"))), arguments: vec![]})) Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
}, },
body: bx! { body: bx! {
IfExpressionBody::SimpleConditional( IfExpressionBody::SimpleConditional(
vec![exst!(Call { f: bx!(ex!(m val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(m val!("c"))), arguments: vec![] })], vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
None None
) )
} }
@ -358,11 +356,11 @@ fn parsing_block_expressions() {
"if a() then { b(); c() } else { q }", exst!( "if a() then { b(); c() } else { q }", exst!(
IfExpression { IfExpression {
discriminator: bx! { discriminator: bx! {
Discriminator::Simple(ex!(m Call { f: bx!(ex!(m val!("a"))), arguments: vec![]})) Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
}, },
body: bx! { body: bx! {
IfExpressionBody::SimpleConditional( IfExpressionBody::SimpleConditional(
vec![exst!(Call { f: bx!(ex!(m val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(m val!("c"))), arguments: vec![] })], vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
Some( Some(
vec![exst!(val!("q"))], vec![exst!(val!("q"))],
) )
@ -407,69 +405,66 @@ fn parsing_block_expressions() {
#[test] #[test]
fn parsing_interfaces() { fn parsing_interfaces() {
parse_test_wrap_ast!("interface Unglueable { fn unglue(a: Glue); fn mar(): Glue }", parse_test_wrap_ast!("interface Unglueable { fn unglue(a: Glue); fn mar(): Glue }",
Meta::new(decl!(Interface { decl!(Interface {
name: rc!(Unglueable), name: rc!(Unglueable),
signatures: vec![ signatures: vec![
Signature { Signature {
name: rc!(unglue), name: rc!(unglue),
operator: false, operator: false,
params: vec![ params: vec![
FormalParam { name: rc!(a), anno: Some(Singleton(TypeSingletonName { name: rc!(Glue), params: vec![] })), default: None } FormalParam { name: rc!(a), anno: Some(Singleton(TypeSingletonName { name: rc!(Glue), params: vec![] })), default: None }
], ],
type_anno: None type_anno: None
}, },
Signature { name: rc!(mar), operator: false, params: vec![], type_anno: Some(Singleton(TypeSingletonName { name: rc!(Glue), params: vec![] })) }, Signature { name: rc!(mar), operator: false, params: vec![], type_anno: Some(Singleton(TypeSingletonName { name: rc!(Glue), params: vec![] })) },
] ]
})) })
); );
} }
#[test] #[test]
fn parsing_impls() { fn parsing_impls() {
parse_test_wrap_ast!("impl Heh { fn yolo(); fn swagg(); }", parse_test_wrap_ast!("impl Heh { fn yolo(); fn swagg(); }",
Meta::new( decl!(Impl {
decl!(Impl { type_name: ty!("Heh"),
type_name: ty!("Heh"), interface_name: None,
interface_name: None, block: vec![
block: vec![ FuncSig(Signature { name: rc!(yolo), operator: false, params: vec![], type_anno: None }),
FuncSig(Signature { name: rc!(yolo), operator: false, params: vec![], type_anno: None }), FuncSig(Signature { name: rc!(swagg), operator: false, params: vec![], type_anno: None })
FuncSig(Signature { name: rc!(swagg), operator: false, params: vec![], type_anno: None }) ] }));
] })));
parse_test_wrap_ast!("impl Mondai for Lollerino { fn yolo(); fn swagg(); }", parse_test_wrap_ast!("impl Mondai for Lollerino { fn yolo(); fn swagg(); }",
Meta::new(decl!(Impl { decl!(Impl {
type_name: ty!("Lollerino"), type_name: ty!("Lollerino"),
interface_name: Some(TypeSingletonName { name: rc!(Mondai), params: vec![] }), interface_name: Some(TypeSingletonName { name: rc!(Mondai), params: vec![] }),
block: vec![ block: vec![
FuncSig(Signature { name: rc!(yolo), operator: false, params: vec![], type_anno: None}), FuncSig(Signature { name: rc!(yolo), operator: false, params: vec![], type_anno: None}),
FuncSig(Signature { name: rc!(swagg), operator: false, params: vec![], type_anno: None }) FuncSig(Signature { name: rc!(swagg), operator: false, params: vec![], type_anno: None })
] }))); ] }));
parse_test_wrap_ast!("impl Hella<T> for (Alpha, Omega) { }", parse_test_wrap_ast!("impl Hella<T> for (Alpha, Omega) { }",
Meta::new(decl!(Impl { decl!(Impl {
type_name: Tuple(vec![ty!("Alpha"), ty!("Omega")]), type_name: Tuple(vec![ty!("Alpha"), ty!("Omega")]),
interface_name: Some(TypeSingletonName { name: rc!(Hella), params: vec![ty!("T")] }), interface_name: Some(TypeSingletonName { name: rc!(Hella), params: vec![ty!("T")] }),
block: vec![] block: vec![]
})) })
); );
parse_test_wrap_ast!("impl Option<WTFMate> { fn oi() }", parse_test_wrap_ast!("impl Option<WTFMate> { fn oi() }",
Meta::new( decl!(Impl {
decl!(Impl { type_name: Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("WTFMate")]}),
type_name: Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("WTFMate")]}), interface_name: None,
interface_name: None, block: vec![
block: vec![ FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None }),
FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None }), ]
] }));
})));
} }
#[test] #[test]
fn parsing_type_annotations() { fn parsing_type_annotations() {
parse_test_wrap_ast!("let a = b : Int", parse_test_wrap_ast!("let a = b : Int",
Meta::new(
decl!(Binding { name: rc!(a), constant: true, type_anno: None, expr: decl!(Binding { name: rc!(a), constant: true, type_anno: None, expr:
ex!(m val!("b"), ty!("Int")) }))); ex!(val!("b"), ty!("Int")) }));
parse_test_wrap_ast!("a : Int", parse_test_wrap_ast!("a : Int",
exst!(val!("a"), ty!("Int")) exst!(val!("a"), ty!("Int"))
@ -511,7 +506,7 @@ fn parsing_lambdas() {
); );
parse_test_wrap_ast! { r#"\(x){y}(1)"#, parse_test_wrap_ast! { r#"\(x){y}(1)"#,
exst!(Call { f: bx!(ex!(m exst!(Call { f: bx!(ex!(
Lambda { Lambda {
params: vec![ params: vec![
FormalParam { name: rc!(x), anno: None, default: None } FormalParam { name: rc!(x), anno: None, default: None }
@ -519,7 +514,7 @@ fn parsing_lambdas() {
type_anno: None, type_anno: None,
body: vec![exst!(s "y")] } body: vec![exst!(s "y")] }
)), )),
arguments: vec![inv!(ex!(m NatLiteral(1))).into()] }) arguments: vec![inv!(ex!(NatLiteral(1))).into()] })
}; };
parse_test_wrap_ast! { parse_test_wrap_ast! {
@ -566,8 +561,8 @@ fn more_advanced_lambdas() {
exst!(s r"fn wahoo() { let a = 10; \(x) { x + a } }"), exst!(s r"fn wahoo() { let a = 10; \(x) { x + a } }"),
exst! { exst! {
Call { Call {
f: bx!(ex!(m Call { f: bx!(ex!(m val!("wahoo"))), arguments: vec![] })), f: bx!(ex!(Call { f: bx!(ex!(val!("wahoo"))), arguments: vec![] })),
arguments: vec![inv!(ex!(m NatLiteral(3))).into()], arguments: vec![inv!(ex!(NatLiteral(3))).into()],
} }
} }
] ]
@ -579,7 +574,7 @@ fn more_advanced_lambdas() {
fn list_literals() { fn list_literals() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"[1,2]", "[1,2]",
exst!(ListLiteral(vec![ex!(m NatLiteral(1)), ex!(m NatLiteral(2))])) exst!(ListLiteral(vec![ex!(NatLiteral(1)), ex!(NatLiteral(2))]))
}; };
} }
@ -592,7 +587,7 @@ fn while_expr() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"while a == b { }", "while a == b { }",
exst!(WhileExpression { condition: Some(bx![ex![m binexp!("==", val!("a"), val!("b"))]]), body: vec![] }) exst!(WhileExpression { condition: Some(bx![ex![binexp!("==", val!("a"), val!("b"))]]), body: vec![] })
} }
} }
@ -619,7 +614,7 @@ fn patterns() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"if x is Some(a) then { 4 } else { 9 }", exst!( "if x is Some(a) then { 4 } else { 9 }", exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some), body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some),
vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) }
) )
@ -628,7 +623,7 @@ fn patterns() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"if x is Some(a) then 4 else 9", exst!( "if x is Some(a) then 4 else 9", exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some), body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some),
vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) } vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) }
) )
@ -637,7 +632,7 @@ fn patterns() {
parse_test_wrap_ast! { parse_test_wrap_ast! {
"if x is Something { a, b: x } then { 4 } else { 9 }", exst!( "if x is Something { a, b: x } then { 4 } else { 9 }", exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch( body: bx!(IfExpressionBody::SimplePatternMatch(
Pattern::Record(qname!(Something), vec![ Pattern::Record(qname!(Something), vec![
(rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))), (rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))),
@ -655,7 +650,7 @@ fn pattern_literals() {
"if x is -1 then 1 else 2", "if x is -1 then 1 else 2",
exst!( exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch( body: bx!(IfExpressionBody::SimplePatternMatch(
Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }), Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }),
vec![exst!(NatLiteral(1))], vec![exst!(NatLiteral(1))],
@ -669,7 +664,7 @@ fn pattern_literals() {
"if x is 1 then 1 else 2", "if x is 1 then 1 else 2",
exst!( exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch( body: bx!(IfExpressionBody::SimplePatternMatch(
Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }), Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }),
vec![exst!(s "1")], vec![exst!(s "1")],
@ -683,7 +678,7 @@ fn pattern_literals() {
"if x is true then 1 else 2", "if x is true then 1 else 2",
exst!( exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch( body: bx!(IfExpressionBody::SimplePatternMatch(
Pattern::Literal(PatternLiteral::BoolPattern(true)), Pattern::Literal(PatternLiteral::BoolPattern(true)),
vec![exst!(NatLiteral(1))], vec![exst!(NatLiteral(1))],
@ -697,7 +692,7 @@ fn pattern_literals() {
"if x is \"gnosticism\" then 1 else 2", "if x is \"gnosticism\" then 1 else 2",
exst!( exst!(
IfExpression { IfExpression {
discriminator: bx!(Discriminator::Simple(Meta::new(ex!(s "x")))), discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
body: bx!(IfExpressionBody::SimplePatternMatch( body: bx!(IfExpressionBody::SimplePatternMatch(
Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))), Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
vec![exst!(s "1")], vec![exst!(s "1")],