Convert names_test from jsunit to mocha. (#2873)

This commit is contained in:
Sam El-Husseini
2019-08-20 13:17:40 -07:00
committed by GitHub
parent 419451932a
commit 3d9b8267b5
2 changed files with 72 additions and 0 deletions

View File

@@ -45,6 +45,7 @@
<script src="field_variable_test.js"></script>
<script src="gesture_test.js"></script>
<script src="key_map_test.js"></script>
<script src="names_test.js"></script>
<script src="navigation_modify_test.js"></script>
<script src="navigation_test.js"></script>
<script src="procedures_test.js"></script>

71
tests/mocha/names_test.js Normal file
View File

@@ -0,0 +1,71 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2019 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Blockly names tests.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
suite('Names', function() {
test('Safe name', function() {
var varDB = new Blockly.Names('window,door');
assertEquals('SafeName empty.', 'unnamed', varDB.safeName_(''));
assertEquals('SafeName ok.', 'foobar', varDB.safeName_('foobar'));
assertEquals('SafeName number start.', 'my_9lives',
varDB.safeName_('9lives'));
assertEquals('SafeName number end.', 'lives9', varDB.safeName_('lives9'));
assertEquals('SafeName special chars.', '____', varDB.safeName_('!@#$'));
assertEquals('SafeName reserved.', 'door', varDB.safeName_('door'));
});
test('Get name', function() {
var varDB = new Blockly.Names('window,door');
assertEquals('Name add #1.', 'Foo_bar', varDB.getName('Foo.bar', 'var'));
assertEquals('Name get #1.', 'Foo_bar', varDB.getName('Foo.bar', 'var'));
assertEquals('Name add #2.', 'Foo_bar2', varDB.getName('Foo bar', 'var'));
assertEquals('Name get #2.', 'Foo_bar2', varDB.getName('foo BAR', 'var'));
assertEquals('Name add #3.', 'door2', varDB.getName('door', 'var'));
assertEquals('Name add #4.', 'Foo_bar3', varDB.getName('Foo.bar', 'proc'));
assertEquals('Name get #1b.', 'Foo_bar', varDB.getName('Foo.bar', 'var'));
assertEquals('Name get #4.', 'Foo_bar3', varDB.getName('Foo.bar', 'proc'));
});
test('Get distinct name', function() {
var varDB = new Blockly.Names('window,door');
assertEquals('Name distinct #1.', 'Foo_bar',
varDB.getDistinctName('Foo.bar', 'var'));
assertEquals('Name distinct #2.', 'Foo_bar2',
varDB.getDistinctName('Foo.bar', 'var'));
assertEquals('Name distinct #3.', 'Foo_bar3',
varDB.getDistinctName('Foo.bar', 'proc'));
varDB.reset();
assertEquals('Name distinct #4.', 'Foo_bar',
varDB.getDistinctName('Foo.bar', 'var'));
});
test('name equals', function() {
assertTrue('Name equals #1.', Blockly.Names.equals('Foo.bar', 'Foo.bar'));
assertFalse('Name equals #2.', Blockly.Names.equals('Foo.bar', 'Foo_bar'));
assertTrue('Name equals #3.', Blockly.Names.equals('Foo.bar', 'FOO.BAR'));
});
});