-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4/n][enums] Move compiler enums tests
- Loading branch information
Showing
129 changed files
with
1,592 additions
and
538 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
30 changes: 30 additions & 0 deletions
30
external-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> has drop { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun t0(): u64 { | ||
let subject = ABC::C(0); | ||
match (subject) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => 1, | ||
} | ||
} | ||
|
||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
|
||
fun main() { | ||
use 0x42::m::t0; | ||
assert!(t0() == 0, 0); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_binder.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
63 changes: 63 additions & 0 deletions
63
...crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_binder.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> has drop { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun a(): ABC<u64> { | ||
ABC::A(42) | ||
} | ||
|
||
public fun b(): ABC<u64> { | ||
ABC::B | ||
} | ||
|
||
public fun c(): ABC<u64> { | ||
ABC::C(42) | ||
} | ||
|
||
public fun is_a<T>(x: &ABC<T>): bool { | ||
match (x) { | ||
ABC::A(_) => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
public fun is_b<T>(x: &ABC<T>): bool { | ||
match (x) { | ||
ABC::B => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
public fun is_c<T>(x: &ABC<T>): bool { | ||
match (x) { | ||
ABC::C(_) => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
public fun t0(x: ABC<u64>): ABC<u64> { | ||
match (x) { | ||
ABC::C(c) => ABC::C(c), | ||
ABC::A(a) => ABC::A(a), | ||
y => y, | ||
} | ||
} | ||
|
||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
use 0x42::m::{a, b, c}; | ||
fun main() { | ||
assert!(a().t0().is_a(), 0); | ||
assert!(b().t0().is_b(), 1); | ||
assert!(c().t0().is_c(), 2); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_mut_ref.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
78 changes: 78 additions & 0 deletions
78
...rates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_mut_ref.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> has drop { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun a(): ABC<u64> { | ||
ABC::A(42) | ||
} | ||
|
||
public fun b(): ABC<u64> { | ||
ABC::B | ||
} | ||
|
||
public fun c(): ABC<u64> { | ||
ABC::C(42) | ||
} | ||
|
||
public fun is_a<T>(x: &ABC<T>): bool { | ||
match (x) { | ||
ABC::A(_) => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
public fun is_b<T>(x: &ABC<T>): bool { | ||
match (x) { | ||
ABC::B => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
public fun is_c<T>(x: &ABC<T>): bool { | ||
match (x) { | ||
ABC::C(_) => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
public fun t0(abc: &mut ABC<u64>, default: &mut u64): &mut u64 { | ||
match (abc) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => default, | ||
} | ||
} | ||
|
||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
use 0x42::m::{a, b, c}; | ||
fun main() { | ||
let mut x = 43; | ||
let a = a().t0(&mut x); | ||
assert!(*a == 42, 1); | ||
*a = 0; | ||
assert!(*a == 0, 2); | ||
assert!(x == 43, 3); | ||
|
||
let c = c().t0(&mut x); | ||
assert!(*c == 42, 4); | ||
*c = 0; | ||
assert!(*c == 0, 5); | ||
assert!(x == 43, 6); | ||
|
||
let b = b().t0(&mut x); | ||
assert!(*b == 43, 7); | ||
*b = 0; | ||
assert!(*b == 0, 8); | ||
assert!(x == 0, 9); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_no_drop.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
28 changes: 28 additions & 0 deletions
28
...rates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_no_drop.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun t0(): u64 { | ||
match (ABC::C(0)) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => 1, | ||
} | ||
} | ||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
|
||
fun main() { | ||
use 0x42::m::t0; | ||
assert!(t0() == 0, 0); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...nal-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_ref.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
50 changes: 50 additions & 0 deletions
50
...al-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_ref.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> has drop { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun a(): ABC<u64> { | ||
ABC::A(42) | ||
} | ||
|
||
public fun b(): ABC<u64> { | ||
ABC::B | ||
} | ||
|
||
public fun c(): ABC<u64> { | ||
ABC::C(42) | ||
} | ||
|
||
public fun t0(abc: &ABC<u64>, default: &u64): &u64 { | ||
match (abc) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => default, | ||
} | ||
} | ||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
use 0x42::m::{a, b, c}; | ||
fun main() { | ||
let x = 43; | ||
let a = a().t0(&x); | ||
assert!(*a == 42, 1); | ||
assert!(x == 43, 2); | ||
|
||
let c = c().t0(&x); | ||
assert!(*c == 42, 3); | ||
assert!(x == 43, 4); | ||
|
||
let b = b().t0(&x); | ||
assert!(*b == 43, 5); | ||
assert!(x == 43, 6); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...l-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_twice.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
102 changes: 102 additions & 0 deletions
102
...-crates/move/crates/move-compiler-transactional-tests/tests/matching/abc_match_twice.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> has drop { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun a(): ABC<u64> { | ||
ABC::A(42) | ||
} | ||
|
||
public fun b(): ABC<u64> { | ||
ABC::B | ||
} | ||
|
||
public fun c(): ABC<u64> { | ||
ABC::C(42) | ||
} | ||
|
||
public fun t0(x: ABC<u64>): u64 { | ||
let default = 1; | ||
let y = match (&x) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => &default, | ||
}; | ||
let y = *y; | ||
let z = match (x) { | ||
ABC::C(x) => y + x, | ||
ABC::A(x) => y + x, | ||
ABC::B => y, | ||
}; | ||
z | ||
} | ||
|
||
public fun t1(x: &ABC<u64>): u64 { | ||
let default = 1; | ||
let y = match (x) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => &default, | ||
}; | ||
let y = *y; | ||
let z = match (x) { | ||
ABC::C(x) => y + *x, | ||
ABC::A(x) => y + *x, | ||
ABC::B => y, | ||
}; | ||
z | ||
} | ||
|
||
public fun t2(x: &mut ABC<u64>): u64 { | ||
let mut default = 1; | ||
let y = match (x) { | ||
ABC::C(x) => x, | ||
ABC::A(x) => x, | ||
ABC::B => &mut default, | ||
}; | ||
let y = *y; | ||
let z = match (x) { | ||
ABC::C(x) => y + *x, | ||
ABC::A(x) => y + *x, | ||
ABC::B => y, | ||
}; | ||
z | ||
} | ||
|
||
|
||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
use 0x42::m::{a, b, c}; | ||
fun main() { | ||
let a = a().t0(); | ||
assert!(a == 42 * 2, 1); | ||
|
||
let c = c().t0(); | ||
assert!(c == 42 * 2, 2); | ||
|
||
let b = b().t0(); | ||
assert!(b == 1, 3); | ||
|
||
let a = a().t1(); | ||
assert!(a == 42 * 2, 4); | ||
let c = c().t1(); | ||
assert!(c == 42 * 2, 5); | ||
let b = b().t1(); | ||
assert!(b == 1, 6); | ||
|
||
let a = a().t2(); | ||
assert!(a == 42 * 2, 7); | ||
let c = c().t2(); | ||
assert!(c == 42 * 2, 8); | ||
let b = b().t2(); | ||
assert!(b == 1, 9); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...move/crates/move-compiler-transactional-tests/tests/matching/abc_match_value_wildcard.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
processed 3 tasks |
27 changes: 27 additions & 0 deletions
27
...ove/crates/move-compiler-transactional-tests/tests/matching/abc_match_value_wildcard.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//# init --edition development | ||
|
||
//# publish | ||
module 0x42::m { | ||
|
||
public enum ABC<T> has drop { | ||
A(T), | ||
B, | ||
C(T) | ||
} | ||
|
||
public fun t0(): u64 { | ||
match (ABC::C(0)) { | ||
ABC::C(x) => x, | ||
_ => 1, | ||
} | ||
} | ||
|
||
} | ||
|
||
//# run | ||
module 0x42::main { | ||
use 0x42::m::t0; | ||
fun main() { | ||
assert!(t0() == 0, 0); | ||
} | ||
} |
Oops, something went wrong.