- commit
- aafe389e4c5eaf7fd0e5f1eea77f5e17d83d826b
- parent
- 7c2a46d87be81ea2567546e9244ad294fb58ad7c
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-05-08 18:03
add tests
Diffstat
A | static/test.js | 27 | +++++++++++++++++++++++++++ |
1 files changed, 27 insertions, 0 deletions
diff --git a/static/test.js b/static/test.js
@@ -0,0 +1,27 @@ -1 1 import * as context from './context.js'; -1 2 -1 3 var assertEqual = function(a, b, msg) { -1 4 if (JSON.stringify(a) !== JSON.stringify(b)) { -1 5 console.warn('test failed:', msg || '', a, b); -1 6 } else { -1 7 console.log('test passed:', msg || ''); -1 8 } -1 9 }; -1 10 -1 11 var testChange = function(a, b) { -1 12 var diff = context.diff(a, b, 3); -1 13 var actual = context.apply(a, diff); -1 14 assertEqual(actual, b, 'testChange:' + a); -1 15 }; -1 16 -1 17 testChange('', 'asd'); -1 18 testChange('foobar', 'foobarbaz'); -1 19 testChange('foobaz', 'foobarbaz'); -1 20 testChange('barbaz', 'foobarbaz'); -1 21 testChange('asd', 'as'); -1 22 -1 23 assertEqual(context.diff('xxasdz', 'xxasz', 0), [4, 1, 'd', '']); -1 24 assertEqual(context.diff('xxasdz', 'xxasz', 3), [1, 0, 'xasdz', 'xasz']); -1 25 -1 26 assertEqual(context.merge([1, 0, 'foobaz', 'foobbaz'], [2, 1, 'oobba', 'oobaba']), [[1, 0, 'foobaz', 'foobabaz']], 'merge insert'); -1 27 assertEqual(context.merge([1, 1, 'fooba', 'foba'], [0, 0, 'Xfobaz', 'Xfbaz']), [[0, 0, 'Xfoobaz', 'Xfbaz']], 'merge delete');