diff --git a/src/prisms.ts b/src/prisms.ts index c2b4e3d..c700b85 100644 --- a/src/prisms.ts +++ b/src/prisms.ts @@ -2,16 +2,13 @@ import { AbstractPrism, Prism } from "./types.ts"; /** * Static methods for prisms - * */ export class Prisms { - /** * Construct a prism that unions a series of prisms. * * - view: returns the first non-null view of the prism series * - set: sets the value of the first prism that has a non-null view - * */ static union(...prisms: Prism[]) { return new class extends AbstractPrism { diff --git a/src/traversals.test.ts b/src/traversals.test.ts new file mode 100644 index 0000000..c166719 --- /dev/null +++ b/src/traversals.test.ts @@ -0,0 +1,49 @@ +import * as Peach from "../../peach.ts/src/mod.ts"; +import * as SubEdit from "./mod.ts"; +import { assertEquals } from "https://deno.land/std@0.171.0/testing/asserts.ts"; + +import { Traversals } from "./traversals.ts"; + +const sampleText = Peach.String.from( + Peach.String.blocks.myanmarExtendedA(Peach.Number.uniform), + Peach.Number.uniform(0, 100), +); + +Deno.test({ + name: "Traversals.union.view: union() == []", + fn() { + const unioned = Traversals.union(); + + for (const tcase of Peach.Array.from(sampleText, 100)()) { + assertEquals(unioned.view(tcase), []); + } + }, +}); + +Deno.test({ + name: "Traversals.union.view: union(traversal) ~ traversal", + fn() { + const traversal = SubEdit.EachMatch(/.{3}/gd); + const unioned = Traversals.union(traversal); + + for (const tcase of Peach.Array.from(sampleText, 100)()) { + assertEquals(unioned.view(tcase), traversal.view(tcase)); + } + }, +}); + +Deno.test({ + name: + "Traversals.union.view: union(traversal, traversal) ~ traversal + traversal", + fn() { + const traversal = SubEdit.EachMatch(/.{3}/gd); + const unioned = Traversals.union(traversal, traversal); + + for (const tcase of Peach.Array.from(sampleText, 100)()) { + assertEquals( + unioned.view(tcase), + traversal.view(tcase).concat(traversal.view(tcase)), + ); + } + }, +}); diff --git a/src/traversals.ts b/src/traversals.ts index 7dc18e9..871b022 100644 --- a/src/traversals.ts +++ b/src/traversals.ts @@ -2,16 +2,13 @@ import { AbstractTraversal, Traversal } from "./types.ts"; /** * Static methods for traversals - * */ export class Traversals { - /** * Construct a traversal that joins the views of multiple traversals. * * - view: returns the concatenation of the views of each traversal * - modify: applies the modifier to the view of each traversal - * */ static union(...traversals: Traversal[]) { return new class extends AbstractTraversal { diff --git a/src/types.ts b/src/types.ts index 47ad7ef..b25efaa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,6 @@ export interface Prism { /* * Partial implementation of the prism interface, leaving view and set abstract - * */ export abstract class AbstractPrism implements Prism { abstract view(whole: Whole): Part | null; @@ -84,7 +83,6 @@ export interface Traversal { /* * Partial implementation of the traversal interface, leaving view and modify abstract - * */ export abstract class AbstractTraversal implements Traversal {