Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
52
scratch-vm/test/unit/util_xml.js
Normal file
52
scratch-vm/test/unit/util_xml.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const test = require('tap').test;
|
||||
const xml = require('../../src/util/xml-escape');
|
||||
|
||||
test('escape', t => {
|
||||
const input = '<foo bar="he & llo \'"></foo>';
|
||||
const output = '<foo bar="he & llo '"></foo>';
|
||||
t.strictEqual(xml(input), output);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('xmlEscape (more)', t => {
|
||||
const empty = '';
|
||||
t.equal(xml(empty), empty);
|
||||
|
||||
const safe = 'hello';
|
||||
t.equal(xml(safe), safe);
|
||||
|
||||
const unsafe = '< > & \' "';
|
||||
t.equal(xml(unsafe), '< > & ' "');
|
||||
|
||||
const single = '&';
|
||||
t.equal(xml(single), '&');
|
||||
|
||||
const mix = '<a>b& c\'def_-"';
|
||||
t.equal(xml(mix), '<a>b& c'def_-"');
|
||||
|
||||
const dupes = '<<&_"_"_&>>';
|
||||
t.equal(xml(dupes), '<<&_"_"_&>>');
|
||||
|
||||
const emoji = '(>^_^)>';
|
||||
t.equal(xml(emoji), '(>^_^)>');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('xmlEscape should handle non strings', t => {
|
||||
const array = ['hello', 'world'];
|
||||
t.equal(xml(array), String(array));
|
||||
|
||||
const arrayWithSpecialChar = ['hello', '<world>'];
|
||||
t.equal(xml(arrayWithSpecialChar), 'hello,<world>');
|
||||
|
||||
const arrayWithNumbers = [1, 2, 3];
|
||||
t.equal(xml(arrayWithNumbers), '1,2,3');
|
||||
|
||||
// Objects shouldn't get provided to replaceUnsafeChars, but in the event
|
||||
// they do, it should just return the object (and log an error)
|
||||
const object = {hello: 'world'};
|
||||
t.equal(xml(object), object);
|
||||
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user