Comparison

spec/util_error_spec.lua @ 11102:5a0ff475ecfd

util.error: Drop registry initialization with namespace as key Enough complexity with compact vs normal and with/without namespace
author Kim Alvefur <zash@zash.se>
date Mon, 28 Sep 2020 23:48:02 +0200
parent 11101:2288d206b14b
child 11221:b0a563716334
comparison
equal deleted inserted replaced
11101:2288d206b14b 11102:5a0ff475ecfd
94 assert.equal("not-authorized", nope.condition); 94 assert.equal("not-authorized", nope.condition);
95 assert.equal("Can't let you do that Dave", nope.text); 95 assert.equal("Can't let you do that Dave", nope.text);
96 end); 96 end);
97 97
98 it("compact mode works", function() 98 it("compact mode works", function()
99 local reg = errors.init("test", { 99 local reg = errors.init("test", "spec", {
100 namespace = "spec";
101 broke = {"cancel"; "internal-server-error"; "It broke :("}; 100 broke = {"cancel"; "internal-server-error"; "It broke :("};
102 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; 101 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"};
103 }); 102 });
104 103
105 local broke = reg.new("broke"); 104 local broke = reg.new("broke");
124 condition = "not-authorized"; 123 condition = "not-authorized";
125 text = "Can't let you do that Dave"; 124 text = "Can't let you do that Dave";
126 extra = {namespace = "spec"; condition = "sorry-dave"}; 125 extra = {namespace = "spec"; condition = "sorry-dave"};
127 }; 126 };
128 }); 127 });
129 local compact1 = errors.init("test", { 128 local compact1 = errors.init("test", "spec", {
130 namespace = "spec";
131 broke = {"cancel"; "internal-server-error"; "It broke :("}; 129 broke = {"cancel"; "internal-server-error"; "It broke :("};
132 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; 130 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"};
133 }); 131 });
134 local compact2 = errors.init("test", "spec", { 132 local compact2 = errors.init("test", {
135 broke = {"cancel"; "internal-server-error"; "It broke :("};
136 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"};
137 });
138 local compact3 = errors.init("test", {
139 broke = {"cancel"; "internal-server-error"; "It broke :("}; 133 broke = {"cancel"; "internal-server-error"; "It broke :("};
140 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"}; 134 nope = {"auth"; "not-authorized"; "Can't let you do that Dave"};
141 }); 135 });
142 assert.same(normal.registry, compact1.registry); 136 assert.same(normal.registry, compact1.registry);
143 assert.same(normal.registry, compact2.registry);
144 137
145 assert.same({ 138 assert.same({
146 broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("}; 139 broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("};
147 nope = {type = "auth"; condition = "not-authorized"; text = "Can't let you do that Dave"}; 140 nope = {type = "auth"; condition = "not-authorized"; text = "Can't let you do that Dave"};
148 }, compact3.registry); 141 }, compact2.registry);
149 end); 142 end);
150 end); 143 end);
151 144
152 end); 145 end);
153 146