Merge pull request #1055 from marisaleung/develop

Create a variable model with name, id, and type.
This commit is contained in:
marisaleung
2017-04-20 13:31:22 -07:00
committed by GitHub
3 changed files with 154 additions and 0 deletions

View File

@@ -20,5 +20,6 @@
<script src="workspace_test.js"></script>
<script src="xml_test.js"></script>
<script src="json_test.js"></script>
<script src="variable_model_test.js"></script>
</body>
</html>

View File

@@ -0,0 +1,78 @@
/**
* @license
* Blockly Tests
*
* Copyright 2017 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 Tests for variable model.
* @author marisaleung@google.com (Marisa Leung)
*/
'use strict';
var variable;
function variableTest_tearDown() {
variable = null;
}
/**
* These tests check the constructor of the variable model.
*/
function testInit_Trivial() {
variable = new Blockly.VariableModel('test', 'test_type', 'test_id');
assertEquals('test', variable.name);
assertEquals('test_type', variable.type);
assertEquals('test_id', variable.id_);
variableTest_tearDown();
}
function testInit_NullType() {
variable = new Blockly.VariableModel('test', null, 'test_id');
assertEquals('', variable.type);
variableTest_tearDown();
}
function testInit_UndefinedType() {
variable = new Blockly.VariableModel('test', undefined, 'test_id');
assertEquals('', variable.type);
variableTest_tearDown();
}
function testInit_NullId() {
variable = new Blockly.VariableModel('test', 'test_type', null);
assertEquals('test', variable.name);
assertEquals('test_type', variable.type);
assertNotNull(variable.id_);
variableTest_tearDown();
}
function testInit_UndefinedId() {
variable = new Blockly.VariableModel('test', 'test_type', undefined);
assertEquals('test', variable.name);
assertEquals('test_type', variable.type);
assertNotNull(variable.id_);
variableTest_tearDown();
}
function testInit_OnlyNameProvided() {
variable = new Blockly.VariableModel('test');
assertEquals('test', variable.name);
assertEquals('', variable.type);
assertNotNull(variable.id_);
variableTest_tearDown();
}