Skip to content

Commit

Permalink
Merge pull request #1 from 4ian/master
Browse files Browse the repository at this point in the history
Merge from upstream
  • Loading branch information
Wend1go committed Jan 23, 2019
2 parents fb6b959 + 4af867b commit f214565
Show file tree
Hide file tree
Showing 87 changed files with 14,634 additions and 2,291 deletions.
6 changes: 3 additions & 3 deletions GDJS/Runtime/events-tools/networktools.js
Expand Up @@ -52,9 +52,9 @@ gdjs.evtTools.network.variableStructureToJSON = function(variable)
{
if ( !variable.isStructure() ) {
if ( variable.isNumber() )
return variable.getAsNumber().toString();
return JSON.stringify(variable.getAsNumber());
else
return "\""+variable.getAsString()+"\"";
return JSON.stringify(variable.getAsString());
}

var str = "{";
Expand All @@ -63,7 +63,7 @@ gdjs.evtTools.network.variableStructureToJSON = function(variable)
for(var p in children) {
if (children.hasOwnProperty(p)) {
if ( !firstChild ) str += ",";
str += "\""+p+"\": "+gdjs.evtTools.network.variableStructureToJSON(children[p]);
str += JSON.stringify(p) + ": " + gdjs.evtTools.network.variableStructureToJSON(children[p]);

firstChild = false;
}
Expand Down
1 change: 1 addition & 0 deletions GDJS/tests/karma.conf.js
Expand Up @@ -38,6 +38,7 @@ module.exports = function(config) {
'../Runtime/events-tools/commontools.js',
'../Runtime/events-tools/runtimescenetools.js',
'../Runtime/events-tools/inputtools.js',
'../Runtime/events-tools/networktools.js',
'../Runtime/events-tools/objecttools.js',
'../Runtime/events-tools/cameratools.js',
'../Runtime/events-tools/soundtools.js',
Expand Down
136 changes: 89 additions & 47 deletions GDJS/tests/tests/variable.js
Expand Up @@ -4,53 +4,95 @@
*/

describe('gdjs.variable', function() {
it('should parse initial values into strings and numbers', function() {
var intVar = new gdjs.Variable({ value: '526' });
var floatVar = new gdjs.Variable({ value: '10.568' });
var strVar = new gdjs.Variable({ value: 'testing variables' });
var numStrVar = new gdjs.Variable({ value: '5Apples' });

it('should parse initial values into strings and numbers', function(){

var intVar = new gdjs.Variable( {value : "526"} );
var floatVar = new gdjs.Variable( {value : "10.568"} );
var strVar = new gdjs.Variable( {value : "testing variables"} );
var numStrVar = new gdjs.Variable( {value : "5Apples"} );

expect(intVar.getAsNumber()).to.be(526);
expect(intVar.getAsString()).to.be("526");
expect(floatVar.getAsNumber()).to.be(10.568);
expect(floatVar.getAsString()).to.be("10.568");
expect(strVar.getAsNumber()).to.be(0);
expect(strVar.getAsString()).to.be("testing variables");
expect(numStrVar.getAsNumber()).to.be(5);
expect(numStrVar.getAsString()).to.be("5Apples");
});

it('should do some variable arithmetics', function(){

var a = new gdjs.Variable( {value : "5"} );

a.add(3);
expect(a.getAsNumber()).to.be(8);
a.sub(10);
expect(a.getAsNumber()).to.be(-2);
a.mul(3);
expect(a.getAsNumber()).to.be(-6);
a.div(-2);
expect(a.getAsNumber()).to.be(3);
a.concatenate("Apples");
expect(a.getAsString()).to.be("3Apples");

});

it('should clear a structure', function(){
var structure = new gdjs.Variable( {value : "0"} );
structure.getChild("a").setNumber(5);
structure.getChild("b").getChild("alpha").setString("Apples");

expect(structure.hasChild("a")).to.be(true);
expect(structure.hasChild("b")).to.be(true);
expect(structure.getChild("b").hasChild("alpha")).to.be(true);

structure.clearChildren();
expect(structure.hasChild("a")).to.be(false);
expect(structure.hasChild("b")).to.be(false);
})
expect(intVar.getAsNumber()).to.be(526);
expect(intVar.getAsString()).to.be('526');
expect(floatVar.getAsNumber()).to.be(10.568);
expect(floatVar.getAsString()).to.be('10.568');
expect(strVar.getAsNumber()).to.be(0);
expect(strVar.getAsString()).to.be('testing variables');
expect(numStrVar.getAsNumber()).to.be(5);
expect(numStrVar.getAsString()).to.be('5Apples');
});

it('should do some variable arithmetics', function() {
var a = new gdjs.Variable({ value: '5' });

a.add(3);
expect(a.getAsNumber()).to.be(8);
a.sub(10);
expect(a.getAsNumber()).to.be(-2);
a.mul(3);
expect(a.getAsNumber()).to.be(-6);
a.div(-2);
expect(a.getAsNumber()).to.be(3);
a.concatenate('Apples');
expect(a.getAsString()).to.be('3Apples');
});

it('should clear a structure', function() {
var structure = new gdjs.Variable({ value: '0' });
structure.getChild('a').setNumber(5);
structure
.getChild('b')
.getChild('alpha')
.setString('Apples');

expect(structure.hasChild('a')).to.be(true);
expect(structure.hasChild('b')).to.be(true);
expect(structure.getChild('b').hasChild('alpha')).to.be(true);

structure.clearChildren();
expect(structure.hasChild('a')).to.be(false);
expect(structure.hasChild('b')).to.be(false);
});

it('can be serialized to JSON', function() {
var structure = new gdjs.Variable({ value: '0' });
structure.getChild('a').setNumber(5);
structure
.getChild('b')
.getChild('alpha')
.setString('Apples');
structure
.getChild('b')
.getChild('Child with quotes "" and a backlash \\')
.setString(
'String with quotes "", and a backslash \\ and new line \\n \\n\\r and brackets {[{}]}!'
);

expect(gdjs.evtTools.network.variableStructureToJSON(structure)).to.be(
'{"a": 5,"b": {"alpha": "Apples","Child with quotes \\"\\" and a backlash \\\\": "String with quotes \\"\\", and a backslash \\\\ and new line \\\\n \\\\n\\\\r and brackets {[{}]}!"}}'
);
});

it('can be unserialized from JSON', function() {
var structure = new gdjs.Variable({ value: '0' });

gdjs.evtTools.network.jsonToVariableStructure(
'{"a": 5,"b": {"alpha": "Apples","Child with quotes \\"\\" and a backlash \\\\": "String with quotes \\"\\", and a backslash \\\\ and new line \\\\n \\\\n\\\\r and brackets {[{}]}!"}}',
structure
);

expect(structure.getChild('a').getAsNumber()).to.be(5);
expect(
structure
.getChild('b')
.getChild('alpha')
.getAsString()
).to.be('Apples');
expect(
structure
.getChild('b')
.getChild('Child with quotes "" and a backlash \\')
.getAsString()
).to.be(
'String with quotes "", and a backslash \\ and new line \\n \\n\\r and brackets {[{}]}!'
);
});
});
1 change: 1 addition & 0 deletions newIDE/app/package.json
Expand Up @@ -45,6 +45,7 @@
"react-error-boundary": "^1.2.0",
"react-i18next": "6.2.0",
"react-json-view": "^1.16.1",
"react-markdown": "^4.0.6",
"react-measure": "1.4.7",
"react-monaco-editor": "^0.18.0",
"react-mosaic-component": "1.0.3",
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f214565

Please sign in to comment.