|
@@ -1,24 +1,27 @@
|
|
|
-import {Delta} from "./delta";
|
|
|
+import {Parser} from "../onion/parser";
|
|
|
+
|
|
|
+import {Delta} from "../onion/delta";
|
|
|
+import {UUID} from "../onion/types";
|
|
|
+import {visitPartialOrdering} from "../util/partial_ordering";
|
|
|
+
|
|
|
import {
|
|
|
- initialVersion,
|
|
|
Version,
|
|
|
VersionRegistry,
|
|
|
embed,
|
|
|
-} from "./version";
|
|
|
+} from "../onion/version";
|
|
|
+
|
|
|
import {
|
|
|
NodeCreation,
|
|
|
NodeDeletion,
|
|
|
EdgeCreation,
|
|
|
EdgeUpdate,
|
|
|
-} from "./primitive_delta";
|
|
|
+} from "../onion/primitive_delta";
|
|
|
+
|
|
|
import {
|
|
|
CompositeLevel,
|
|
|
CompositeDelta,
|
|
|
-} from "./composite_delta";
|
|
|
-import {mockUuid} from "./test_helpers";
|
|
|
-import {UUID} from "./types";
|
|
|
-import {assert} from "../util/assert";
|
|
|
-import {visitPartialOrdering} from "../util/partial_ordering";
|
|
|
+} from "../onion/composite_delta";
|
|
|
+
|
|
|
|
|
|
function getParentLink(cs: Version, parentCorr: Version): [Version,Delta] {
|
|
|
const parentCsEmbedding = parentCorr.getEmbedded("cs");
|
|
@@ -32,15 +35,8 @@ function getParentLink(cs: Version, parentCorr: Version): [Version,Delta] {
|
|
|
return csParentLink;
|
|
|
}
|
|
|
|
|
|
-interface Parser {
|
|
|
- // cs: the new (modified) CS version
|
|
|
- // parentCorr: the latest CORR version, that embeds the parent of 'cs'.
|
|
|
- // Returns a new CORR version that embeds 'cs'.
|
|
|
- parse(cs: Version, parentCorr: Version): Version;
|
|
|
-}
|
|
|
-
|
|
|
// A parser that creates an AS-node for every CS-node, with a Corr-node in between.
|
|
|
-class TrivialParser implements Parser {
|
|
|
+export class TrivialParser implements Parser {
|
|
|
readonly registry: VersionRegistry;
|
|
|
|
|
|
readonly csLvl: CompositeLevel;
|
|
@@ -145,35 +141,3 @@ class TrivialParser implements Parser {
|
|
|
return this.registry.createVersion(parentCorr, corrComposite, embed(["cs", cs, csOverrides], ["as", as, asOverrides]));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-describe("Parser", () => {
|
|
|
- it("Parse CS creation and deletion", () => {
|
|
|
- const registry = new VersionRegistry();
|
|
|
- const csLvl = new CompositeLevel();
|
|
|
- const asLvl = new CompositeLevel();
|
|
|
- const corrLvl = new CompositeLevel();
|
|
|
- const getUuid = mockUuid();
|
|
|
- const parser = new TrivialParser(registry, csLvl, asLvl, corrLvl, getUuid);
|
|
|
-
|
|
|
- const csInitial = initialVersion;
|
|
|
- const corrInitial = initialVersion;
|
|
|
- const asInitital = initialVersion;
|
|
|
-
|
|
|
- const csCreation = new NodeCreation(getUuid());
|
|
|
- const csDeletion = new NodeDeletion(csCreation, [], []);
|
|
|
-
|
|
|
- const csV1 = registry.createVersion(csInitial, csLvl.createComposite([csCreation]));
|
|
|
- const csV2 = registry.createVersion(csV1, csLvl.createComposite([csDeletion]));
|
|
|
-
|
|
|
- const corrV1 = parser.parse(csV1, corrInitial);
|
|
|
- const corrV2 = parser.parse(csV2, corrV1);
|
|
|
-
|
|
|
- const asV2 = corrV2.getEmbedded("as")?.embedded;
|
|
|
- if (asV2 === undefined) {
|
|
|
- throw new Error("Expected asV2 to exist!");
|
|
|
- }
|
|
|
-
|
|
|
- const asV2Primitives = [...asV2.iterPrimitiveDeltas()];
|
|
|
- assert(asV2Primitives.length === 2, "Expected 2 primitive deltas on AS");
|
|
|
- });
|
|
|
-});
|