From 2e56b7ae997e228d99643ef61d669d11e85b49b2 Mon Sep 17 00:00:00 2001 From: ployt0 <25666053+ployt0@users.noreply.github.com> Date: Sun, 12 Mar 2023 12:14:31 +0000 Subject: [PATCH 1/8] Introduce greater and less than type conditions --- src/Expectation.lua | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/Expectation.lua b/src/Expectation.lua index 96dc2c7..0a84702 100644 --- a/src/Expectation.lua +++ b/src/Expectation.lua @@ -89,6 +89,13 @@ function Expectation.new(value) self.equal = bindSelf(self, self.equal) self.throw = bindSelf(self, self.throw) self.near = bindSelf(self, self.near) + self.over = bindSelf(self, self.over) + self.gt = bindSelf(self, self.over) + self.gte = bindSelf(self, self.gte) + self.under = bindSelf(self, self.under) + self.lt = bindSelf(self, self.under) + self.lte = bindSelf(self, self.lte) + return self end @@ -263,6 +270,110 @@ function Expectation:near(otherValue, limit) return self end +--[[ + Assert that our expectation value is greater than another value. +]] +function Expectation:over(otherValue) + assert(type(self.value) == "number", "Expectation value must be a number to use 'over'") + assert(type(otherValue) == "number", "otherValue must be a number") + + local result = self.value > otherValue == self.successCondition + + local message = formatMessage(self.successCondition, + ("Expected value to be over %f but got %f instead"):format( + otherValue, + self.value + ), + ("Expected value to not be over %f but got %f instead"):format( + otherValue, + self.value + ) + ) + + assertLevel(result, message, 3) + self:_resetModifiers() + + return self +end + +--[[ + Assert that our expectation value is greater than or equal to another value. +]] +function Expectation:gte(otherValue) + assert(type(self.value) == "number", "Expectation value must be a number to use 'gte'") + assert(type(otherValue) == "number", "otherValue must be a number") + + local result = self.value >= otherValue == self.successCondition + + local message = formatMessage(self.successCondition, + ("Expected value to be greater than or equal to %f but got %f instead"):format( + otherValue, + self.value + ), + ("Expected value to not be greater than or equal to %f but got %f instead"):format( + otherValue, + self.value + ) + ) + + assertLevel(result, message, 3) + self:_resetModifiers() + + return self +end + +--[[ + Assert that our expectation value is less than another value. +]] +function Expectation:under(otherValue) + assert(type(self.value) == "number", "Expectation value must be a number to use 'under'") + assert(type(otherValue) == "number", "otherValue must be a number") + + local result = self.value < otherValue == self.successCondition + + local message = formatMessage(self.successCondition, + ("Expected value to be under %f but got %f instead"):format( + otherValue, + self.value + ), + ("Expected value to not be under %f but got %f instead"):format( + otherValue, + self.value + ) + ) + + assertLevel(result, message, 3) + self:_resetModifiers() + + return self +end + +--[[ + Assert that our expectation value is less than or equal to another value. +]] +function Expectation:lte(otherValue) + assert(type(self.value) == "number", "Expectation value must be a number to use 'lte'") + assert(type(otherValue) == "number", "otherValue must be a number") + + local result = self.value <= otherValue == self.successCondition + + local message = formatMessage(self.successCondition, + ("Expected value to be less than or equal to %f but got %f instead"):format( + otherValue, + self.value + ), + ("Expected value to not be less than or equal to %f but got %f instead"):format( + otherValue, + self.value + ) + ) + + assertLevel(result, message, 3) + self:_resetModifiers() + + return self +end + --[[ Assert that our functoid expectation value throws an error when called. An optional error message can be passed to assert that the error message From 8fb41e766937140e762c08da7e91e4ddf19735a4 Mon Sep 17 00:00:00 2001 From: ployt0 <25666053+ployt0@users.noreply.github.com> Date: Sun, 12 Mar 2023 12:41:52 +0000 Subject: [PATCH 2/8] unit test gt, lt, gte and lte predicates --- tests/Expectation.lua | 131 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/tests/Expectation.lua b/tests/Expectation.lua index cbb8133..7ebf5cb 100644 --- a/tests/Expectation.lua +++ b/tests/Expectation.lua @@ -266,4 +266,135 @@ return { assert(success, "should succeed") end, + ["a greater than b should succeed when a>b"] = function() + local expect = Expectation.new(2) + + local success = pcall(function() + expect:over(1) + end) + + assert(success, "should succeed") + end, + ["a greater than b should fail when equal"] = function() + local expect = Expectation.new(2) + + local success = pcall(function() + expect:over(2) + end) + + assert(not success, "should fail") + assert( + message:match('Expected value to be over %d+.%d+ but got %d+.%d+ instead'), + ("Error message does not match:\n%s\n"):format(message) + ) + end, + ["a greater than b should fail when ab"] = function() + local expect = Expectation.new(2) + + local success = pcall(function() + expect:gte(1) + end) + + assert(success, "should succeed") + end, + ["a greater than or equal to b should succeed when equal"] = function() + local expect = Expectation.new(2) + + local success = pcall(function() + expect:gte(2) + end) + + assert(success, "should succeed") + end, + ["a greater than or equal to b should fail when a Date: Sun, 12 Mar 2023 12:47:25 +0000 Subject: [PATCH 3/8] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fd403..2a1b890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased Changes +## 0.4.3 (2023-03-12) +* Added `under` and `over` expectations, analogous to less than and greater than. The latter were ruled out by the last word needing to be callable. +* Added shorthand `lt`, `lte`, `gt`, and `gte` for those that know and want to keep things tidy. + ## 0.4.2 (2022-01-05) * Updated `rotriever.toml` to fix deprecation warnings * Added dark theme support to the documentation site From d69d0bd64e5ff019fd7bd9991b27e513f64423f0 Mon Sep 17 00:00:00 2001 From: ployt0 <25666053+ployt0@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:12:00 +0000 Subject: [PATCH 4/8] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d168132..3d8a143 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,7 @@ name: CI on: + workflow_dispatch: pull_request: push: branches: From 4c49f8f71b7570e561b2c7a8921b81c730a67715 Mon Sep 17 00:00:00 2001 From: ployt0 <25666053+ployt0@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:02:07 +0000 Subject: [PATCH 5/8] Update ci.yml --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d8a143..94f1212 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,8 @@ jobs: run: | lua -lluacov test/lemur.lua luacheck src tests + echo "REPO_TOKEN is $REPO_TOKEN" + echo "GITHUB_TOKEN is ${{ secrets.GITHUB_TOKEN }}" # luacov-coveralls default settings do not function on GitHub Actions. # We need to pass different service name and repo token explicitly From e7e5bfd56c20349a59af9f92a0c7d5d85519b2da Mon Sep 17 00:00:00 2001 From: ployt0 <25666053+ployt0@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:13:28 +0000 Subject: [PATCH 6/8] revert previous 2 commits --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94f1212..d168132 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,6 @@ name: CI on: - workflow_dispatch: pull_request: push: branches: @@ -34,8 +33,6 @@ jobs: run: | lua -lluacov test/lemur.lua luacheck src tests - echo "REPO_TOKEN is $REPO_TOKEN" - echo "GITHUB_TOKEN is ${{ secrets.GITHUB_TOKEN }}" # luacov-coveralls default settings do not function on GitHub Actions. # We need to pass different service name and repo token explicitly From 658e072750218a121f50e852d290d06e86f35a17 Mon Sep 17 00:00:00 2001 From: ployt0 <25666053+ployt0@users.noreply.github.com> Date: Sat, 25 Mar 2023 22:26:58 +0000 Subject: [PATCH 7/8] fix failing tests --- tests/Expectation.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/Expectation.lua b/tests/Expectation.lua index 7ebf5cb..068b937 100644 --- a/tests/Expectation.lua +++ b/tests/Expectation.lua @@ -278,7 +278,7 @@ return { ["a greater than b should fail when equal"] = function() local expect = Expectation.new(2) - local success = pcall(function() + local success, message = pcall(function() expect:over(2) end) @@ -291,7 +291,7 @@ return { ["a greater than b should fail when ab"] = function() local expect = Expectation.new(2) @@ -309,7 +310,7 @@ return { assert(success, "should succeed") end, - ["a greater than or equal to b should succeed when equal"] = function() + ["a greater than or equal gte to b should succeed when equal"] = function() local expect = Expectation.new(2) local success = pcall(function() @@ -321,7 +322,7 @@ return { ["a greater than or equal to b should fail when a Date: Sat, 25 Mar 2023 22:27:51 +0000 Subject: [PATCH 8/8] remove acronym --- tests/Expectation.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Expectation.lua b/tests/Expectation.lua index 068b937..ff5cf97 100644 --- a/tests/Expectation.lua +++ b/tests/Expectation.lua @@ -310,7 +310,7 @@ return { assert(success, "should succeed") end, - ["a greater than or equal gte to b should succeed when equal"] = function() + ["a greater than or equal to b should succeed when equal"] = function() local expect = Expectation.new(2) local success = pcall(function()