|
|
@ -77,31 +77,31 @@ describe("registry", () => {
|
|
|
|
|
|
|
|
|
|
|
|
it("should work correctly for traits", () => {
|
|
|
|
it("should work correctly for traits", () => {
|
|
|
|
let Givable = registry.createTrait("Givable", {
|
|
|
|
let Givable = registry.createTrait("Givable", {
|
|
|
|
from: registry.type("Person"),
|
|
|
|
from: registry.type("AlsoPerson"),
|
|
|
|
to: registry.type("Person")
|
|
|
|
to: registry.type("AlsoPerson")
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let Person = registry.createType("Person", {
|
|
|
|
let AlsoPerson = registry.createType("AlsoPerson", {
|
|
|
|
name: dm.string(),
|
|
|
|
name: dm.string(),
|
|
|
|
favouriteGift: registry.trait("Givable").optional()
|
|
|
|
favouriteGift: registry.trait("Givable").optional()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let Gift = registry.createType("Gift", {
|
|
|
|
let AlsoGift = registry.createType("AlsoGift", {
|
|
|
|
description: dm.string()
|
|
|
|
description: dm.string()
|
|
|
|
}).implements(Givable, {
|
|
|
|
}).implements(Givable, {
|
|
|
|
from: dm.slot(),
|
|
|
|
from: dm.slot(),
|
|
|
|
to: dm.slot()
|
|
|
|
to: dm.slot()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let joe = Person({
|
|
|
|
let joe = AlsoPerson({
|
|
|
|
name: "Joe"
|
|
|
|
name: "Joe"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let jane = Person({
|
|
|
|
let jane = AlsoPerson({
|
|
|
|
name: "Jane"
|
|
|
|
name: "Jane"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let flowers = Gift({
|
|
|
|
let flowers = AlsoGift({
|
|
|
|
description: "Flowers",
|
|
|
|
description: "Flowers",
|
|
|
|
from: jane,
|
|
|
|
from: jane,
|
|
|
|
to: joe
|
|
|
|
to: joe
|
|
|
@ -119,11 +119,11 @@ describe("registry", () => {
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
expect(() => {
|
|
|
|
flowers.to = "not a person";
|
|
|
|
flowers.to = "not a person";
|
|
|
|
}).to.throw("Expected an instance of Person, got a string instead");
|
|
|
|
}).to.throw("Expected an instance of AlsoPerson, got a string instead");
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
expect(() => {
|
|
|
|
flowers.to = flowers;
|
|
|
|
flowers.to = flowers;
|
|
|
|
}).to.throw("Expected an instance of Person, got an instance of Gift instead");
|
|
|
|
}).to.throw("Expected an instance of AlsoPerson, got an instance of AlsoGift instead");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("should work correctly for type aliases", () => {
|
|
|
|
it("should work correctly for type aliases", () => {
|
|
|
@ -147,20 +147,20 @@ describe("registry", () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("should work correctly for guarded maps and sets", () => {
|
|
|
|
it("should work correctly for guarded maps and sets", () => {
|
|
|
|
let SomeType = registry.createType("SomeType", {
|
|
|
|
let SomeNewType = registry.createType("SomeNewType", {
|
|
|
|
value: dm.string()
|
|
|
|
value: dm.string()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let SomeOtherType = registry.createType("SomeOtherType", {
|
|
|
|
let SomeOtherType = registry.createType("SomeOtherType", {
|
|
|
|
things: dm.setOf(registry.type("SomeType")),
|
|
|
|
things: dm.setOf(registry.type("SomeNewType")),
|
|
|
|
thingsMap: dm.mapOf(dm.string(), registry.type("SomeType"))
|
|
|
|
thingsMap: dm.mapOf(dm.string(), registry.type("SomeNewType"))
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let thingOne = SomeType({
|
|
|
|
let thingOne = SomeNewType({
|
|
|
|
value: "one"
|
|
|
|
value: "one"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let thingTwo = SomeType({
|
|
|
|
let thingTwo = SomeNewType({
|
|
|
|
value: "two"
|
|
|
|
value: "two"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -186,7 +186,7 @@ describe("registry", () => {
|
|
|
|
["two", thingTwo]
|
|
|
|
["two", thingTwo]
|
|
|
|
])
|
|
|
|
])
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).to.throw("Expected an instance of SomeType, got a string instead");
|
|
|
|
}).to.throw("Expected an instance of SomeNewType, got a string instead");
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
expect(() => {
|
|
|
|
SomeOtherType({
|
|
|
|
SomeOtherType({
|
|
|
@ -199,7 +199,23 @@ describe("registry", () => {
|
|
|
|
["two", "things"]
|
|
|
|
["two", "things"]
|
|
|
|
])
|
|
|
|
])
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).to.throw("Expected an instance of SomeType, got a string instead");
|
|
|
|
}).to.throw("Expected an instance of SomeNewType, got a string instead");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("should reject duplicate type registrations", () => {
|
|
|
|
|
|
|
|
registry.createType("DuplicateType", {});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
|
|
registry.createType("DuplicateType", {});
|
|
|
|
|
|
|
|
}).to.throw("A type named DuplicateType already exists in this registry");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("should reject duplicate trait registrations", () => {
|
|
|
|
|
|
|
|
registry.createTrait("DuplicateTrait", {});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
|
|
registry.createTrait("DuplicateTrait", {});
|
|
|
|
|
|
|
|
}).to.throw("A trait named DuplicateTrait already exists in this registry");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|