Rename folders

This commit is contained in:
Christopher Schleiden
2023-02-22 15:52:40 -08:00
parent 16cc4d9bda
commit 2a3d63551f
469 changed files with 0 additions and 0 deletions
@@ -0,0 +1,31 @@
import {StringData} from "../data";
import {DescriptionDictionary} from "./descriptionDictionary";
describe("description dictionary", () => {
it("pairs contains all values", () => {
const d = new DescriptionDictionary();
d.add("ABC", new StringData("val"));
expect(d.pairs()).toEqual([{key: "ABC", value: new StringData("val")}]);
});
it("does not add duplicate entries", () => {
const d = new DescriptionDictionary();
d.add("ABC", new StringData("val1"));
d.add("ABC", new StringData("val2"));
d.add("abc", new StringData("val3"));
expect(d.pairs()).toEqual([{key: "ABC", value: new StringData("val1")}]);
});
it("can set optional descriptions", () => {
const d = new DescriptionDictionary();
d.add("ABC", new StringData("val"), "desc");
d.add("DEF", new StringData("val"));
expect(d.pairs()).toEqual([
{key: "ABC", value: new StringData("val"), description: "desc"},
{key: "DEF", value: new StringData("val")}
]);
});
});
@@ -0,0 +1,42 @@
import {Dictionary} from "../data/dictionary";
import {ExpressionData, Kind, Pair} from "../data/expressiondata";
export type DescriptionPair = Pair & {description?: string};
export function isDescriptionDictionary(x: ExpressionData): x is DescriptionDictionary {
return x.kind === Kind.Dictionary && x instanceof DescriptionDictionary;
}
export class DescriptionDictionary extends Dictionary {
private readonly descriptions = new Map<string, string>();
public complete: boolean = true;
constructor(...pairs: DescriptionPair[]) {
super();
for (const p of pairs) {
this.add(p.key, p.value, p.description);
}
}
override add(key: string, value: ExpressionData, description?: string): void {
if (this.get(key) !== undefined) {
// Key already added, ignore
return;
}
super.add(key, value);
if (description) {
this.descriptions.set(key, description);
}
}
override pairs(): DescriptionPair[] {
const pairs = super.pairs();
return pairs.map(p => ({...p, description: this.descriptions.get(p.key)}));
}
getDescription(key: string): string | undefined {
return this.descriptions.get(key);
}
}