|
|
|
|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
|
|
|
|
goog.module('Blockly.test.astNode');
|
|
|
|
|
|
|
|
|
|
const ASTNode = goog.require('Blockly.ASTNode');
|
|
|
|
|
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -103,7 +104,7 @@ suite('ASTNode', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var input2 = this.blocks.statementInput1.inputList[1];
|
|
|
|
|
var connection = input.connection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(connection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(connection);
|
|
|
|
|
var newASTNode = node.findNextForInput_(input);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), input2.connection);
|
|
|
|
|
});
|
|
|
|
|
@@ -112,7 +113,7 @@ suite('ASTNode', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var input2 = this.blocks.statementInput1.inputList[1];
|
|
|
|
|
var connection = input2.connection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(connection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(connection);
|
|
|
|
|
var newASTNode = node.findPrevForInput_(input2);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), input.connection);
|
|
|
|
|
});
|
|
|
|
|
@@ -120,7 +121,7 @@ suite('ASTNode', function() {
|
|
|
|
|
test('findNextForField_', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
var field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var newASTNode = node.findNextForField_(field);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), field2);
|
|
|
|
|
});
|
|
|
|
|
@@ -128,39 +129,39 @@ suite('ASTNode', function() {
|
|
|
|
|
test('findPrevForField_', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
var field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field2);
|
|
|
|
|
var node = ASTNode.createFieldNode(field2);
|
|
|
|
|
var newASTNode = node.findPrevForField_(field2);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), field);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('navigateBetweenStacks_Forward', function() {
|
|
|
|
|
var node = new Blockly.ASTNode(
|
|
|
|
|
Blockly.ASTNode.types.NEXT, this.blocks.statementInput1.nextConnection);
|
|
|
|
|
var node = new ASTNode(
|
|
|
|
|
ASTNode.types.NEXT, this.blocks.statementInput1.nextConnection);
|
|
|
|
|
var newASTNode = node.navigateBetweenStacks_(true);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('navigateBetweenStacks_Backward', function() {
|
|
|
|
|
var node = new Blockly.ASTNode(
|
|
|
|
|
Blockly.ASTNode.types.BLOCK, this.blocks.statementInput4);
|
|
|
|
|
var node = new ASTNode(
|
|
|
|
|
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
|
|
|
|
var newASTNode = node.navigateBetweenStacks_(false);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('getOutAstNodeForBlock_', function() {
|
|
|
|
|
var node = new Blockly.ASTNode(
|
|
|
|
|
Blockly.ASTNode.types.BLOCK, this.blocks.statementInput2);
|
|
|
|
|
var node = new ASTNode(
|
|
|
|
|
ASTNode.types.BLOCK, this.blocks.statementInput2);
|
|
|
|
|
var newASTNode = node.getOutAstNodeForBlock_(this.blocks.statementInput2);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('getOutAstNodeForBlock_OneBlock', function() {
|
|
|
|
|
var node = new Blockly.ASTNode(
|
|
|
|
|
Blockly.ASTNode.types.BLOCK, this.blocks.statementInput4);
|
|
|
|
|
var node = new ASTNode(
|
|
|
|
|
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
|
|
|
|
var newASTNode = node.getOutAstNodeForBlock_(this.blocks.statementInput4);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
|
|
|
|
});
|
|
|
|
|
test('findFirstFieldOrInput_', function() {
|
|
|
|
|
var node = new Blockly.ASTNode(
|
|
|
|
|
Blockly.ASTNode.types.BLOCK, this.blocks.statementInput4);
|
|
|
|
|
var node = new ASTNode(
|
|
|
|
|
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
|
|
|
|
var field = this.blocks.statementInput4.inputList[0].fieldRow[0];
|
|
|
|
|
var newASTNode = node.findFirstFieldOrInput_(this.blocks.statementInput4);
|
|
|
|
|
chai.assert.equal(newASTNode.getLocation(), field);
|
|
|
|
|
@@ -321,95 +322,95 @@ suite('ASTNode', function() {
|
|
|
|
|
|
|
|
|
|
test('fromPreviousToBlock', function() {
|
|
|
|
|
var prevConnection = this.blocks.statementInput1.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToNext', function() {
|
|
|
|
|
var nextConnection = this.blocks.statementInput1.nextConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), nextConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToNull', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.noNextConnection);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.noNextConnection);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.isNull(nextNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromNextToPrevious', function() {
|
|
|
|
|
var nextConnection = this.blocks.statementInput1.nextConnection;
|
|
|
|
|
var prevConnection = this.blocks.statementInput2.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), prevConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromNextToNull', function() {
|
|
|
|
|
var nextConnection = this.blocks.statementInput2.nextConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.isNull(nextNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToInput', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var inputConnection = this.blocks.statementInput1.inputList[1].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToStatementInput', function() {
|
|
|
|
|
var input = this.blocks.fieldAndInputs2.inputList[1];
|
|
|
|
|
var inputConnection = this.blocks.fieldAndInputs2.inputList[2].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToField', function() {
|
|
|
|
|
var input = this.blocks.fieldAndInputs2.inputList[0];
|
|
|
|
|
var field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), field);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToNull', function() {
|
|
|
|
|
var input = this.blocks.fieldAndInputs2.inputList[2];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.isNull(nextNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromOutputToBlock', function() {
|
|
|
|
|
var output = this.blocks.fieldWithOutput.outputConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(output);
|
|
|
|
|
var node = ASTNode.createConnectionNode(output);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), this.blocks.fieldWithOutput);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToInput', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
|
|
|
|
var inputConnection = this.blocks.statementInput1.inputList[0].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToField', function() {
|
|
|
|
|
var field = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var field2 = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), field2);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToNull', function() {
|
|
|
|
|
var field = this.blocks.twoFields.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.isNull(nextNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToStack', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.statementInput1);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.statementInput1);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput4);
|
|
|
|
|
chai.assert.equal(nextNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(nextNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToNull', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.singleBlock);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.singleBlock);
|
|
|
|
|
var nextNode = node.next();
|
|
|
|
|
chai.assert.isNull(nextNode);
|
|
|
|
|
});
|
|
|
|
|
@@ -418,96 +419,96 @@ suite('ASTNode', function() {
|
|
|
|
|
suite('Previous', function() {
|
|
|
|
|
test('fromPreviousToNull', function() {
|
|
|
|
|
var prevConnection = this.blocks.statementInput1.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.isNull(prevNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromPreviousToNext', function() {
|
|
|
|
|
var prevConnection = this.blocks.statementInput2.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
var nextConnection = this.blocks.statementInput1.nextConnection;
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), nextConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromPreviousToInput', function() {
|
|
|
|
|
var prevConnection = this.blocks.statementInput3.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.isNull(prevNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToPrevious', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
var prevConnection = this.blocks.statementInput1.previousConnection;
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), prevConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToNull', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.noPrevConnection);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.noPrevConnection);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.isNull(prevNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToOutput', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.fieldWithOutput);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.fieldWithOutput);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
var outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), outputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromNextToBlock', function() {
|
|
|
|
|
var nextConnection = this.blocks.statementInput1.nextConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToField', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), input.fieldRow[1]);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToNull', function() {
|
|
|
|
|
var input = this.blocks.fieldAndInputs2.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.isNull(prevNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToInput', function() {
|
|
|
|
|
var input = this.blocks.fieldAndInputs2.inputList[2];
|
|
|
|
|
var inputConnection = this.blocks.fieldAndInputs2.inputList[1].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromOutputToNull', function() {
|
|
|
|
|
var output = this.blocks.fieldWithOutput.outputConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(output);
|
|
|
|
|
var node = ASTNode.createConnectionNode(output);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.isNull(prevNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToNull', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.isNull(prevNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToInput', function() {
|
|
|
|
|
var field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
|
|
|
|
var inputConnection = this.blocks.fieldAndInputs2.inputList[0].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToField', function() {
|
|
|
|
|
var field = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
|
|
|
|
var field2 = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), field2);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToStack', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.statementInput4);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.statementInput4);
|
|
|
|
|
var prevNode = node.prev();
|
|
|
|
|
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
chai.assert.equal(prevNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(prevNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -521,99 +522,99 @@ suite('ASTNode', function() {
|
|
|
|
|
|
|
|
|
|
test('fromInputToOutput', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
var outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), outputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToNull', function() {
|
|
|
|
|
var input = this.blocks.statementInput2.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.isNull(inNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromInputToPrevious', function() {
|
|
|
|
|
var input = this.blocks.statementInput2.inputList[1];
|
|
|
|
|
var previousConnection = this.blocks.statementInput3.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), previousConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToInput', function() {
|
|
|
|
|
var input = this.blocks.valueInput.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.valueInput);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.valueInput);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), input.connection);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToField', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), field);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToPrevious', function() {
|
|
|
|
|
var prevConnection = this.blocks.statementInput4.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.statementInput4);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.statementInput4);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), prevConnection);
|
|
|
|
|
chai.assert.equal(inNode.getType(), Blockly.ASTNode.types.PREVIOUS);
|
|
|
|
|
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToNull_DummyInput', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.dummyInput);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.dummyInput);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.isNull(inNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToInput_DummyInputValue', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.dummyInputValue);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.dummyInputValue);
|
|
|
|
|
var inputConnection = this.blocks.dummyInputValue.inputList[1].connection;
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromOuputToNull', function() {
|
|
|
|
|
var output = this.blocks.fieldWithOutput.outputConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(output);
|
|
|
|
|
var node = ASTNode.createConnectionNode(output);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.isNull(inNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToNull', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.isNull(inNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromWorkspaceToStack', function() {
|
|
|
|
|
var coordinate = new Blockly.utils.Coordinate(100, 100);
|
|
|
|
|
var node = Blockly.ASTNode.createWorkspaceNode(this.workspace, coordinate);
|
|
|
|
|
var node = ASTNode.createWorkspaceNode(this.workspace, coordinate);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), this.workspace.getTopBlocks()[0]);
|
|
|
|
|
chai.assert.equal(inNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(inNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
});
|
|
|
|
|
test('fromWorkspaceToNull', function() {
|
|
|
|
|
var coordinate = new Blockly.utils.Coordinate(100, 100);
|
|
|
|
|
var node = Blockly.ASTNode.createWorkspaceNode(
|
|
|
|
|
var node = ASTNode.createWorkspaceNode(
|
|
|
|
|
this.emptyWorkspace, coordinate);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.isNull(inNode);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToPrevious', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.statementInput1);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.statementInput1);
|
|
|
|
|
var previous = this.blocks.statementInput1.previousConnection;
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), previous);
|
|
|
|
|
chai.assert.equal(inNode.getType(), Blockly.ASTNode.types.PREVIOUS);
|
|
|
|
|
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToOutput', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.fieldWithOutput2);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.fieldWithOutput2);
|
|
|
|
|
var output = this.blocks.fieldWithOutput2.outputConnection;
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), output);
|
|
|
|
|
chai.assert.equal(inNode.getType(), Blockly.ASTNode.types.OUTPUT);
|
|
|
|
|
chai.assert.equal(inNode.getType(), ASTNode.types.OUTPUT);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToBlock', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.dummyInput);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.dummyInput);
|
|
|
|
|
var inNode = node.in();
|
|
|
|
|
chai.assert.equal(inNode.getLocation(), this.blocks.dummyInput);
|
|
|
|
|
chai.assert.equal(inNode.getType(), Blockly.ASTNode.types.BLOCK);
|
|
|
|
|
chai.assert.equal(inNode.getType(), ASTNode.types.BLOCK);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -628,39 +629,39 @@ suite('ASTNode', function() {
|
|
|
|
|
|
|
|
|
|
test('fromInputToBlock', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.BLOCK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromOutputToInput', function() {
|
|
|
|
|
var output = this.blocks.fieldWithOutput.outputConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(output);
|
|
|
|
|
var node = ASTNode.createConnectionNode(output);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(),
|
|
|
|
|
this.blocks.statementInput1.inputList[0].connection);
|
|
|
|
|
});
|
|
|
|
|
test('fromOutputToStack', function() {
|
|
|
|
|
var output = this.blocks.fieldWithOutput2.outputConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(output);
|
|
|
|
|
var node = ASTNode.createConnectionNode(output);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
|
|
|
|
});
|
|
|
|
|
test('fromFieldToBlock', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.BLOCK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromStackToWorkspace', function() {
|
|
|
|
|
var stub = sinon.stub(this.blocks.statementInput4,
|
|
|
|
|
"getRelativeToSurfaceXY").returns({x: 10, y:10});
|
|
|
|
|
var node = Blockly.ASTNode.createStackNode(this.blocks.statementInput4);
|
|
|
|
|
var node = ASTNode.createStackNode(this.blocks.statementInput4);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.WORKSPACE);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.WORKSPACE);
|
|
|
|
|
chai.assert.equal(outNode.wsCoordinate_.x, 10);
|
|
|
|
|
chai.assert.equal(outNode.wsCoordinate_.y, -10);
|
|
|
|
|
stub.restore();
|
|
|
|
|
@@ -668,38 +669,38 @@ suite('ASTNode', function() {
|
|
|
|
|
test('fromPreviousToInput', function() {
|
|
|
|
|
var previous = this.blocks.statementInput3.previousConnection;
|
|
|
|
|
var inputConnection = this.blocks.statementInput2.inputList[1].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(previous);
|
|
|
|
|
var node = ASTNode.createConnectionNode(previous);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromPreviousToStack', function() {
|
|
|
|
|
var previous = this.blocks.statementInput2.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(previous);
|
|
|
|
|
var node = ASTNode.createConnectionNode(previous);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromNextToInput', function() {
|
|
|
|
|
var next = this.blocks.statementInput3.nextConnection;
|
|
|
|
|
var inputConnection = this.blocks.statementInput2.inputList[1].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(next);
|
|
|
|
|
var node = ASTNode.createConnectionNode(next);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
test('fromNextToStack', function() {
|
|
|
|
|
var next = this.blocks.statementInput2.nextConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(next);
|
|
|
|
|
var node = ASTNode.createConnectionNode(next);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromNextToStack_NoPreviousConnection', function() {
|
|
|
|
|
var next = this.blocks.secondBlock.nextConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(next);
|
|
|
|
|
var node = ASTNode.createConnectionNode(next);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.noPrevConnection);
|
|
|
|
|
});
|
|
|
|
|
/**
|
|
|
|
|
@@ -708,42 +709,42 @@ suite('ASTNode', function() {
|
|
|
|
|
*/
|
|
|
|
|
test('fromNextToInput_OutputAndPreviousConnection', function() {
|
|
|
|
|
var next = this.blocks.outputNextBlock.nextConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(next);
|
|
|
|
|
var node = ASTNode.createConnectionNode(next);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(),
|
|
|
|
|
this.blocks.secondBlock.inputList[0].connection);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToStack', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.statementInput2);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.statementInput2);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToInput', function() {
|
|
|
|
|
var input = this.blocks.statementInput2.inputList[1].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.statementInput3);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.statementInput3);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), input);
|
|
|
|
|
});
|
|
|
|
|
test('fromTopBlockToStack', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToStack_OutputConnection', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.fieldWithOutput2);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.fieldWithOutput2);
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
|
|
|
|
});
|
|
|
|
|
test('fromBlockToInput_OutputConnection', function() {
|
|
|
|
|
var node = Blockly.ASTNode.createBlockNode(this.blocks.outputNextBlock);
|
|
|
|
|
var node = ASTNode.createBlockNode(this.blocks.outputNextBlock);
|
|
|
|
|
var inputConnection = this.blocks.secondBlock.inputList[0].connection;
|
|
|
|
|
var outNode = node.out();
|
|
|
|
|
chai.assert.equal(outNode.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(outNode.getLocation(), inputConnection);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
@@ -751,55 +752,55 @@ suite('ASTNode', function() {
|
|
|
|
|
suite('createFunctions', function() {
|
|
|
|
|
test('createFieldNode', function() {
|
|
|
|
|
var field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
|
|
|
|
var node = Blockly.ASTNode.createFieldNode(field);
|
|
|
|
|
var node = ASTNode.createFieldNode(field);
|
|
|
|
|
chai.assert.equal(node.getLocation(), field);
|
|
|
|
|
chai.assert.equal(node.getType(), Blockly.ASTNode.types.FIELD);
|
|
|
|
|
chai.assert.equal(node.getType(), ASTNode.types.FIELD);
|
|
|
|
|
chai.assert.isFalse(node.isConnection());
|
|
|
|
|
});
|
|
|
|
|
test('createConnectionNode', function() {
|
|
|
|
|
var prevConnection = this.blocks.statementInput4.previousConnection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(prevConnection);
|
|
|
|
|
chai.assert.equal(node.getLocation(), prevConnection);
|
|
|
|
|
chai.assert.equal(node.getType(), Blockly.ASTNode.types.PREVIOUS);
|
|
|
|
|
chai.assert.equal(node.getType(), ASTNode.types.PREVIOUS);
|
|
|
|
|
chai.assert.isTrue(node.isConnection());
|
|
|
|
|
});
|
|
|
|
|
test('createInputNode', function() {
|
|
|
|
|
var input = this.blocks.statementInput1.inputList[0];
|
|
|
|
|
var node = Blockly.ASTNode.createInputNode(input);
|
|
|
|
|
var node = ASTNode.createInputNode(input);
|
|
|
|
|
chai.assert.equal(node.getLocation(), input.connection);
|
|
|
|
|
chai.assert.equal(node.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.isTrue(node.isConnection());
|
|
|
|
|
});
|
|
|
|
|
test('createWorkspaceNode', function() {
|
|
|
|
|
var coordinate = new Blockly.utils.Coordinate(100, 100);
|
|
|
|
|
var node = Blockly.ASTNode
|
|
|
|
|
var node = ASTNode
|
|
|
|
|
.createWorkspaceNode(this.workspace, coordinate);
|
|
|
|
|
chai.assert.equal(node.getLocation(), this.workspace);
|
|
|
|
|
chai.assert.equal(node.getType(), Blockly.ASTNode.types.WORKSPACE);
|
|
|
|
|
chai.assert.equal(node.getType(), ASTNode.types.WORKSPACE);
|
|
|
|
|
chai.assert.equal(node.getWsCoordinate(), coordinate);
|
|
|
|
|
chai.assert.isFalse(node.isConnection());
|
|
|
|
|
});
|
|
|
|
|
test('createStatementConnectionNode', function() {
|
|
|
|
|
var nextConnection = this.blocks.statementInput1.inputList[1].connection;
|
|
|
|
|
var inputConnection = this.blocks.statementInput1.inputList[1].connection;
|
|
|
|
|
var node = Blockly.ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
var node = ASTNode.createConnectionNode(nextConnection);
|
|
|
|
|
chai.assert.equal(node.getLocation(), inputConnection);
|
|
|
|
|
chai.assert.equal(node.getType(), Blockly.ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
|
|
|
|
chai.assert.isTrue(node.isConnection());
|
|
|
|
|
});
|
|
|
|
|
test('createTopNode-previous', function() {
|
|
|
|
|
var block = this.blocks.statementInput1;
|
|
|
|
|
var topNode = Blockly.ASTNode.createTopNode(block);
|
|
|
|
|
var topNode = ASTNode.createTopNode(block);
|
|
|
|
|
chai.assert.equal(topNode.getLocation(), block.previousConnection);
|
|
|
|
|
});
|
|
|
|
|
test('createTopNode-block', function() {
|
|
|
|
|
var block = this.blocks.noPrevConnection;
|
|
|
|
|
var topNode = Blockly.ASTNode.createTopNode(block);
|
|
|
|
|
var topNode = ASTNode.createTopNode(block);
|
|
|
|
|
chai.assert.equal(topNode.getLocation(), block);
|
|
|
|
|
});
|
|
|
|
|
test('createTopNode-output', function() {
|
|
|
|
|
var block = this.blocks.outputNextBlock;
|
|
|
|
|
var topNode = Blockly.ASTNode.createTopNode(block);
|
|
|
|
|
var topNode = ASTNode.createTopNode(block);
|
|
|
|
|
chai.assert.equal(topNode.getLocation(), block.outputConnection);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|