소스 검색

Restructure directories a bit

Joeri Exelmans 2 년 전
부모
커밋
bb04b3f459
3개의 변경된 파일68개의 추가작업 그리고 49개의 파일을 삭제
  1. 6 0
      src/onion/parser.ts
  2. 49 0
      src/parser/trivial_parser.test.ts
  3. 13 49
      src/onion/parser.test.ts

+ 6 - 0
src/onion/parser.ts

@@ -0,0 +1,6 @@
+export 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;
+}

+ 49 - 0
src/parser/trivial_parser.test.ts

@@ -0,0 +1,49 @@
+import {TrivialParser} from "./trivial_parser";
+
+import {
+  initialVersion,
+  VersionRegistry,
+} from "../onion/version";
+
+import {
+  NodeCreation,
+  NodeDeletion,
+  EdgeCreation,
+  EdgeUpdate,
+} from "../onion/primitive_delta";
+
+import {CompositeLevel} from "../onion/composite_delta";
+import {mockUuid} from "../onion/test_helpers";
+import {assert} from "../util/assert";
+
+describe("Trivial 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");
+  });
+});

+ 13 - 49
src/onion/parser.test.ts

@@ -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");
-  });
-});