});
it("[[Construct]] defaults the preferred label to the empty string", () => {
- assertStrictEquals(new Tag().prefLabel, "");
+ assertEquals({ ...new Tag().prefLabel }, { "@value": "" });
});
it("[[Construct]] correctly sets the preferred label to a simple string", () => {
- assertStrictEquals(
- new Tag("RelationshipTag", "Shadow, Me").prefLabel,
- "Shadow, Me",
+ assertEquals(
+ { ...new Tag("RelationshipTag", "Shadow, Me").prefLabel },
+ { "@value": "Shadow, Me" },
);
});
});
});
+ describe(".constructor", () => {
+ it("[[Get]] is `Function`", () => {
+ assertStrictEquals(Tag.constructor, Function);
+ });
+ });
+
describe(".fromIRI", () => {
it("[[Call]] returns the persisted tag with the given I·R·I", () => {
const tag = new Tag();
assertStrictEquals(retrieved.identifier, identifier);
});
- it("[[Call]] returns null if no tag with the given I·R·I has been persisted", () => {
+ it("[[Call]] returns undefined if no tag with the given I·R·I has been persisted", () => {
assertStrictEquals(
Tag.fromIRI(
`https://${system.authorityName}/tag:${system.taggingEntity}:000-0000`,
),
- null,
+ undefined,
);
});
- it("[[Call]] returns null if passed an invalid I·R·I", () => {
- assertStrictEquals(Tag.fromIRI(`bad iri`), null);
+ it("[[Call]] throws if passed an invalid I·R·I", () => {
+ assertThrows(() => {
+ Tag.fromIRI(`bad iri`);
+ });
});
});
assertStrictEquals(retrieved.identifier, identifier);
});
- it("[[Call]] returns null if no tag with the given identifier has been persisted", () => {
- assertStrictEquals(Tag.fromIdentifier("000-0000"), null);
+ it("[[Call]] returns undefined if no tag with the given identifier has been persisted", () => {
+ assertStrictEquals(Tag.fromIdentifier("000-0000"), undefined);
});
it("[[Call]] throws if passed an invalid identifier", () => {
assertStrictEquals(retrieved.identifier, identifier);
});
- it("[[Call]] returns null if no tag with the given Tag U·R·I has been persisted", () => {
+ it("[[Call]] returns undefined if no tag with the given Tag U·R·I has been persisted", () => {
assertStrictEquals(
- Tag.fromIRI(`tag:${system.taggingEntity}:`),
- null,
+ Tag.fromTagURI(`tag:${system.taggingEntity}:`),
+ undefined,
);
assertStrictEquals(
- Tag.fromIRI(`tag:${system.taggingEntity}:000-0000`),
- null,
+ Tag.fromTagURI(`tag:${system.taggingEntity}:000-0000`),
+ undefined,
);
});
});
});
- describe(".getSystem", () => {
- it("[[Has]] is not present", () => {
- assertFalse("getSystem" in Tag);
- });
- });
-
describe(".identifiers", () => {
it("[[Call]] yields all the persisted identifiers", () => {
const tags = new Set(function* () {
{ "@value": "three", "@language": "en" },
);
assertEquals(
- Array.from(
- tag.altLabels(),
- ($) => typeof $ == "string" ? $ : { ...$ },
- ),
+ Array.from(tag.altLabels(), ($) => ({ ...$ })),
[
- "one",
- "two",
+ { "@value": "one" },
+ { "@value": "two" },
{ "@value": "three", "@language": "en" },
],
);
{ "@value": "three", "@language": "en" },
);
assertEquals(
- Array.from(
- tag.hiddenLabels(),
- ($) => typeof $ == "string" ? $ : { ...$ },
- ),
+ Array.from(tag.hiddenLabels(), ($) => ({ ...$ })),
[
- "one",
- "two",
+ { "@value": "one" },
+ { "@value": "two" },
{ "@value": "three", "@language": "en" },
],
);
});
it("[[Call]] throws when this is not a tag which can be placed in canon", () => {
+ const canon = new Tag("CanonTag");
+ canon.persist();
assertThrows(() => {
- new Tag().addInCanonTag();
+ new Tag().addInCanonTag(canon);
});
});
});
it("[[Call]] throws when this is not a conceptual tag", () => {
+ const involved = new Tag();
+ involved.persist();
assertThrows(() => {
- new Tag().addInvolvesTag();
+ new Tag().addInvolvesTag(involved);
});
});
const tag = new Tag();
tag.addAltLabel("etaoin");
tag.deleteAltLabel();
- assertEquals([...tag.altLabels()], ["etaoin"]);
+ assertEquals(
+ Array.from(tag.altLabels(), ($) => ({ ...$ })),
+ [{ "@value": "etaoin" }],
+ );
});
it("[[Call]] deletes only the provided hidden labels", () => {
{ "@value": "three", "@language": "en" },
{ "@value": "four", "@language": "en" },
);
- assertEquals([...tag.altLabels()], ["four"]);
+ assertEquals(
+ Array.from(tag.altLabels(), ($) => ({ ...$ })),
+ [{ "@value": "four" }],
+ );
});
it("[[Call]] returns this", () => {
const tag = new Tag();
tag.addHiddenLabel("etaoin");
tag.deleteHiddenLabel();
- assertEquals([...tag.hiddenLabels()], ["etaoin"]);
+ assertEquals(
+ Array.from(tag.hiddenLabels(), ($) => ({ ...$ })),
+ [{ "@value": "etaoin" }],
+ );
});
it("[[Call]] deletes only the provided alternative labels", () => {
{ "@value": "three", "@language": "en" },
{ "@value": "four", "@language": "en" },
);
- assertEquals([...tag.hiddenLabels()], ["four"]);
+ assertEquals(
+ Array.from(tag.hiddenLabels(), ($) => ({ ...$ })),
+ [{ "@value": "four" }],
+ );
});
it("[[Call]] returns this", () => {
// `::iri` is tested by a `.fromIRI`.
+ // `::iriSpace` is tested by a `.fromIRI`.
+
// `::kind` is tested by the constructor.
describe("::narrowerTags", () => {
it("[[Set]] sets the preferred label", () => {
const tag = new Tag();
tag.prefLabel = "one";
- assertStrictEquals(tag.prefLabel, "one");
+ assertEquals({ ...tag.prefLabel }, { "@value": "one" });
tag.prefLabel = { "@value": "two" };
- assertStrictEquals(tag.prefLabel, "two");
+ assertEquals({ ...tag.prefLabel }, { "@value": "two" });
tag.prefLabel = { "@value": "three", "@language": "en" };
assertEquals(
{ ...tag.prefLabel },
});
});
+ describe("::iriSpace", () => {
+ it("[[Get]] returns the I·R·I space", () => {
+ const system = new TagSystem("etaoin.example", "1972-12-31");
+ assertStrictEquals(
+ system.iriSpace,
+ "https://etaoin.example/tag:etaoin.example,1972-12-31:",
+ );
+ const system2 = new TagSystem(
+ "etaoin.example",
+ "1972-12-31",
+ "etaoin",
+ );
+ assertStrictEquals(
+ system2.iriSpace,
+ "https://etaoin.example/tag:etaoin.example,1972-12-31:",
+ );
+ });
+ });
+
describe("::tagURI", () => {
it("[[Get]] returns the Tag U·R·I", () => {
const system = new TagSystem("etaoin.example", "1972-12-31");