From fdd18c77575ea0fe904e7cd1d4261f9e09700794 Mon Sep 17 00:00:00 2001 From: "John K. Luebs" Date: Wed, 6 Mar 2024 16:41:07 -0600 Subject: [PATCH] Fix error type naming consistency and punctuation. --- ckiwi/ckiwi.cpp | 12 ++++++------ ckiwi/ckiwi.h | 6 +++--- kiwi.lua | 22 +++++++++++----------- spec/solver_spec.lua | 28 ++++++++++++++-------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ckiwi/ckiwi.cpp b/ckiwi/ckiwi.cpp index ba8a395..b0247c9 100644 --- a/ckiwi/ckiwi.cpp +++ b/ckiwi/ckiwi.cpp @@ -42,12 +42,12 @@ static const constexpr KiwiErr kKiwiErrUnhandledCxxException { static const constexpr KiwiErr kKiwiErrNullObjectArg0 { KiwiErrNullObject, - "null object passed as argument #0 (self)" + "null object passed as argument #0 (self)." }; static const constexpr KiwiErr kKiwiErrNullObjectArg1 { KiwiErrNullObject, - "null object passed as argument #1" + "null object passed as argument #1." }; template @@ -76,14 +76,14 @@ const KiwiErr* wrap_err(F&& f) { } catch (const UnknownEditVariable& ex) { static const constexpr KiwiErr err { - KiwiErrUnknownEditVariable, + KiwiErrUnknownEditVar, "The edit variable has not been added to the solver." }; return &err; } catch (const DuplicateEditVariable& ex) { static const constexpr KiwiErr err { - KiwiErrDuplicateEditVariable, + KiwiErrDuplicateEditVar, "The edit variable has already been added to the solver." }; return &err; @@ -161,9 +161,9 @@ void kiwi_str_release(char* str) { std::free(str); } -void kiwi_err_release(const KiwiErr* err) { +void kiwi_err_release(KiwiErr* err) { if (lk_likely(err && err->must_release)) - std::free(const_cast(err)); + std::free(err); } KiwiVar* kiwi_var_new(const char* name) { diff --git a/ckiwi/ckiwi.h b/ckiwi/ckiwi.h index 60e3e71..88f2d98 100644 --- a/ckiwi/ckiwi.h +++ b/ckiwi/ckiwi.h @@ -37,8 +37,8 @@ enum KiwiErrKind { KiwiErrUnsatisfiableConstraint = 1, KiwiErrUnknownConstraint, KiwiErrDuplicateConstraint, - KiwiErrUnknownEditVariable, - KiwiErrDuplicateEditVariable, + KiwiErrUnknownEditVar, + KiwiErrDuplicateEditVar, KiwiErrBadRequiredStrength, KiwiErrInternalSolverError, KiwiErrAlloc, @@ -78,7 +78,7 @@ struct KiwiSolver; LJKIWI_EXP void kiwi_solver_type_info(unsigned sz_align[2]); LJKIWI_EXP void kiwi_str_release(char* str); -LJKIWI_EXP void kiwi_err_release(const KiwiErr* err); +LJKIWI_EXP void kiwi_err_release(KiwiErr* err); LJKIWI_EXP KiwiVar* kiwi_var_new(const char* name); LJKIWI_EXP void kiwi_var_release(KiwiVar* var); diff --git a/kiwi.lua b/kiwi.lua index 69a0ab5..4673de9 100644 --- a/kiwi.lua +++ b/kiwi.lua @@ -77,8 +77,8 @@ enum KiwiErrKind { KiwiErrUnsatisfiableConstraint = 1, KiwiErrUnknownConstraint, KiwiErrDuplicateConstraint, - KiwiErrUnknownEditVariable, - KiwiErrDuplicateEditVariable, + KiwiErrUnknownEditVar, + KiwiErrDuplicateEditVar, KiwiErrBadRequiredStrength, KiwiErrInternalSolverError, KiwiErrAlloc, @@ -110,7 +110,7 @@ typedef struct KiwiErr { struct KiwiSolver; void kiwi_str_release(char *); -void kiwi_err_release(const KiwiErr *); +void kiwi_err_release(KiwiErr *); KiwiVar* kiwi_var_new(const char* name); void kiwi_var_release(KiwiVar* var); @@ -173,8 +173,8 @@ end ---| '"KiwiErrUnsatisfiableConstraint"' # The given constraint is required and cannot be satisfied. ---| '"KiwiErrUnknownConstraint"' # The given constraint has not been added to the solver. ---| '"KiwiErrDuplicateConstraint"' # The given constraint has already been added to the solver. ----| '"KiwiErrUnknownEditVariable"' # The given edit variable has not been added to the solver. ----| '"KiwiErrDuplicateEditVariable"' # The given edit variable has already been added to the solver. +---| '"KiwiErrUnknownEditVar"' # The given edit variable has not been added to the solver. +---| '"KiwiErrDuplicateEditVar"' # The given edit variable has already been added to the solver. ---| '"KiwiErrBadRequiredStrength"' # The given strength is >= required. ---| '"KiwiErrInternalSolverError"' # An internal solver error occurred. ---| '"KiwiErrAlloc"' # A memory allocation error occurred. @@ -1139,7 +1139,7 @@ do --- This method should be called before the `suggestValue` method is --- used to supply a suggested value for the given edit variable. --- Errors: - --- KiwiErrDuplicateEditVariable + --- KiwiErrDuplicateEditVar --- KiwiErrBadRequiredStrength: The given strength is >= required. ---@param var kiwi.Var the variable to add as an edit variable ---@param strength number the strength of the edit variable (must be less than `Strength.REQUIRED`) @@ -1153,7 +1153,7 @@ do --- This method should be called before the `suggestValue` method is --- used to supply a suggested value for the given edit variable. --- Errors: - --- KiwiErrDuplicateEditVariable + --- KiwiErrDuplicateEditVar --- KiwiErrBadRequiredStrength: The given strength is >= required. ---@param vars kiwi.Var[] the variables to add as an edit variable ---@param strength number the strength of the edit variables (must be less than `Strength.REQUIRED`) @@ -1164,7 +1164,7 @@ do --- Remove an edit variable from the solver. --- Raises: - --- KiwiErrUnknownEditVariable + --- KiwiErrUnknownEditVar ---@param var kiwi.Var the edit variable to remove ---@return kiwi.Var var, kiwi.Error? function Solver_cls:remove_edit_var(var) @@ -1173,7 +1173,7 @@ do --- Removes edit variables from the solver. --- Raises: - --- KiwiErrUnknownEditVariable + --- KiwiErrUnknownEditVar ---@param vars kiwi.Var[] the edit variables to remove ---@return kiwi.Var[] vars, kiwi.Error? function Solver_cls:remove_edit_vars(vars) @@ -1185,7 +1185,7 @@ do --- to suggest the value for that variable. After all suggestions have been made, --- the `update_vars` methods can be used to update the values of the external solver variables. --- Raises: - --- KiwiErrUnknownEditVariable + --- KiwiErrUnknownEditVar ---@param var kiwi.Var the edit variable to suggest a value for ---@param value number the suggested value ---@return kiwi.Var var, kiwi.Error? @@ -1196,7 +1196,7 @@ do --- Suggest values for the given edit variables. --- Convenience wrapper of `suggest_value` that takes tables of `kiwi.Var` and number pairs. --- Raises: - --- KiwiErrUnknownEditVariable: The given edit variable has not been added to the solver. + --- KiwiErrUnknownEditVar: The given edit variable has not been added to the solver. ---@param vars kiwi.Var[] edit variables to suggest ---@param values number[] suggested values ---@return kiwi.Var[] vars, number[] values, kiwi.Error? diff --git a/spec/solver_spec.lua b/spec/solver_spec.lua index 8b68847..81efc45 100644 --- a/spec/solver_spec.lua +++ b/spec/solver_spec.lua @@ -57,7 +57,7 @@ describe("solver", function() assert.True(kiwi.is_error(err)) assert.True(kiwi.is_solver(err.solver)) assert.equal(v1, err.item) - assert.equal("KiwiErrDuplicateEditVariable", err.kind) + assert.equal("KiwiErrDuplicateEditVar", err.kind) assert.equal("The edit variable has already been added to the solver.", err.message) end) @@ -73,7 +73,7 @@ describe("solver", function() end) it("should return errors for duplicate variables", function() - solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" }) + solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" }) local ret, err = solver:add_edit_var(v1, kiwi.strength.STRONG) assert.Nil(err) @@ -84,13 +84,13 @@ describe("solver", function() ---@diagnostic disable: need-check-nil assert.True(kiwi.is_solver(err.solver)) assert.equal(v1, err.item) - assert.equal("KiwiErrDuplicateEditVariable", err.kind) + assert.equal("KiwiErrDuplicateEditVar", err.kind) assert.equal("The edit variable has already been added to the solver.", err.message) ---@diagnostic enable: need-check-nil end) it("should return errors for invalid strength", function() - solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" }) + solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" }) ---@diagnostic disable: need-check-nil local ret, err = solver:add_edit_var(v2, kiwi.strength.REQUIRED) @@ -154,7 +154,7 @@ describe("solver", function() assert.True(kiwi.is_error(err)) assert.True(kiwi.is_solver(err.solver)) assert.equal(v2, err.item) - assert.equal("KiwiErrDuplicateEditVariable", err.kind) + assert.equal("KiwiErrDuplicateEditVar", err.kind) assert.equal("The edit variable has already been added to the solver.", err.message) end) @@ -170,7 +170,7 @@ describe("solver", function() end) it("should return errors for duplicate variables", function() - solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" }) + solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" }) local ret, err = solver:add_edit_vars({ v1, v2, v3 }, kiwi.strength.STRONG) assert.Nil(err) @@ -181,13 +181,13 @@ describe("solver", function() ---@diagnostic disable: need-check-nil assert.True(kiwi.is_solver(err.solver)) assert.equal(v1, err.item) - assert.equal("KiwiErrDuplicateEditVariable", err.kind) + assert.equal("KiwiErrDuplicateEditVar", err.kind) assert.equal("The edit variable has already been added to the solver.", err.message) ---@diagnostic enable: need-check-nil end) it("should return errors for invalid strength", function() - solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" }) + solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" }) arg = { v2, v3 } local ret, err = solver:add_edit_vars(arg, kiwi.strength.REQUIRED) assert.equal(arg, ret) @@ -239,12 +239,12 @@ describe("solver", function() assert.True(kiwi.is_error(err)) assert.True(kiwi.is_solver(err.solver)) assert.equal(v2, err.item) - assert.equal("KiwiErrUnknownEditVariable", err.kind) + assert.equal("KiwiErrUnknownEditVar", err.kind) assert.equal("The edit variable has not been added to the solver.", err.message) end) it("should return errors if requested", function() - solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrUnknownEditVariable" }) + solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrUnknownEditVar" }) local ret, err = solver:remove_edit_var(v1) @@ -253,7 +253,7 @@ describe("solver", function() ---@diagnostic disable: need-check-nil assert.True(kiwi.is_solver(err.solver)) assert.equal(v1, err.item) - assert.equal("KiwiErrUnknownEditVariable", err.kind) + assert.equal("KiwiErrUnknownEditVar", err.kind) assert.equal("The edit variable has not been added to the solver.", err.message) ---@diagnostic enable: need-check-nil end) @@ -304,12 +304,12 @@ describe("solver", function() assert.True(kiwi.is_error(err)) assert.True(kiwi.is_solver(err.solver)) assert.equal(v2, err.item) - assert.equal("KiwiErrUnknownEditVariable", err.kind) + assert.equal("KiwiErrUnknownEditVar", err.kind) assert.equal("The edit variable has not been added to the solver.", err.message) end) it("should return errors for unknown variables", function() - solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrUnknownEditVariable" }) + solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrUnknownEditVar" }) local ret, err = solver:add_edit_vars({ v1, v2 }, kiwi.strength.STRONG) assert.Nil(err) @@ -320,7 +320,7 @@ describe("solver", function() ---@diagnostic disable: need-check-nil assert.True(kiwi.is_solver(err.solver)) assert.equal(v3, err.item) - assert.equal("KiwiErrUnknownEditVariable", err.kind) + assert.equal("KiwiErrUnknownEditVar", err.kind) assert.equal("The edit variable has not been added to the solver.", err.message) ---@diagnostic enable: need-check-nil end)