Skip to content

Commit 5ac0724

Browse files
committed
test with enum with just one variant
1 parent e2b8cf5 commit 5ac0724

File tree

2 files changed

+29
-8
lines changed
  • test/src/e2e_vm_tests/test_programs/should_pass/language/const_generics

2 files changed

+29
-8
lines changed

test/src/e2e_vm_tests/test_programs/should_pass/language/const_generics/src/main.sw

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,24 @@ impl<T, const N: u64> S<T, N> {
3333
}
3434
}
3535

36-
enum E<T, const N: u64> {
36+
// Enum with just one variant
37+
enum OneVariant<const N: u64> {
38+
A: [u64; N],
39+
}
40+
41+
impl<const N: u64> OneVariant<N> {
42+
pub fn return_n(self) -> u64 {
43+
N
44+
}
45+
}
46+
47+
// Enum with more than one variant
48+
enum TwoVariants<T, const N: u64> {
3749
Nothing: (),
3850
Array: [T; N]
3951
}
4052

41-
impl<T, const N: u64> E<T, N> {
53+
impl<T, const N: u64> TwoVariants<T, N> {
4254
pub fn len_xxx2(self) -> u64 {
4355
N
4456
}
@@ -56,7 +68,15 @@ fn main(a: [u64; 2]) {
5668
let s: S<u64, 3> = S { };
5769
let _ = __dbg(s.len_xxx());
5870

59-
let e: E<u64, 3> = E::<u64, 3>::Nothing;
71+
// Check enum with just one variant, with
72+
// all types explicit
73+
let e: OneVariant<3> = OneVariant::<3>::A([1u64, 2u64, 3u64]);
74+
assert(e.return_n() == 3);
75+
let _ = __dbg(e);
76+
77+
// Check enum with more than one variant, with
78+
// all types explicit
79+
let e: TwoVariants<u64, 3> = TwoVariants::<u64, 3>::Nothing;
6080
let _ = __dbg(e);
6181
let b = e.len_xxx2();
6282
assert(b == 3);

test/src/e2e_vm_tests/test_programs/should_pass/language/const_generics/stdout.snap

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ output:
77
Building test/src/e2e_vm_tests/test_programs/should_pass/language/const_generics
88
Compiling library std (sway-lib-std)
99
Compiling script const_generics (test/src/e2e_vm_tests/test_programs/should_pass/language/const_generics)
10-
Finished debug [unoptimized + fuel] target(s) [3.664 KB] in ???
10+
Finished debug [unoptimized + fuel] target(s) [4.472 KB] in ???
1111
Running 1 test, filtered 0 tests
1212

1313
tested -- const_generics
1414

15-
test main_test ... ok (???, 3212 gas)
16-
[src/main.sw:48:13] a = [0, 1]
17-
[src/main.sw:57:13] s.len_xxx() = 3
18-
[src/main.sw:60:13] e = Nothing
15+
test main_test ... ok (???, 6377 gas)
16+
[src/main.sw:60:13] a = [0, 1]
17+
[src/main.sw:69:13] s.len_xxx() = 3
18+
[src/main.sw:75:13] e = OneVariant([1, 2, 3])
19+
[src/main.sw:80:13] e = Nothing
1920

2021
test result: OK. 1 passed; 0 failed; finished in ???
2122

0 commit comments

Comments
 (0)