Skip to content

Commit

Permalink
added compose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrannell1 committed Jul 3, 2023
1 parent e5fd395 commit 1fd6a5e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
14 changes: 8 additions & 6 deletions src/prism.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ Deno.test({

assertEquals(
identity.view(whole),
identity.composePrism(identity).view(whole));
identity.composePrism(identity).view(whole),
);

assertEquals(
identity.set(part, whole),
identity.composePrism(identity).set(part, whole));
assertEquals(
identity.set(part, whole),
identity.composePrism(identity).set(part, whole),
);
}
}
});
},
});
47 changes: 37 additions & 10 deletions src/traversal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,11 @@ Deno.test({

Deno.test({
name: "EachMatch.modify: modify is invoked elementwise",
fn () {

fn() {
const numberPairs = SubEdit.EachMatch(/[0-9]{2}/dg);

for (const whole of Peach.Array.from(sampleNumbers, 100)()) {
const expectedLength0 = numberPairs.view(whole)
const expectedLength0 = numberPairs.view(whole);

let actualLength0 = 0;
numberPairs.modify((pair: string) => {
Expand All @@ -129,16 +128,16 @@ Deno.test({

assertEquals(expectedLength0, expectedLength0);
}
}
})
},
});

Deno.test({
name: "EachGroupMatch.modify: modify is invoked elementwise",
fn () {
fn() {
const numberPairsGroup = SubEdit.EachGroupMatch(/([0-9]){2}/dg, 1);

for (const whole of Peach.Array.from(sampleNumbers, 100)()) {
const expectedLength1 = numberPairsGroup.view(whole)
const expectedLength1 = numberPairsGroup.view(whole);

let actualLength1 = 0;
numberPairsGroup.modify((pair: string) => {
Expand All @@ -148,8 +147,36 @@ Deno.test({

assertEquals(expectedLength1, expectedLength1);
}
}
})

},
});

// ++++ Traversal Composition ++++ //
Deno.test({
name:
"Traversal.composePrism.view: an always match prism acts as the original traversal",
fn() {
const digit = SubEdit.EachMatch(/[0-9]/dg);
const digitPrism = SubEdit.MaybeMatch(/[0-9]/d);

const composed = digit.composePrism(digitPrism);

for (const whole of Peach.Array.from(sampleNumbers, 100)()) {
assertEquals(composed.view(whole), digit.view(whole));
}
},
});

Deno.test({
name:
"Traversal.composePrism.view: an always match prism acts as the original traversal",
fn() {
const digit = SubEdit.EachMatch(/[0-9]/dg);
const digitPrism = SubEdit.MaybeMatch(/[0-9]{2}/d);

const composed = digit.composePrism(digitPrism);

for (const whole of Peach.Array.from(sampleNumbers, 100)()) {
assertEquals(composed.view(whole), []);
}
},
});
2 changes: 1 addition & 1 deletion src/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function EachGroupMatch(
// the pattern matched, but not the group.
// this can be legitimately empty depending on the regexp
if (text === undefined) {
continue
continue;
}

const boundaries = (match as RegExpMatchArrayIndexed).indices[index];
Expand Down

0 comments on commit 1fd6a5e

Please sign in to comment.