mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
feat: add JSO serialization and deserialization of variables (#5131)
* Add variable serialization tests * Fix requires for new file * Add serialization and deserialization of variables * Remove only in tests * Cleanup
This commit is contained in:
committed by
alschmiedt
parent
56d3cb6c8f
commit
28ff2c84c6
@@ -26,15 +26,16 @@ suite('JSO', function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
function assertProperty(obj, property, value) {
|
||||
chai.assert.deepEqual(obj[property], value);
|
||||
}
|
||||
|
||||
function assertNoProperty(obj, property) {
|
||||
assertProperty(obj, property, undefined);
|
||||
}
|
||||
|
||||
|
||||
suite('Blocks', function() {
|
||||
function assertProperty(obj, property, value) {
|
||||
chai.assert.deepEqual(obj[property], value);
|
||||
}
|
||||
|
||||
function assertNoProperty(obj, property) {
|
||||
assertProperty(obj, property, undefined);
|
||||
}
|
||||
|
||||
test('Null on insertionMarkers', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
block.setInsertionMarker(true);
|
||||
@@ -634,4 +635,23 @@ suite('JSO', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Variables', function() {
|
||||
test('Without type', function() {
|
||||
const variable = this.workspace.createVariable('testVar', '', 'testId');
|
||||
const jso = Blockly.serialization.variables.save(variable);
|
||||
assertProperty(jso, 'name', 'testVar');
|
||||
assertProperty(jso, 'id', 'testId');
|
||||
assertNoProperty(jso, 'type');
|
||||
});
|
||||
|
||||
test('With type', function() {
|
||||
const variable = this.workspace
|
||||
.createVariable('testVar', 'testType', 'testId');
|
||||
const jso = Blockly.serialization.variables.save(variable);
|
||||
assertProperty(jso, 'name', 'testVar');
|
||||
assertProperty(jso, 'id', 'testId');
|
||||
assertProperty(jso, 'type', 'testType');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user