Diff

spec/util_error_spec.lua @ 11101:2288d206b14b

util.error: Expand compact registries into normal form internally Also the exposed form on the table returned from init()
author Kim Alvefur <zash@zash.se>
date Mon, 28 Sep 2020 22:13:04 +0200
parent 11100:3aa06cdd2dc8
child 11102:5a0ff475ecfd
line wrap: on
line diff
--- a/spec/util_error_spec.lua	Mon Sep 28 18:39:51 2020 +0200
+++ b/spec/util_error_spec.lua	Mon Sep 28 22:13:04 2020 +0200
@@ -115,6 +115,38 @@
 			assert.equal("spec", nope.extra.namespace);
 			assert.equal("sorry-dave", nope.extra.condition);
 		end);
+
+		it("registry looks the same regardless of syntax", function()
+			local normal = errors.init("test", {
+				broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("};
+				nope = {
+					type = "auth";
+					condition = "not-authorized";
+					text = "Can't let you do that Dave";
+					extra = {namespace = "spec"; condition = "sorry-dave"};
+				};
+			});
+			local compact1 = errors.init("test", {
+				namespace = "spec";
+				broke = {"cancel"; "internal-server-error"; "It broke :("};
+				nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"};
+			});
+			local compact2 = errors.init("test", "spec", {
+				broke = {"cancel"; "internal-server-error"; "It broke :("};
+				nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"};
+			});
+			local compact3 = errors.init("test", {
+				broke = {"cancel"; "internal-server-error"; "It broke :("};
+				nope = {"auth"; "not-authorized"; "Can't let you do that Dave"};
+			});
+			assert.same(normal.registry, compact1.registry);
+			assert.same(normal.registry, compact2.registry);
+
+			assert.same({
+				broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("};
+				nope = {type = "auth"; condition = "not-authorized"; text = "Can't let you do that Dave"};
+			}, compact3.registry);
+		end);
 	end);
 
 end);