Skip to content

Commit

Permalink
[4/n][enums] Move compiler enums tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed May 22, 2024
1 parent 8f1cb35 commit cf11909
Show file tree
Hide file tree
Showing 129 changed files with 1,592 additions and 538 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
processed 3 tasks
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);
}
}
Loading

0 comments on commit cf11909

Please sign in to comment.