mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: allow enums to be used as bitfield flags
This commit is contained in:

committed by
Alexander Medvednikov

parent
0650d58818
commit
6d5e9f88f8
34
vlib/compiler/tests/enum_bitfield_test.v
Normal file
34
vlib/compiler/tests/enum_bitfield_test.v
Normal file
@ -0,0 +1,34 @@
|
||||
[flag]
|
||||
enum BfPermission {
|
||||
read
|
||||
write
|
||||
execute
|
||||
other
|
||||
}
|
||||
|
||||
struct BfFile {
|
||||
mut:
|
||||
perm BfPermission
|
||||
}
|
||||
|
||||
fn test_enum_bitfield() {
|
||||
mut a := BfFile{}
|
||||
a.perm.set(.read)
|
||||
a.perm.set(.write)
|
||||
a.perm.toggle(.execute)
|
||||
a.perm.clear(.write)
|
||||
//a.perm.set(.other)
|
||||
|
||||
assert a.perm.has(.read)
|
||||
assert a.perm.has(.execute)
|
||||
assert !a.perm.has(.write)
|
||||
assert !a.perm.has(.other)
|
||||
|
||||
mut b := BfPermission.read // TODO: this does nothing currenty just sets the type
|
||||
b.set(.write)
|
||||
b.set(.other)
|
||||
assert b.has(.write)
|
||||
assert b.has(.other)
|
||||
assert !b.has(.read)
|
||||
assert !b.has(.execute)
|
||||
}
|
Reference in New Issue
Block a user