mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-22 22:12:28 -05:00
Updating tests for refactoring lists. Updating demo fixture -- now we have IDs and variable types for variables.
This commit is contained in:
parent
26d4a3a069
commit
3f444138db
2 changed files with 51 additions and 11 deletions
2
test/fixtures/demo.json
vendored
2
test/fixtures/demo.json
vendored
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,6 @@
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
const Target = require('../../src/engine/target');
|
const Target = require('../../src/engine/target');
|
||||||
|
const Variable = require('../../src/engine/variable');
|
||||||
|
|
||||||
test('spec', t => {
|
test('spec', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
|
@ -23,14 +24,14 @@ test('spec', t => {
|
||||||
// Create Variable tests.
|
// Create Variable tests.
|
||||||
test('createVariable', t => {
|
test('createVariable', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
target.createVariable('foo', 'bar', '');
|
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE);
|
||||||
|
|
||||||
const variables = target.variables;
|
const variables = target.variables;
|
||||||
t.equal(Object.keys(variables).length, 1);
|
t.equal(Object.keys(variables).length, 1);
|
||||||
const variable = variables[Object.keys(variables)[0]];
|
const variable = variables[Object.keys(variables)[0]];
|
||||||
t.equal(variable.id, 'foo');
|
t.equal(variable.id, 'foo');
|
||||||
t.equal(variable.name, 'bar');
|
t.equal(variable.name, 'bar');
|
||||||
t.equal(variable.type, '');
|
t.equal(variable.type, Variable.SCALAR_TYPE);
|
||||||
t.equal(variable.value, 0);
|
t.equal(variable.value, 0);
|
||||||
t.equal(variable.isCloud, false);
|
t.equal(variable.isCloud, false);
|
||||||
|
|
||||||
|
@ -40,8 +41,8 @@ test('createVariable', t => {
|
||||||
// Create Same Variable twice.
|
// Create Same Variable twice.
|
||||||
test('createVariable2', t => {
|
test('createVariable2', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
target.createVariable('foo', 'bar', '');
|
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE);
|
||||||
target.createVariable('foo', 'bar', '');
|
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE);
|
||||||
|
|
||||||
const variables = target.variables;
|
const variables = target.variables;
|
||||||
t.equal(Object.keys(variables).length, 1);
|
t.equal(Object.keys(variables).length, 1);
|
||||||
|
@ -50,16 +51,16 @@ test('createVariable2', t => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a list
|
// Create a list
|
||||||
test('createVariable creates a list', t => {
|
test('createListVariable creates a list', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
target.createVariable('foo', 'bar', 'list');
|
target.createVariable('foo', 'bar', Variable.LIST_TYPE);
|
||||||
|
|
||||||
const variables = target.variables;
|
const variables = target.variables;
|
||||||
t.equal(Object.keys(variables).length, 1);
|
t.equal(Object.keys(variables).length, 1);
|
||||||
const variable = variables[Object.keys(variables)[0]];
|
const variable = variables[Object.keys(variables)[0]];
|
||||||
t.equal(variable.id, 'foo');
|
t.equal(variable.id, 'foo');
|
||||||
t.equal(variable.name, 'bar');
|
t.equal(variable.name, 'bar');
|
||||||
t.equal(variable.type, 'list');
|
t.equal(variable.type, Variable.LIST_TYPE);
|
||||||
t.assert(variable.value instanceof Array, true);
|
t.assert(variable.value instanceof Array, true);
|
||||||
t.equal(variable.value.length, 0);
|
t.equal(variable.value.length, 0);
|
||||||
t.equal(variable.isCloud, false);
|
t.equal(variable.isCloud, false);
|
||||||
|
@ -67,10 +68,20 @@ test('createVariable creates a list', t => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('createVariable throws when given invalid type', t => {
|
||||||
|
const target = new Target();
|
||||||
|
t.throws(
|
||||||
|
(() => target.createVariable('foo', 'bar', 'baz')),
|
||||||
|
new Error('Invalid variable type: baz')
|
||||||
|
);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
// Rename Variable tests.
|
// Rename Variable tests.
|
||||||
test('renameVariable', t => {
|
test('renameVariable', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
target.createVariable('foo', 'bar', '');
|
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE);
|
||||||
target.renameVariable('foo', 'bar2');
|
target.renameVariable('foo', 'bar2');
|
||||||
|
|
||||||
const variables = target.variables;
|
const variables = target.variables;
|
||||||
|
@ -99,7 +110,7 @@ test('renameVariable2', t => {
|
||||||
// Expect no change.
|
// Expect no change.
|
||||||
test('renameVariable3', t => {
|
test('renameVariable3', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
target.createVariable('foo1', 'foo', '');
|
target.createVariable('foo1', 'foo', Variable.SCALAR_TYPE);
|
||||||
target.renameVariable('foo', 'bar2');
|
target.renameVariable('foo', 'bar2');
|
||||||
|
|
||||||
const variables = target.variables;
|
const variables = target.variables;
|
||||||
|
@ -114,7 +125,7 @@ test('renameVariable3', t => {
|
||||||
// Delete Variable tests.
|
// Delete Variable tests.
|
||||||
test('deleteVariable', t => {
|
test('deleteVariable', t => {
|
||||||
const target = new Target();
|
const target = new Target();
|
||||||
target.createVariable('foo', 'bar', '');
|
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE);
|
||||||
target.deleteVariable('foo');
|
target.deleteVariable('foo');
|
||||||
|
|
||||||
const variables = target.variables;
|
const variables = target.variables;
|
||||||
|
@ -133,3 +144,32 @@ test('deleteVariable2', t => {
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('lookupOrCreateList creates a list if var with given id does not exist', t => {
|
||||||
|
const target = new Target();
|
||||||
|
const variables = target.variables;
|
||||||
|
|
||||||
|
t.equal(Object.keys(variables).length, 0);
|
||||||
|
const listVar = target.lookupOrCreateList('foo', 'bar');
|
||||||
|
t.equal(Object.keys(variables).length, 1);
|
||||||
|
t.equal(listVar.id, 'foo');
|
||||||
|
t.equal(listVar.name, 'bar');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('lookupOrCreateList returns list if one with given id exists', t => {
|
||||||
|
const target = new Target();
|
||||||
|
const variables = target.variables;
|
||||||
|
|
||||||
|
t.equal(Object.keys(variables).length, 0);
|
||||||
|
target.createVariable('foo', 'bar', Variable.LIST_TYPE);
|
||||||
|
t.equal(Object.keys(variables).length, 1);
|
||||||
|
|
||||||
|
const listVar = target.lookupOrCreateList('foo', 'bar');
|
||||||
|
t.equal(Object.keys(variables).length, 1);
|
||||||
|
t.equal(listVar.id, 'foo');
|
||||||
|
t.equal(listVar.name, 'bar');
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue