mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
* chore: fix 918 violations of comma-dangle rule * chore: fix 2 violations of comma-spacing * chore: fix 13 violations of padded-blocks * chore: fix 50 violations of block-spacing * chore: fix one violation of semi-spacing * chore: fix 4 violations of space-before-blocks * chore: fix 38 violations of object-curly-spacing * chore: fix 30 violations of key-spacing * chore: fix 3 violations of quote-props * chore: fix 5 violations of arrow-parens * chore: fix 8 violations of no-tabs * chore: allow uncommented helper functions in mocha tests * chore: fix several more lint errors * chore: tweak eslint configuration in core and tests * chore: rebuild for tests
64 lines
2.7 KiB
JavaScript
64 lines
2.7 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.module('Blockly.test.names');
|
|
|
|
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
|
|
|
|
|
|
suite('Names', function() {
|
|
setup(function() {
|
|
sharedTestSetup.call(this);
|
|
});
|
|
teardown(function() {
|
|
sharedTestTeardown.call(this);
|
|
});
|
|
|
|
test('Safe name', function() {
|
|
const varDB = new Blockly.Names('window,door');
|
|
chai.assert.equal(varDB.safeName_(''), 'unnamed', 'SafeName empty.');
|
|
chai.assert.equal(varDB.safeName_('foobar'), 'foobar', 'SafeName ok.');
|
|
chai.assert.equal(varDB.safeName_('9lives'), 'my_9lives', 'SafeName number start.');
|
|
chai.assert.equal(varDB.safeName_('lives9'), 'lives9', 'SafeName number end.');
|
|
chai.assert.equal(varDB.safeName_('!@#$'), '____', 'SafeName special chars.');
|
|
chai.assert.equal(varDB.safeName_('door'), 'door', 'SafeName reserved.');
|
|
});
|
|
|
|
test('Get name', function() {
|
|
const varDB = new Blockly.Names('window,door');
|
|
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name add #1.');
|
|
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name get #1.');
|
|
chai.assert.equal(varDB.getName('Foo bar', 'var'), 'Foo_bar2', 'Name add #2.');
|
|
chai.assert.equal(varDB.getName('foo BAR', 'var'), 'Foo_bar2', 'Name get #2.');
|
|
chai.assert.equal(varDB.getName('door', 'var'), 'door2', 'Name add #3.');
|
|
chai.assert.equal(varDB.getName('Foo.bar', 'proc'), 'Foo_bar3', 'Name add #4.');
|
|
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name get #1b.');
|
|
chai.assert.equal(varDB.getName('Foo.bar', 'proc'), 'Foo_bar3', 'Name get #4.');
|
|
|
|
chai.assert.equal(String(varDB.getUserNames('var')), 'foo.bar,foo bar,door', 'Get var names.');
|
|
chai.assert.equal(String(varDB.getUserNames('proc')), 'foo.bar', 'Get proc names.');
|
|
});
|
|
|
|
test('Get distinct name', function() {
|
|
const varDB = new Blockly.Names('window,door');
|
|
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar',
|
|
'Name distinct #1.');
|
|
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar2',
|
|
'Name distinct #2.');
|
|
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'proc'), 'Foo_bar3',
|
|
'Name distinct #3.');
|
|
varDB.reset();
|
|
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar',
|
|
'Name distinct #4.');
|
|
});
|
|
|
|
test('name equals', function() {
|
|
chai.assert.isTrue(Blockly.Names.equals('Foo.bar', 'Foo.bar'), 'Name equals #1.');
|
|
chai.assert.isFalse(Blockly.Names.equals('Foo.bar', 'Foo_bar'), 'Name equals #2.');
|
|
chai.assert.isTrue(Blockly.Names.equals('Foo.bar', 'FOO.BAR'), 'Name equals #3.');
|
|
});
|
|
});
|