reimplement persistence approach
This commit is contained in:
29
test/diff.tests.js
Normal file
29
test/diff.tests.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { test } from '../node_modules/cutest/cutest.mjs'
|
||||
import simpleDiff from '../src/Util/simpleDiff.js'
|
||||
import Chance from 'chance'
|
||||
|
||||
function runDiffTest (t, a, b, expected) {
|
||||
let result = simpleDiff(a, b)
|
||||
t.compare(result, expected, `Compare "${a}" with "${b}"`)
|
||||
}
|
||||
|
||||
test('diff tests', async function diff1 (t) {
|
||||
runDiffTest(t, 'abc', 'axc', { pos: 1, remove: 1, insert: 'x' })
|
||||
runDiffTest(t, 'bc', 'xc', { pos: 0, remove: 1, insert: 'x' })
|
||||
runDiffTest(t, 'ab', 'ax', { pos: 1, remove: 1, insert: 'x' })
|
||||
runDiffTest(t, 'b', 'x', { pos: 0, remove: 1, insert: 'x' })
|
||||
runDiffTest(t, '', 'abc', { pos: 0, remove: 0, insert: 'abc' })
|
||||
runDiffTest(t, 'abc', 'xyz', { pos: 0, remove: 3, insert: 'xyz' })
|
||||
runDiffTest(t, 'axz', 'au', { pos: 1, remove: 2, insert: 'u' })
|
||||
runDiffTest(t, 'ax', 'axy', { pos: 2, remove: 0, insert: 'y' })
|
||||
})
|
||||
|
||||
test('random diff tests', async function randomDiff (t) {
|
||||
const chance = new Chance(t.getSeed() * 1000000000)
|
||||
let a = chance.word()
|
||||
let b = chance.word()
|
||||
let change = simpleDiff(a, b)
|
||||
let arr = Array.from(a)
|
||||
arr.splice(change.pos, change.remove, ...Array.from(change.insert))
|
||||
t.assert(arr.join('') === b, 'Applying change information is correct')
|
||||
})
|
||||
@@ -54,6 +54,9 @@ test('varString', async function varString (t) {
|
||||
testEncoding(t, writeVarString, readVarString, 'test!')
|
||||
testEncoding(t, writeVarString, readVarString, '☺☺☺')
|
||||
testEncoding(t, writeVarString, readVarString, '1234')
|
||||
testEncoding(t, writeVarString, readVarString, '쾟')
|
||||
testEncoding(t, writeVarString, readVarString, '龟') // surrogate length 3
|
||||
testEncoding(t, writeVarString, readVarString, '😝') // surrogate length 4
|
||||
})
|
||||
|
||||
test('varString random', async function varStringRandom (t) {
|
||||
@@ -3,6 +3,6 @@
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script type="module" src="./encode-decode.js"></script>
|
||||
<script type="module" src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
6
test/index.js
Normal file
6
test/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import './red-black-tree.js'
|
||||
import './y-array.tests.js'
|
||||
import './y-map.tests.js'
|
||||
import './y-xml.tests.js'
|
||||
import './encode-decode.tests.js'
|
||||
import './diff.tests.js'
|
||||
Reference in New Issue
Block a user