Create block id database.

This commit is contained in:
Neil Fraser
2015-12-09 10:02:42 +01:00
parent b2bbde04a1
commit 3b3ef79fbd
9 changed files with 84 additions and 70 deletions

View File

@@ -0,0 +1,35 @@
/**
* @license
* Blockly Tests
*
* Copyright 2015 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.
*/
'use strict';
function test_getById() {
var workspace = new Blockly.Workspace();
var blockA = workspace.newBlock('');
var blockB = workspace.newBlock('');
assertEquals('Find blockA.', blockA, Blockly.Block.getById(blockA.id));
assertEquals('Find blockB.', blockB, Blockly.Block.getById(blockB.id));
assertEquals('No block found.', null,
Blockly.Block.getById('I do not exist.'));
blockA.dispose();
assertEquals('Can\'t find blockA.', null, Blockly.Block.getById(blockA.id));
assertEquals('BlockB exists.', blockB, Blockly.Block.getById(blockB.id));
workspace.clear();
assertEquals('Can\'t find blockB.', null, Blockly.Block.getById(blockB.id));
}

View File

@@ -8,6 +8,7 @@
</head>
<body>
<script src="blockly_test.js"></script>
<script src="block_test.js"></script>
<script src="connection_test.js"></script>
<script src="generator_test.js"></script>
<script src="names_test.js"></script>

View File

@@ -66,17 +66,3 @@ function test_maxBlocksWorkspace() {
workspace.clear();
assertEquals('Cleared capacity.', 0, workspace.remainingCapacity());
}
function test_getByIdWorkspace() {
var workspace = new Blockly.Workspace();
var blockA = workspace.newBlock('');
var blockB = workspace.newBlock('');
assertEquals('Find blockA.', blockA, workspace.getBlockById(blockA.id));
assertEquals('Find blockB.', blockB, workspace.getBlockById(blockB.id));
assertEquals('No block found.', null, workspace.getBlockById('I do not exist.'));
blockA.dispose();
assertEquals('Can\'t find blockA.', null, workspace.getBlockById(blockA.id));
assertEquals('BlockB exists.', blockB, workspace.getBlockById(blockB.id));
workspace.clear();
assertEquals('Can\'t find blockB.', null, workspace.getBlockById(blockB.id));
}