fix: format snapshot tests
This commit is contained in:
parent
7f26db401c
commit
00907c2bcc
|
@ -232,7 +232,15 @@ impl<'comments> Formatter<'comments> {
|
||||||
return_annotation,
|
return_annotation,
|
||||||
end_position,
|
end_position,
|
||||||
..
|
..
|
||||||
}) => self.definition_fn(public, name, args, return_annotation, body, *end_position),
|
}) => self.definition_fn(
|
||||||
|
public,
|
||||||
|
name,
|
||||||
|
args,
|
||||||
|
return_annotation,
|
||||||
|
body,
|
||||||
|
*end_position,
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
|
||||||
Definition::Validator(Validator {
|
Definition::Validator(Validator {
|
||||||
end_position,
|
end_position,
|
||||||
|
@ -513,12 +521,18 @@ impl<'comments> Formatter<'comments> {
|
||||||
return_annotation: &'a Option<Annotation>,
|
return_annotation: &'a Option<Annotation>,
|
||||||
body: &'a UntypedExpr,
|
body: &'a UntypedExpr,
|
||||||
end_location: usize,
|
end_location: usize,
|
||||||
|
is_validator: bool,
|
||||||
) -> Document<'a> {
|
) -> Document<'a> {
|
||||||
// Fn name and args
|
// Fn name and args
|
||||||
let head = pub_(*public)
|
let head = if !is_validator {
|
||||||
.append("fn ")
|
pub_(*public)
|
||||||
.append(name)
|
.append("fn ")
|
||||||
.append(wrap_args(args.iter().map(|e| (self.fn_arg(e), false))));
|
.append(name)
|
||||||
|
.append(wrap_args(args.iter().map(|e| (self.fn_arg(e), false))))
|
||||||
|
} else {
|
||||||
|
name.to_doc()
|
||||||
|
.append(wrap_args(args.iter().map(|e| (self.fn_arg(e), false))))
|
||||||
|
};
|
||||||
|
|
||||||
// Add return annotation
|
// Add return annotation
|
||||||
let head = match return_annotation {
|
let head = match return_annotation {
|
||||||
|
@ -613,6 +627,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
&handler.return_annotation,
|
&handler.return_annotation,
|
||||||
&handler.body,
|
&handler.body,
|
||||||
handler.end_position,
|
handler.end_position,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
.group();
|
.group();
|
||||||
|
|
||||||
|
@ -632,6 +647,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
&fallback.return_annotation,
|
&fallback.return_annotation,
|
||||||
&fallback.body,
|
&fallback.body,
|
||||||
fallback.end_position,
|
fallback.end_position,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
.group();
|
.group();
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ Validator(
|
||||||
},
|
},
|
||||||
doc: None,
|
doc: None,
|
||||||
location: 0..0,
|
location: 0..0,
|
||||||
name: "fallback",
|
name: "else",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: None,
|
||||||
return_type: (),
|
return_type: (),
|
||||||
|
|
|
@ -87,7 +87,7 @@ Validator(
|
||||||
},
|
},
|
||||||
doc: None,
|
doc: None,
|
||||||
location: 0..0,
|
location: 0..0,
|
||||||
name: "fallback",
|
name: "else",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: None,
|
||||||
return_type: (),
|
return_type: (),
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
|
||||||
doc: None,
|
doc: None,
|
||||||
location: ast::Span::empty(),
|
location: ast::Span::empty(),
|
||||||
end_position: span.end - 1,
|
end_position: span.end - 1,
|
||||||
name: "fallback".to_string(),
|
name: "else".to_string(),
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: None,
|
||||||
return_type: (),
|
return_type: (),
|
||||||
|
|
|
@ -111,8 +111,8 @@ fn bls12_381_ml_result_in_data_type() {
|
||||||
#[test]
|
#[test]
|
||||||
fn validator_illegal_return_type() {
|
fn validator_illegal_return_type() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator {
|
validator foo {
|
||||||
fn foo(d, r, c) {
|
spend(d, r, c) {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,8 +140,8 @@ fn implicitly_discard_void() {
|
||||||
#[test]
|
#[test]
|
||||||
fn validator_illegal_arity() {
|
fn validator_illegal_arity() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator {
|
validator foo {
|
||||||
fn foo(c) {
|
mint(c) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,8 +318,8 @@ fn mark_constructors_as_used_via_field_access() {
|
||||||
bar: Int,
|
bar: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
validator {
|
validator foo {
|
||||||
fn foo(d: Datum, _r, _c) {
|
spend(d: Datum, _r, _c) {
|
||||||
when d is {
|
when d is {
|
||||||
D0(params) -> params.foo == 1
|
D0(params) -> params.foo == 1
|
||||||
D1(_params) -> False
|
D1(_params) -> False
|
||||||
|
@ -359,8 +359,8 @@ fn expect_multi_patterns() {
|
||||||
#[test]
|
#[test]
|
||||||
fn validator_correct_form() {
|
fn validator_correct_form() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator {
|
validator foo {
|
||||||
fn foo(d, r, c) {
|
spend(d, r, c) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,8 +372,8 @@ fn validator_correct_form() {
|
||||||
#[test]
|
#[test]
|
||||||
fn validator_in_lib_warning() {
|
fn validator_in_lib_warning() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator {
|
validator foo {
|
||||||
fn foo(c) {
|
spend(c) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -390,12 +390,12 @@ fn validator_in_lib_warning() {
|
||||||
#[test]
|
#[test]
|
||||||
fn multi_validator() {
|
fn multi_validator() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator(foo: ByteArray, bar: Int) {
|
validator foo(foo: ByteArray, bar: Int) {
|
||||||
fn spend(_d, _r, _c) {
|
spend(_d, _r, _c) {
|
||||||
foo == #"aabb"
|
foo == #"aabb"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mint(_r, _c) {
|
mint(_r, _c) {
|
||||||
bar == 0
|
bar == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,12 +409,12 @@ fn multi_validator() {
|
||||||
#[test]
|
#[test]
|
||||||
fn multi_validator_warning() {
|
fn multi_validator_warning() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator(foo: ByteArray, bar: Int) {
|
validator foo(foo: ByteArray, bar: Int) {
|
||||||
fn spend(_d, _r, _c) {
|
spend(_d, _r, _c) {
|
||||||
foo == #"aabb"
|
foo == #"aabb"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mint(_r, _c) {
|
mint(_r, _c) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -460,7 +460,7 @@ fn exhaustiveness_simple() {
|
||||||
fn validator_args_no_annotation() {
|
fn validator_args_no_annotation() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator hello(d) {
|
validator hello(d) {
|
||||||
foo (a, b, c) {
|
spend(a, b, c) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2472,8 +2472,8 @@ fn validator_private_type_leak() {
|
||||||
bar: Int,
|
bar: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
validator {
|
validator bar {
|
||||||
pub fn bar(datum: Datum, redeemer: Redeemer, _ctx) {
|
spend(datum: Datum, redeemer: Redeemer, _ctx) {
|
||||||
datum.foo == redeemer.bar
|
datum.foo == redeemer.bar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2496,8 +2496,8 @@ fn validator_public() {
|
||||||
bar: Int,
|
bar: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
validator {
|
validator bar {
|
||||||
pub fn bar(datum: Datum, redeemer: Redeemer, _ctx) {
|
spend(datum: Datum, redeemer: Redeemer, _ctx) {
|
||||||
datum.foo == redeemer.bar
|
datum.foo == redeemer.bar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2517,8 +2517,8 @@ fn validator_private_everything() {
|
||||||
bar: Int,
|
bar: Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
validator {
|
validator bar {
|
||||||
fn bar(datum: Datum, redeemer: Redeemer, _ctx) {
|
spend(datum: Datum, redeemer: Redeemer, _ctx) {
|
||||||
datum.foo == redeemer.bar
|
datum.foo == redeemer.bar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,18 +198,18 @@ fn format_preserve_newline_after_bool_expect() {
|
||||||
fn format_validator() {
|
fn format_validator() {
|
||||||
assert_format!(
|
assert_format!(
|
||||||
r#"
|
r#"
|
||||||
validator ( ) {
|
validator thing ( ) {
|
||||||
// What is the purpose of life
|
// What is the purpose of life
|
||||||
|
|
||||||
fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// What?
|
// What?
|
||||||
validator {
|
validator foo {
|
||||||
/// Some documentation for foo
|
/// Some documentation for foo
|
||||||
fn foo() {
|
foo() {
|
||||||
Void
|
Void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,12 +223,12 @@ fn format_validator() {
|
||||||
fn format_double_validator() {
|
fn format_double_validator() {
|
||||||
assert_format!(
|
assert_format!(
|
||||||
r#"
|
r#"
|
||||||
validator ( param1 : ByteArray ) {
|
validator foo( param1 : ByteArray ) {
|
||||||
fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
/// This is bar
|
/// This is bar
|
||||||
fn bar(r: Redeemer, ctx : ScriptContext ) -> Bool { True }
|
mint(r: Redeemer, ctx : ScriptContext ) -> Bool { True }
|
||||||
}
|
}
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
@ -238,12 +238,12 @@ fn format_double_validator() {
|
||||||
fn format_double_validator_public() {
|
fn format_double_validator_public() {
|
||||||
assert_format!(
|
assert_format!(
|
||||||
r#"
|
r#"
|
||||||
validator ( param1 : ByteArray ) {
|
validator foo ( param1 : ByteArray ) {
|
||||||
pub fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
/// This is bar
|
/// This is bar
|
||||||
pub fn bar(r: Redeemer, ctx : ScriptContext ) -> Bool { True }
|
mint(r: Redeemer, ctx : ScriptContext ) -> Bool { True }
|
||||||
}
|
}
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
@ -967,20 +967,20 @@ fn format_anon_fn_pattern() {
|
||||||
fn format_validator_pattern() {
|
fn format_validator_pattern() {
|
||||||
assert_format!(
|
assert_format!(
|
||||||
r#"
|
r#"
|
||||||
validator(Foo { a, b, .. }) {
|
validator foo(Foo { a, b, .. }) {
|
||||||
fn foo() { todo }
|
spend() { todo }
|
||||||
}
|
}
|
||||||
|
|
||||||
validator([Bar] : List<Bar>) {
|
validator foo([Bar] : List<Bar>) {
|
||||||
fn bar() { todo }
|
spend() { todo }
|
||||||
}
|
}
|
||||||
|
|
||||||
validator((Baz, Baz) as x) {
|
validator foo((Baz, Baz) as x) {
|
||||||
fn baz() { todo }
|
mint() { todo }
|
||||||
}
|
}
|
||||||
|
|
||||||
validator((fst, snd) as x: Pair<Int, Int>) {
|
validator fiz((fst, snd) as x: Pair<Int, Int>) {
|
||||||
fn fiz() { todo }
|
spend() { todo }
|
||||||
}
|
}
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-lang/src/tests/format.rs
|
source: crates/aiken-lang/src/tests/format.rs
|
||||||
description: "Code:\n\n validator ( param1 : ByteArray ) {\n fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\nfn bar(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
description: "Code:\n\n validator foo( param1 : ByteArray ) {\n spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\nmint(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
||||||
---
|
---
|
||||||
validator(param1: ByteArray) {
|
validator foo(param1: ByteArray) {
|
||||||
fn foo(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is bar
|
/// This is bar
|
||||||
fn bar(r: Redeemer, ctx: ScriptContext) -> Bool {
|
mint(r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-lang/src/tests/format.rs
|
source: crates/aiken-lang/src/tests/format.rs
|
||||||
description: "Code:\n\n validator ( param1 : ByteArray ) {\n pub fn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\npub fn bar(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
description: "Code:\n\n validator foo ( param1 : ByteArray ) {\n spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\nmint(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
||||||
---
|
---
|
||||||
validator(param1: ByteArray) {
|
validator foo(param1: ByteArray) {
|
||||||
pub fn foo(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is bar
|
/// This is bar
|
||||||
pub fn bar(r: Redeemer, ctx: ScriptContext) -> Bool {
|
mint(r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,28 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-lang/src/tests/format.rs
|
source: crates/aiken-lang/src/tests/format.rs
|
||||||
description: "Code:\n\nvalidator ( ) {\n// What is the purpose of life\n\nfn foo (d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\nTrue\n}\n}\n\n// What?\nvalidator {\n /// Some documentation for foo\n fn foo() {\n Void\n }\n\n // I am lost\n}\n"
|
description: "Code:\n\nvalidator thing ( ) {\n// What is the purpose of life\n\nspend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\nTrue\n}\n}\n\n// What?\nvalidator foo {\n /// Some documentation for foo\n foo() {\n Void\n }\n\n // I am lost\n}\n"
|
||||||
---
|
---
|
||||||
validator {
|
validator thing {
|
||||||
// What is the purpose of life
|
// What is the purpose of life
|
||||||
|
|
||||||
fn foo(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// What?
|
// What?
|
||||||
validator {
|
validator foo {
|
||||||
/// Some documentation for foo
|
/// Some documentation for foo
|
||||||
fn foo() {
|
foo() {
|
||||||
Void
|
Void
|
||||||
}
|
}
|
||||||
|
|
||||||
// I am lost
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
// I am lost
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,43 @@
|
||||||
---
|
---
|
||||||
source: crates/aiken-lang/src/tests/format.rs
|
source: crates/aiken-lang/src/tests/format.rs
|
||||||
description: "Code:\n\nvalidator(Foo { a, b, .. }) {\n fn foo() { todo }\n}\n\nvalidator([Bar] : List<Bar>) {\n fn bar() { todo }\n}\n\nvalidator((Baz, Baz) as x) {\n fn baz() { todo }\n}\n\nvalidator((fst, snd) as x: Pair<Int, Int>) {\n fn fiz() { todo }\n}\n"
|
description: "Code:\n\nvalidator foo(Foo { a, b, .. }) {\n spend() { todo }\n}\n\nvalidator foo([Bar] : List<Bar>) {\n spend() { todo }\n}\n\nvalidator foo((Baz, Baz) as x) {\n mint() { todo }\n}\n\nvalidator fiz((fst, snd) as x: Pair<Int, Int>) {\n spend() { todo }\n}\n"
|
||||||
---
|
---
|
||||||
validator(Foo { a, b, .. }) {
|
validator foo(Foo { a, b, .. }) {
|
||||||
fn foo() {
|
spend() {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validator([Bar]: List<Bar>) {
|
validator foo([Bar]: List<Bar>) {
|
||||||
fn bar() {
|
spend() {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validator((Baz, Baz) as x) {
|
validator foo((Baz, Baz) as x) {
|
||||||
fn baz() {
|
mint() {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validator((fst, snd) as x: Pair<Int, Int>) {
|
validator fiz((fst, snd) as x: Pair<Int, Int>) {
|
||||||
fn fiz() {
|
spend() {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else(_ctx) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue