Skip to content

Commit

Permalink
adds enum paths, spread operator, more enum tests, fixes move_or_copy…
Browse files Browse the repository at this point in the history
… precedence
  • Loading branch information
damirka committed Jul 28, 2024
1 parent a634a00 commit 9709700
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier-plugin-move",
"version": "0.0.23",
"version": "0.0.24",
"license": "Apache-2.0",
"keywords": [
"prettier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ function printBindFields(path: AstPath<Node>, options: ParserOptions, print: pri
* Print `bind_field` node.
*/
function printBindField(path: AstPath<Node>, options: ParserOptions, print: printFn): Doc {
// special case for `..` operator
if (path.node.child(0)?.type == '..') {
return '..';
}

const nonFormatting = path.node.nonFormattingChildren;
const isMut = !!path.node.children.find((c) => c.text === 'mut');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// options:
// printWidth: 40

module tests::enum {
public enum Test {
A,
B,
C,
}

public enum Test<phantom C> {
A(u8, u64),
C(u8),
B { a: u8, b: u64 },
}

fun use_enum() {
let _local = tests::enum::test::A(
10,
1000,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// options:
// printWidth: 40

module tests::enum {
public enum Test {
A,
B,
C,
}

public enum Test<phantom C> { A(u8, u64), C(u8), B { a: u8, b: u64 }, }

fun use_enum() {
let _local = tests::enum::test::A(10, 1000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// options:
// printWidth: 40

/// Module: kek
module kek::kek {
public struct Kek {
a: u8,
b: u64,
}

public fun destroy(
k1: Kek,
k2: Kek,
) {
let Kek { a, .. } = k1;
let Kek { .. } = k2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// options:
// printWidth: 40

/// Module: kek
module kek::kek {
public struct Kek {
a: u8,
b: u64,
}

public fun destroy(k1: Kek, k2: Kek) {
let Kek { a, .. } = k1;
let Kek { .. } = k2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module prettier::expression {
*&a = 100;
a = (copy b);
b = (move c);

*df::borrow_mut<A, B>() =
another_call();
(a, b) = (1, 2);
Expand Down Expand Up @@ -267,6 +268,7 @@ module prettier::expression {
who_you_gonna_call[
(first_arg, second_arg)
];
result.push_back(copy data[i]);
}

fun expression_list() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module prettier::pattern_matching {
MyEnum::Variant(_, _) => 1,
MyEnum::OtherVariant(_, ERROR) => 2,
// Now exhaustive since this will match all values of MyEnum::OtherVariant
MyEnum::OtherVariant(ERROR) => 2,
MyEnum::OtherVariant(..) => 2,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module prettier::members {
#[
test,
expected_failure(
abort_code = other_module::ENotFound,
abort_code = ::other_module::ENotFound,
),
]
#[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module prettier::members {
#[allow(unused_const, unused_variable)]
#[expected_error(abort_code = ::ENotImplemented)]
#[test, expected_failure(abort_code = other_module::ENotFound)]
#[test, expected_failure(abort_code = ::other_module::ENotFound)]
#[expected_failure(arithmetic_error, location = pkg_addr::other_module)]
#[allow(unused_const, unused_variable, unused_imports, unused_field)]
fun call_something() {}
Expand Down
Binary file not shown.

0 comments on commit 9709700

Please sign in to comment.