diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/05-bitflags_spec.lua | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/spec/05-bitflags_spec.lua b/spec/05-bitflags_spec.lua index 01bf958..8024245 100644 --- a/spec/05-bitflags_spec.lua +++ b/spec/05-bitflags_spec.lua | |||
@@ -71,11 +71,13 @@ describe("BitFlags library", function() | |||
71 | end) | 71 | end) |
72 | 72 | ||
73 | it("sets and clears bits correctly", function() | 73 | it("sets and clears bits correctly", function() |
74 | local bf = sys.bitflag(0) | 74 | local bf = sys.bitflag(8) -- b1000 |
75 | bf[1] = true | 75 | bf[1] = true |
76 | assert.is_true(bf[1]) | 76 | assert.is_true(bf[1]) -- b1010 |
77 | assert.equals(10, bf:value()) | ||
77 | bf[1] = false | 78 | bf[1] = false |
78 | assert.is_false(bf[1]) | 79 | assert.is_false(bf[1]) -- b1000 |
80 | assert.equals(8, bf:value()) | ||
79 | end) | 81 | end) |
80 | 82 | ||
81 | it("errors on setting invalid bit indexes", function() | 83 | it("errors on setting invalid bit indexes", function() |
@@ -85,15 +87,6 @@ describe("BitFlags library", function() | |||
85 | 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") |
86 | end) | 88 | end) |
87 | 89 | ||
88 | it("handles <= and >= operations", function() | ||
89 | local bf1 = sys.bitflag(3) -- b0011 | ||
90 | local bf2 = sys.bitflag(15) -- b1111 | ||
91 | assert.is_true(bf2 >= bf1) -- all bits in bf1 are set in bf2 | ||
92 | assert.is_true(bf2 > bf1) -- all bits in bf1 are set in bf2 and some more | ||
93 | assert.is_false(bf2 <= bf1) -- not all bits in bf2 are set in bf1 | ||
94 | assert.is_false(bf2 < bf1) -- not all bits in bf2 are set in bf1 | ||
95 | end) | ||
96 | |||
97 | it("checks for a subset using 'has'", function() | 90 | it("checks for a subset using 'has'", function() |
98 | local bf1 = sys.bitflag(3) -- b0011 | 91 | local bf1 = sys.bitflag(3) -- b0011 |
99 | local bf2 = sys.bitflag(3) -- b0011 | 92 | local bf2 = sys.bitflag(3) -- b0011 |