mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier * chore: remove clang-format * chore: remove clang-format config * chore: lint additional ts files * chore: fix lint errors in blocks * chore: add prettier-ignore where needed * chore: ignore js blocks when formatting * chore: fix playground html syntax * chore: fix yaml spacing from merge * chore: convert text blocks to use arrow functions * chore: format everything with prettier * chore: fix lint unused imports in blocks
This commit is contained in:
committed by
GitHub
parent
af991f5e1b
commit
88ff901a72
@@ -6,18 +6,20 @@
|
||||
|
||||
goog.declareModuleId('Blockly.test.utils');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Utils', function() {
|
||||
setup(function() {
|
||||
suite('Utils', function () {
|
||||
setup(function () {
|
||||
sharedTestSetup.call(this);
|
||||
});
|
||||
teardown(function() {
|
||||
teardown(function () {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
test('genUid', function() {
|
||||
test('genUid', function () {
|
||||
const uuids = {};
|
||||
chai.assert.equal([1, 2, 3].indexOf(4), -1);
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
@@ -27,160 +29,187 @@ suite('Utils', function() {
|
||||
}
|
||||
});
|
||||
|
||||
suite('tokenizeInterpolation', function() {
|
||||
suite('Basic', function() {
|
||||
test('Empty string', function() {
|
||||
chai.assert.deepEqual(Blockly.utils.parsing.tokenizeInterpolation(''), []);
|
||||
suite('tokenizeInterpolation', function () {
|
||||
suite('Basic', function () {
|
||||
test('Empty string', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation(''),
|
||||
[]
|
||||
);
|
||||
});
|
||||
|
||||
test('No interpolation', function() {
|
||||
test('No interpolation', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello'), ['Hello']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello'),
|
||||
['Hello']
|
||||
);
|
||||
});
|
||||
|
||||
test('Unescaped %', function() {
|
||||
test('Unescaped %', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello%World'),
|
||||
['Hello%World']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello%World'),
|
||||
['Hello%World']
|
||||
);
|
||||
});
|
||||
|
||||
test('Escaped %', function() {
|
||||
test('Escaped %', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello%%World'),
|
||||
['Hello%World']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello%%World'),
|
||||
['Hello%World']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Number interpolation', function() {
|
||||
test('Single-digit number interpolation', function() {
|
||||
suite('Number interpolation', function () {
|
||||
test('Single-digit number interpolation', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello%1World'),
|
||||
['Hello', 1, 'World']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello%1World'),
|
||||
['Hello', 1, 'World']
|
||||
);
|
||||
});
|
||||
|
||||
test('Multi-digit number interpolation', function() {
|
||||
test('Multi-digit number interpolation', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%123Hello%456World%789'),
|
||||
[123, 'Hello', 456, 'World', 789]);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%123Hello%456World%789'),
|
||||
[123, 'Hello', 456, 'World', 789]
|
||||
);
|
||||
});
|
||||
|
||||
test('Escaped number', function() {
|
||||
test('Escaped number', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello %%1 World'),
|
||||
['Hello %1 World']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('Hello %%1 World'),
|
||||
['Hello %1 World']
|
||||
);
|
||||
});
|
||||
|
||||
test('Crazy interpolation', function() {
|
||||
test('Crazy interpolation', function () {
|
||||
// No idea what this is supposed to tell you if it breaks. But might
|
||||
// as well keep it.
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%%%x%%0%00%01%'),
|
||||
['%%x%0', 0, 1, '%']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%%%x%%0%00%01%'),
|
||||
['%%x%0', 0, 1, '%']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
suite('String table interpolation', function() {
|
||||
test('Simple interpolation', function() {
|
||||
suite('String table interpolation', function () {
|
||||
test('Simple interpolation', function () {
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string_ref}'),
|
||||
['test string']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string_ref}'),
|
||||
['test string']
|
||||
);
|
||||
});
|
||||
|
||||
test('Case', function() {
|
||||
test('Case', function () {
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{BkY_StRiNg_ReF}'),
|
||||
['test string']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{BkY_StRiNg_ReF}'),
|
||||
['test string']
|
||||
);
|
||||
});
|
||||
|
||||
test('Surrounding text', function() {
|
||||
test('Surrounding text', function () {
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation(
|
||||
'before %{bky_string_ref} after'),
|
||||
['before test string after']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation(
|
||||
'before %{bky_string_ref} after'
|
||||
),
|
||||
['before test string after']
|
||||
);
|
||||
});
|
||||
|
||||
test('With param', function() {
|
||||
test('With param', function () {
|
||||
Blockly.Msg.WITH_PARAM = 'before %1 after';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_with_param}'),
|
||||
['before ', 1, ' after']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_with_param}'),
|
||||
['before ', 1, ' after']
|
||||
);
|
||||
});
|
||||
|
||||
test('Recursive reference', function() {
|
||||
test('Recursive reference', function () {
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
Blockly.Msg.RECURSE = 'before %{bky_string_ref} after';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_recurse}'),
|
||||
['before test string after']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_recurse}'),
|
||||
['before test string after']
|
||||
);
|
||||
});
|
||||
|
||||
test('Number reference', function() {
|
||||
test('Number reference', function () {
|
||||
Blockly.Msg['1'] = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_1}'), ['test string']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_1}'),
|
||||
['test string']
|
||||
);
|
||||
});
|
||||
|
||||
test('Undefined reference', function() {
|
||||
test('Undefined reference', function () {
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_undefined}'),
|
||||
['%{bky_undefined}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_undefined}'),
|
||||
['%{bky_undefined}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Not prefixed', function() {
|
||||
test('Not prefixed', function () {
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{string_ref}'),
|
||||
['%{string_ref}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{string_ref}'),
|
||||
['%{string_ref}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Not prefixed, number', function() {
|
||||
test('Not prefixed, number', function () {
|
||||
Blockly.Msg['1'] = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{1}'),
|
||||
['%{1}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{1}'),
|
||||
['%{1}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Space in ref', function() {
|
||||
test('Space in ref', function () {
|
||||
Blockly.Msg['string ref'] = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string ref}'),
|
||||
['%{bky_string ref}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string ref}'),
|
||||
['%{bky_string ref}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Dash in ref', function() {
|
||||
test('Dash in ref', function () {
|
||||
Blockly.Msg['string-ref'] = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string-ref}'),
|
||||
['%{bky_string-ref}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string-ref}'),
|
||||
['%{bky_string-ref}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Period in ref', function() {
|
||||
test('Period in ref', function () {
|
||||
Blockly.Msg['string.ref'] = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string.ref}'),
|
||||
['%{bky_string.ref}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string.ref}'),
|
||||
['%{bky_string.ref}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Ampersand in ref', function() {
|
||||
test('Ampersand in ref', function () {
|
||||
Blockly.Msg['string&ref'] = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string&ref}'),
|
||||
['%{bky_string&ref}']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_string&ref}'),
|
||||
['%{bky_string&ref}']
|
||||
);
|
||||
});
|
||||
|
||||
test('Unclosed reference', function() {
|
||||
test('Unclosed reference', function () {
|
||||
Blockly.Msg.UNCLOSED = 'test string';
|
||||
chai.assert.deepEqual(
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_unclosed'),
|
||||
['%{bky_unclosed']);
|
||||
Blockly.utils.parsing.tokenizeInterpolation('%{bky_unclosed'),
|
||||
['%{bky_unclosed']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('replaceMessageReferences', function() {
|
||||
test('replaceMessageReferences', function () {
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
Blockly.Msg.SUBREF = 'subref';
|
||||
Blockly.Msg.STRING_REF_WITH_ARG = 'test %1 string';
|
||||
@@ -192,46 +221,79 @@ suite('Utils', function() {
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences('%%');
|
||||
chai.assert.equal(resultString, '%', 'Escaped %');
|
||||
resultString =
|
||||
Blockly.utils.parsing.replaceMessageReferences('%%{bky_string_ref}');
|
||||
Blockly.utils.parsing.replaceMessageReferences('%%{bky_string_ref}');
|
||||
chai.assert.equal(resultString, '%{bky_string_ref}', 'Escaped %');
|
||||
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences('%a');
|
||||
chai.assert.equal(resultString, '%a', 'Unrecognized % escape code treated as literal');
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'%a',
|
||||
'Unrecognized % escape code treated as literal'
|
||||
);
|
||||
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences('%1');
|
||||
chai.assert.equal(resultString, '%1', 'Interpolation tokens ignored.');
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences('%1 %2');
|
||||
chai.assert.equal(resultString, '%1 %2', 'Interpolation tokens ignored.');
|
||||
resultString =
|
||||
Blockly.utils.parsing.replaceMessageReferences('before %1 after');
|
||||
chai.assert.equal(resultString, 'before %1 after', 'Interpolation tokens ignored.');
|
||||
Blockly.utils.parsing.replaceMessageReferences('before %1 after');
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'before %1 after',
|
||||
'Interpolation tokens ignored.'
|
||||
);
|
||||
|
||||
// Blockly.Msg.STRING_REF cases:
|
||||
resultString =
|
||||
Blockly.utils.parsing.replaceMessageReferences('%{bky_string_ref}');
|
||||
Blockly.utils.parsing.replaceMessageReferences('%{bky_string_ref}');
|
||||
chai.assert.equal(resultString, 'test string', 'Message ref dereferenced.');
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences(
|
||||
'before %{bky_string_ref} after');
|
||||
chai.assert.equal(resultString, 'before test string after', 'Message ref dereferenced.');
|
||||
'before %{bky_string_ref} after'
|
||||
);
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'before test string after',
|
||||
'Message ref dereferenced.'
|
||||
);
|
||||
|
||||
// Blockly.Msg.STRING_REF_WITH_ARG cases:
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences(
|
||||
'%{bky_string_ref_with_arg}');
|
||||
chai.assert.equal(resultString, 'test %1 string', 'Message ref dereferenced with argument preserved.');
|
||||
'%{bky_string_ref_with_arg}'
|
||||
);
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'test %1 string',
|
||||
'Message ref dereferenced with argument preserved.'
|
||||
);
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences(
|
||||
'before %{bky_string_ref_with_arg} after');
|
||||
chai.assert.equal(resultString, 'before test %1 string after', 'Message ref dereferenced with argument preserved.');
|
||||
'before %{bky_string_ref_with_arg} after'
|
||||
);
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'before test %1 string after',
|
||||
'Message ref dereferenced with argument preserved.'
|
||||
);
|
||||
|
||||
// Blockly.Msg.STRING_REF_WITH_SUBREF cases:
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences(
|
||||
'%{bky_string_ref_with_subref}');
|
||||
chai.assert.equal(resultString, 'test subref string', 'Message ref and subref dereferenced.');
|
||||
'%{bky_string_ref_with_subref}'
|
||||
);
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'test subref string',
|
||||
'Message ref and subref dereferenced.'
|
||||
);
|
||||
resultString = Blockly.utils.parsing.replaceMessageReferences(
|
||||
'before %{bky_string_ref_with_subref} after');
|
||||
chai.assert.equal(resultString, 'before test subref string after', 'Message ref and subref dereferenced.');
|
||||
'before %{bky_string_ref_with_subref} after'
|
||||
);
|
||||
chai.assert.equal(
|
||||
resultString,
|
||||
'before test subref string after',
|
||||
'Message ref and subref dereferenced.'
|
||||
);
|
||||
});
|
||||
|
||||
test('arrayRemove', function() {
|
||||
test('arrayRemove', function () {
|
||||
const arr = [1, 2, 3, 2];
|
||||
chai.assert.isFalse(Blockly.utils.arrayRemove(arr, 0), 'Remove Not found');
|
||||
chai.assert.equal(arr.join(','), '1,2,3,2', 'Remove Not found result');
|
||||
@@ -241,7 +303,7 @@ suite('Utils', function() {
|
||||
chai.assert.equal(arr.join(','), '1,3', 'Remove item again result');
|
||||
});
|
||||
|
||||
test('XY_REGEX_', function() {
|
||||
test('XY_REGEX_', function () {
|
||||
const regex = Blockly.utils.svgMath.TEST_ONLY.XY_REGEX;
|
||||
let m;
|
||||
m = 'INVALID'.match(regex);
|
||||
@@ -264,11 +326,19 @@ suite('Utils', function() {
|
||||
chai.assert.equal(m[3], '16', 'translate(15 16), y');
|
||||
|
||||
m = 'translate(1.23456e+42 0.123456e-42)'.match(regex);
|
||||
chai.assert.equal(m[1], '1.23456e+42', 'translate(1.23456e+42 0.123456e-42), x');
|
||||
chai.assert.equal(m[3], '0.123456e-42', 'translate(1.23456e+42 0.123456e-42), y');
|
||||
chai.assert.equal(
|
||||
m[1],
|
||||
'1.23456e+42',
|
||||
'translate(1.23456e+42 0.123456e-42), x'
|
||||
);
|
||||
chai.assert.equal(
|
||||
m[3],
|
||||
'0.123456e-42',
|
||||
'translate(1.23456e+42 0.123456e-42), y'
|
||||
);
|
||||
});
|
||||
|
||||
test('XY_STYLE_REGEX_', function() {
|
||||
test('XY_STYLE_REGEX_', function () {
|
||||
const regex = Blockly.utils.svgMath.TEST_ONLY.XY_STYLE_REGEX;
|
||||
let m;
|
||||
m = 'INVALID'.match(regex);
|
||||
@@ -295,8 +365,16 @@ suite('Utils', function() {
|
||||
chai.assert.equal(m[3], '16', 'transform: translate(15px 16px), y');
|
||||
|
||||
m = 'transform: translate(1.23456e+42px 0.123456e-42px)'.match(regex);
|
||||
chai.assert.equal(m[1], '1.23456e+42', 'transform: translate(1.23456e+42px 0.123456e-42px), x');
|
||||
chai.assert.equal(m[3], '0.123456e-42', 'transform: translate(1.23456e+42px 0.123456e-42px), y');
|
||||
chai.assert.equal(
|
||||
m[1],
|
||||
'1.23456e+42',
|
||||
'transform: translate(1.23456e+42px 0.123456e-42px), x'
|
||||
);
|
||||
chai.assert.equal(
|
||||
m[3],
|
||||
'0.123456e-42',
|
||||
'transform: translate(1.23456e+42px 0.123456e-42px), y'
|
||||
);
|
||||
|
||||
m = 'transform:translate3d(20px, 21px, 22px)'.match(regex);
|
||||
chai.assert.equal(m[1], '20', 'transform:translate3d(20px, 21px, 22px), x');
|
||||
@@ -311,12 +389,20 @@ suite('Utils', function() {
|
||||
chai.assert.equal(m[3], '27', 'transform:translate3d(26px 27px 28px), y');
|
||||
|
||||
m = 'transform:translate3d(1.23456e+42px 0.123456e-42px 42px)'.match(regex);
|
||||
chai.assert.equal(m[1], '1.23456e+42', 'transform:translate3d(1.23456e+42px 0.123456e-42px 42px), x');
|
||||
chai.assert.equal(m[3], '0.123456e-42', 'transform:translate3d(1.23456e+42px 0.123456e-42px 42px), y');
|
||||
chai.assert.equal(
|
||||
m[1],
|
||||
'1.23456e+42',
|
||||
'transform:translate3d(1.23456e+42px 0.123456e-42px 42px), x'
|
||||
);
|
||||
chai.assert.equal(
|
||||
m[3],
|
||||
'0.123456e-42',
|
||||
'transform:translate3d(1.23456e+42px 0.123456e-42px 42px), y'
|
||||
);
|
||||
});
|
||||
|
||||
suite('DOM', function() {
|
||||
test('addClass', function() {
|
||||
suite('DOM', function () {
|
||||
test('addClass', function () {
|
||||
const p = document.createElement('p');
|
||||
Blockly.utils.dom.addClass(p, 'one');
|
||||
chai.assert.equal(p.className, 'one', 'Adding "one"');
|
||||
@@ -330,17 +416,20 @@ suite('Utils', function() {
|
||||
chai.assert.equal(p.className, 'one two three', 'Adding "three"');
|
||||
});
|
||||
|
||||
test('hasClass', function() {
|
||||
test('hasClass', function () {
|
||||
const p = document.createElement('p');
|
||||
p.className = ' one three two three ';
|
||||
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'one'), 'Has "one"');
|
||||
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'two'), 'Has "two"');
|
||||
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'three'), 'Has "three"');
|
||||
chai.assert.isFalse(Blockly.utils.dom.hasClass(p, 'four'), 'Has no "four"');
|
||||
chai.assert.isFalse(
|
||||
Blockly.utils.dom.hasClass(p, 'four'),
|
||||
'Has no "four"'
|
||||
);
|
||||
chai.assert.isFalse(Blockly.utils.dom.hasClass(p, 't'), 'Has no "t"');
|
||||
});
|
||||
|
||||
test('removeClass', function() {
|
||||
test('removeClass', function () {
|
||||
const p = document.createElement('p');
|
||||
p.className = ' one three two three ';
|
||||
Blockly.utils.dom.removeClass(p, 'two');
|
||||
@@ -358,11 +447,15 @@ suite('Utils', function() {
|
||||
});
|
||||
});
|
||||
|
||||
suite('String', function() {
|
||||
test('shortest string length', function() {
|
||||
let len = Blockly.utils.string.shortestStringLength('one,two,three,four,five'.split(','));
|
||||
suite('String', function () {
|
||||
test('shortest string length', function () {
|
||||
let len = Blockly.utils.string.shortestStringLength(
|
||||
'one,two,three,four,five'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 3, 'Length of "one"');
|
||||
len = Blockly.utils.string.shortestStringLength('one,two,three,four,five,'.split(','));
|
||||
len = Blockly.utils.string.shortestStringLength(
|
||||
'one,two,three,four,five,'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'Length of ""');
|
||||
len = Blockly.utils.string.shortestStringLength(['Hello World']);
|
||||
chai.assert.equal(len, 11, 'List of one');
|
||||
@@ -370,12 +463,18 @@ suite('Utils', function() {
|
||||
chai.assert.equal(len, 0, 'Empty list');
|
||||
});
|
||||
|
||||
test('comment word prefix', function() {
|
||||
let len = Blockly.utils.string.commonWordPrefix('one,two,three,four,five'.split(','));
|
||||
test('comment word prefix', function () {
|
||||
let len = Blockly.utils.string.commonWordPrefix(
|
||||
'one,two,three,four,five'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'No prefix');
|
||||
len = Blockly.utils.string.commonWordPrefix('Xone,Xtwo,Xthree,Xfour,Xfive'.split(','));
|
||||
len = Blockly.utils.string.commonWordPrefix(
|
||||
'Xone,Xtwo,Xthree,Xfour,Xfive'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'No word prefix');
|
||||
len = Blockly.utils.string.commonWordPrefix('abc de,abc de,abc de,abc de'.split(','));
|
||||
len = Blockly.utils.string.commonWordPrefix(
|
||||
'abc de,abc de,abc de,abc de'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 6, 'Full equality');
|
||||
len = Blockly.utils.string.commonWordPrefix('abc deX,abc deY'.split(','));
|
||||
chai.assert.equal(len, 4, 'One word prefix');
|
||||
@@ -387,18 +486,28 @@ suite('Utils', function() {
|
||||
chai.assert.equal(len, 11, 'List of one');
|
||||
len = Blockly.utils.string.commonWordPrefix([]);
|
||||
chai.assert.equal(len, 0, 'Empty list');
|
||||
len = Blockly.utils.string.commonWordPrefix('turn left,turn right'.split(','));
|
||||
len = Blockly.utils.string.commonWordPrefix(
|
||||
'turn left,turn right'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'No prefix due to &nbsp;');
|
||||
len = Blockly.utils.string.commonWordPrefix('turn\u00A0left,turn\u00A0right'.split(','));
|
||||
len = Blockly.utils.string.commonWordPrefix(
|
||||
'turn\u00A0left,turn\u00A0right'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'No prefix due to \\u00A0');
|
||||
});
|
||||
|
||||
test('comment word suffix', function() {
|
||||
let len = Blockly.utils.string.commonWordSuffix('one,two,three,four,five'.split(','));
|
||||
test('comment word suffix', function () {
|
||||
let len = Blockly.utils.string.commonWordSuffix(
|
||||
'one,two,three,four,five'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'No suffix');
|
||||
len = Blockly.utils.string.commonWordSuffix('oneX,twoX,threeX,fourX,fiveX'.split(','));
|
||||
len = Blockly.utils.string.commonWordSuffix(
|
||||
'oneX,twoX,threeX,fourX,fiveX'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 0, 'No word suffix');
|
||||
len = Blockly.utils.string.commonWordSuffix('abc de,abc de,abc de,abc de'.split(','));
|
||||
len = Blockly.utils.string.commonWordSuffix(
|
||||
'abc de,abc de,abc de,abc de'.split(',')
|
||||
);
|
||||
chai.assert.equal(len, 6, 'Full equality');
|
||||
len = Blockly.utils.string.commonWordSuffix('Xabc de,Yabc de'.split(','));
|
||||
chai.assert.equal(len, 3, 'One word suffix');
|
||||
@@ -413,8 +522,8 @@ suite('Utils', function() {
|
||||
});
|
||||
});
|
||||
|
||||
suite('Math', function() {
|
||||
test('toRadians', function() {
|
||||
suite('Math', function () {
|
||||
test('toRadians', function () {
|
||||
const quarter = Math.PI / 2;
|
||||
chai.assert.equal(Blockly.utils.math.toRadians(-90), -quarter, '-90');
|
||||
chai.assert.equal(Blockly.utils.math.toRadians(0), 0, '0');
|
||||
@@ -422,10 +531,14 @@ suite('Utils', function() {
|
||||
chai.assert.equal(Blockly.utils.math.toRadians(180), 2 * quarter, '180');
|
||||
chai.assert.equal(Blockly.utils.math.toRadians(270), 3 * quarter, '270');
|
||||
chai.assert.equal(Blockly.utils.math.toRadians(360), 4 * quarter, '360');
|
||||
chai.assert.equal(Blockly.utils.math.toRadians(360 + 90), 5 * quarter, '450');
|
||||
chai.assert.equal(
|
||||
Blockly.utils.math.toRadians(360 + 90),
|
||||
5 * quarter,
|
||||
'450'
|
||||
);
|
||||
});
|
||||
|
||||
test('toDegrees', function() {
|
||||
test('toDegrees', function () {
|
||||
const quarter = Math.PI / 2;
|
||||
chai.assert.equal(Blockly.utils.math.toDegrees(-quarter), -90, '-90');
|
||||
chai.assert.equal(Blockly.utils.math.toDegrees(0), 0, '0');
|
||||
@@ -433,7 +546,11 @@ suite('Utils', function() {
|
||||
chai.assert.equal(Blockly.utils.math.toDegrees(2 * quarter), 180, '180');
|
||||
chai.assert.equal(Blockly.utils.math.toDegrees(3 * quarter), 270, '270');
|
||||
chai.assert.equal(Blockly.utils.math.toDegrees(4 * quarter), 360, '360');
|
||||
chai.assert.equal(Blockly.utils.math.toDegrees(5 * quarter), 360 + 90, '450');
|
||||
chai.assert.equal(
|
||||
Blockly.utils.math.toDegrees(5 * quarter),
|
||||
360 + 90,
|
||||
'450'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user