-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doc] support enum in docgen (#14562)
* doc for enum * add tests
- Loading branch information
1 parent
0b47a5a
commit afd3706
Showing
6 changed files
with
1,210 additions
and
21 deletions.
There are no files selected for viewing
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
86 changes: 86 additions & 0 deletions
86
third_party/move/move-prover/move-docgen/tests/sources/test-compiler-v2/enum.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,86 @@ | ||
module 0x815::m { | ||
|
||
enum CommonFields has key, copy, drop { | ||
Foo{x: u64, y: u8}, | ||
Bar{x: u64, y: u8, z: u32} | ||
} | ||
|
||
spec CommonFields { | ||
invariant self.x > 20; | ||
invariant (self is CommonFields::Bar) ==> self.z > 10; | ||
} | ||
|
||
fun t9_common_field(): u64 { | ||
let common = CommonFields::Bar { | ||
x: 30, | ||
y: 40, | ||
z: 50 | ||
}; | ||
common.x = 15; // struct invariant fails | ||
common.x | ||
} | ||
|
||
fun test_data_invariant() { | ||
let common = CommonFields::Bar { | ||
x: 30, | ||
y: 40, | ||
z: 50 | ||
}; | ||
let CommonFields::Bar {x: _x, y: _y, z} = &mut common; | ||
*z = 9; // struct invariant fails | ||
} | ||
|
||
fun test_match_ref(): u64 { | ||
let common = CommonFields::Bar { | ||
x: 30, | ||
y: 40, | ||
z: 50 | ||
}; | ||
match (&common) { | ||
Foo {x, y: _} => *x, | ||
Bar {x, y: _, z: _ } => *x + 1 | ||
} | ||
} | ||
|
||
spec test_match_ref { | ||
ensures result == 31; | ||
} | ||
|
||
enum CommonFieldsVector has drop { | ||
Foo{x: vector<u8>}, | ||
Bar{x: vector<u8>, y: vector<CommonFields>} | ||
} | ||
|
||
fun test_enum_vector() { | ||
let _common_vector_1 = CommonFieldsVector::Foo { | ||
x: vector[2] | ||
}; | ||
let _common_fields = CommonFields::Bar { | ||
x: 30, | ||
y: 40, | ||
z: 50 | ||
}; | ||
let _common_vector_2 = CommonFieldsVector::Bar { | ||
x: vector[2], | ||
y: vector[_common_fields] | ||
}; | ||
spec { | ||
assert _common_vector_1.x != _common_vector_2.x; // this fails | ||
assert _common_vector_2.y[0] == CommonFields::Bar { | ||
x: 30, | ||
y: 40, | ||
z: 50 | ||
}; | ||
}; | ||
let _common_vector_3 = CommonFieldsVector::Bar { | ||
x: vector[2], | ||
y: vector[_common_fields] | ||
}; | ||
spec { | ||
assert _common_vector_2.x == _common_vector_3.x; | ||
assert _common_vector_2 == _common_vector_3; | ||
}; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.