diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-04-30 21:56:51 +0200 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-04-30 21:56:51 +0200 |
| commit | fdf62fe6c4125d29b3097e49566b2bbe1f650382 (patch) | |
| tree | 81dcf1a0818af6754c44583db3464ddfcab26af4 /spec | |
| parent | bd994461ef7c2553da9a6945c685152bad50eb8f (diff) | |
| download | luasystem-fdf62fe6c4125d29b3097e49566b2bbe1f650382.tar.gz luasystem-fdf62fe6c4125d29b3097e49566b2bbe1f650382.tar.bz2 luasystem-fdf62fe6c4125d29b3097e49566b2bbe1f650382.zip | |
review: bitflags no comparison, extra tests
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 |
