mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-29 09:22:35 -05:00
eb931fd99b
When importing a project we know the file extension for each asset to be loaded. This change provides that information to the storage system so that we can load assets which don't use the default. For example, this allows loading JPG-format backdrops. In support of this change, there's a new function on `StringUtil` called `splitFirst`, which splits a string on the first instance of a separator character. This change includes unit tests for this new function.
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
const test = require('tap').test;
|
||
const StringUtil = require('../../src/util/string-util');
|
||
|
||
test('splitFirst', t => {
|
||
t.deepEqual(StringUtil.splitFirst('asdf.1234', '.'), ['asdf', '1234']);
|
||
t.deepEqual(StringUtil.splitFirst('asdf.', '.'), ['asdf', '']);
|
||
t.deepEqual(StringUtil.splitFirst('.1234', '.'), ['', '1234']);
|
||
t.deepEqual(StringUtil.splitFirst('foo', '.'), ['foo', null]);
|
||
t.end();
|
||
});
|
||
|
||
test('withoutTrailingDigits', t => {
|
||
t.strictEqual(StringUtil.withoutTrailingDigits('boeing747'), 'boeing');
|
||
t.strictEqual(StringUtil.withoutTrailingDigits('boeing747 '), 'boeing747 ');
|
||
t.strictEqual(StringUtil.withoutTrailingDigits('boeing𝟨'), 'boeing𝟨');
|
||
t.strictEqual(StringUtil.withoutTrailingDigits('boeing 747'), 'boeing ');
|
||
t.strictEqual(StringUtil.withoutTrailingDigits('747'), '');
|
||
t.end();
|
||
});
|
||
|
||
test('unusedName', t => {
|
||
t.strictEqual(
|
||
StringUtil.unusedName(
|
||
'name',
|
||
['not the same name']
|
||
),
|
||
'name'
|
||
);
|
||
t.strictEqual(
|
||
StringUtil.unusedName(
|
||
'name',
|
||
['name']
|
||
),
|
||
'name2'
|
||
);
|
||
t.strictEqual(
|
||
StringUtil.unusedName(
|
||
'name',
|
||
['name30']
|
||
),
|
||
'name'
|
||
);
|
||
t.strictEqual(
|
||
StringUtil.unusedName(
|
||
'name',
|
||
['name', 'name2']
|
||
),
|
||
'name3'
|
||
);
|
||
t.strictEqual(
|
||
StringUtil.unusedName(
|
||
'name',
|
||
['name', 'name3']
|
||
),
|
||
'name2'
|
||
);
|
||
t.strictEqual(
|
||
StringUtil.unusedName(
|
||
'boeing747',
|
||
['boeing747']
|
||
),
|
||
'boeing2' // Yup, this matches scratch-flash...
|
||
);
|
||
t.end();
|
||
});
|