Created
July 6, 2022 17:06
-
-
Save aleclarson/b447b7f05fe14eda49b1cbb6f8dab959 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const MagicString = require('magic-string'); | |
const assert = require('assert'); | |
const kleur = require('kleur'); | |
function test() { | |
const s1 = new MagicString('abcde'); | |
const s2 = s1.clone(); | |
const desiredResult = 'abxcde'; | |
// Sanity check without remove call. | |
s2.prependRight(2, 'x'); | |
assert(s2.toString() == desiredResult, `Sanity check failed!`); | |
// Prove that current methods are not | |
// sufficient for the desired behavior. | |
s1.remove(1, 3); | |
assert(s1.toString() == 'ade'); | |
// Restore the removed range with appendLeft. | |
s1.appendLeft(1, s1.original.slice(1, 3)); | |
assert(s1.toString() == 'abcde'); | |
// But now prependRight behaves differently when | |
// compared with the sanity check. | |
s1.prependRight(2, 'x'); | |
assert(s1.toString() == desiredResult, `${s1} !== ${desiredResult}`); | |
} | |
try { | |
test(); | |
console.log(kleur.green('All assertions passed!')); | |
} catch (e) { | |
console.error(kleur.red(e.message)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment