aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/05-bitflags_spec.lua23
1 files changed, 18 insertions, 5 deletions
diff --git a/spec/05-bitflags_spec.lua b/spec/05-bitflags_spec.lua
index 8024245..8eea27f 100644
--- a/spec/05-bitflags_spec.lua
+++ b/spec/05-bitflags_spec.lua
@@ -87,15 +87,28 @@ describe("BitFlags library", function()
87 assert.has_error(function() bf.not_a_number = true end, "index must be a number") 87 assert.has_error(function() bf.not_a_number = true end, "index must be a number")
88 end) 88 end)
89 89
90 it("checks for a subset using 'has'", function() 90 it("checks for a subset using 'has_all_of'", function()
91 local bf1 = sys.bitflag(3) -- b0011 91 local bf1 = sys.bitflag(3) -- b0011
92 local bf2 = sys.bitflag(3) -- b0011 92 local bf2 = sys.bitflag(3) -- b0011
93 local bf3 = sys.bitflag(15) -- b1111 93 local bf3 = sys.bitflag(15) -- b1111
94 local bf0 = sys.bitflag(0) -- b0000 94 local bf0 = sys.bitflag(0) -- b0000
95 assert.is_true(bf1:has(bf2)) -- equal 95 assert.is_true(bf1:has_all_of(bf2)) -- equal
96 assert.is_true(bf3:has(bf1)) -- is a subset, and has more flags 96 assert.is_true(bf3:has_all_of(bf1)) -- is a subset, and has more flags
97 assert.is_false(bf1:has(bf3)) -- not a subset, bf3 has more flags 97 assert.is_false(bf1:has_all_of(bf3)) -- not a subset, bf3 has more flags
98 assert.is_false(bf1:has(bf0)) -- bf0 is unset, always returns false 98 assert.is_false(bf1:has_all_of(bf0)) -- bf0 is unset, always returns false
99 end)
100
101 it("checks for a subset using 'has_any_of'", function()
102 local bf1 = sys.bitflag(3) -- b0011
103 local bf2 = sys.bitflag(3) -- b0011
104 local bf3 = sys.bitflag(7) -- b0111
105 local bf4 = sys.bitflag(8) -- b1000
106 local bf0 = sys.bitflag(0) -- b0000
107 assert.is_true(bf1:has_any_of(bf2)) -- equal
108 assert.is_true(bf3:has_any_of(bf1)) -- is a subset, and has more flags
109 assert.is_false(bf3:has_any_of(bf4)) -- no overlap in flags
110 assert.is_true(bf1:has_any_of(bf3)) -- not a subset, bf3 has more flags but still some overlap
111 assert.is_false(bf1:has_all_of(bf0)) -- bf0 is unset, always returns false
99 end) 112 end)
100 113
101end) 114end)