-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87cefe1
commit 1e289d7
Showing
7 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { assert, assertEquals } from '@std/assert' | ||
import { Diff, DiffOperation } from './Diff.ts' | ||
|
||
Deno.test(Diff.name, async (t) => { | ||
await t.step('TypeScript validates inputs', () => { | ||
;(() => { | ||
new Diff(0, 'a') | ||
new Diff(1, 'a') | ||
new Diff(-1, 'a') | ||
|
||
// @ts-expect-error wrong order | ||
new Diff('a', 1) | ||
// @ts-expect-error 2 is not a valid op | ||
new Diff(2, 'a') | ||
// @ts-expect-error -2 is not a valid op | ||
new Diff(-2, 'a') | ||
})() | ||
}) | ||
|
||
await t.step('diff.op', () => { | ||
assertEquals(new Diff(DiffOperation.Delete, 'a').op, -1) | ||
assertEquals(new Diff(DiffOperation.Equal, 'a').op, 0) | ||
assertEquals(new Diff(DiffOperation.Insert, 'a').op, 1) | ||
}) | ||
|
||
await t.step('other getters', () => { | ||
const diff = new Diff(DiffOperation.Equal, 'a') | ||
assertEquals(diff.text, 'a') | ||
assertEquals(diff.length, 2) | ||
}) | ||
|
||
await t.step('JSON.stringify', () => { | ||
const diff = new Diff(DiffOperation.Equal, 'a') | ||
assertEquals(JSON.stringify(diff), '[0,"a"]') | ||
}) | ||
|
||
await t.step('iterate', () => { | ||
const diff = new Diff(DiffOperation.Equal, 'a') | ||
assertEquals([...diff], [0, 'a']) | ||
}) | ||
|
||
await t.step('inspect', () => { | ||
const diff = new Diff(DiffOperation.Equal, 'a') | ||
assertEquals(Deno.inspect(diff, { colors: false }), 'Diff #[ 0, "a" ]') | ||
assertEquals(Deno.inspect(diff, { colors: true }), 'Diff #[ \x1b[33m0\x1b[39m, \x1b[32m"a"\x1b[39m ]') | ||
}) | ||
|
||
await t.step('clone', () => { | ||
const diff = new Diff(DiffOperation.Equal, 'a') | ||
// value-equal | ||
assertEquals(diff, diff.clone()) | ||
// not reference-equal | ||
assert(diff !== diff.clone()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { assert, assertInstanceOf, assertThrows } from '@std/assert' | ||
import { makeDiff } from './utils.ts' | ||
import { Diff } from './Diff.ts' | ||
|
||
Deno.test(makeDiff.name, async (t) => { | ||
await t.step('instanceof', () => { | ||
assertInstanceOf(makeDiff([0, 'a']), Diff) | ||
}) | ||
|
||
await t.step('returns `Diff` input unchanged', () => { | ||
const diff = makeDiff([0, 'a']) | ||
// reference-equal | ||
assert(diff === diff) | ||
}) | ||
|
||
await t.step('validates inputs at runtime', () => { | ||
makeDiff([0, 'a']) | ||
makeDiff([1, 'a']) | ||
makeDiff([-1, 'a']) | ||
|
||
assertThrows(() => makeDiff([1, 1]), Error, 'Invalid text') | ||
assertThrows(() => makeDiff(['a', '1']), Error, 'Invalid op') | ||
assertThrows(() => makeDiff(['a', 1]), Error, 'Invalid text') | ||
assertThrows(() => makeDiff([2, 'a']), Error, 'Invalid op') | ||
assertThrows(() => makeDiff([-2, 'a']), Error, 'Invalid op') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters