Skip to content

Commit

Permalink
Add and fix tests on boolean variable conditions (#7227)
Browse files Browse the repository at this point in the history
- Don't show in changelog
  • Loading branch information
D8H authored Dec 13, 2024
1 parent 536b0d5 commit e5d77da
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 9 deletions.
14 changes: 11 additions & 3 deletions GDevelop.js/TestUtils/GDJSMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ class RuntimeObject {
return variable.getAsNumber();
}

static getVariableString(variable) {
return variable.getAsString();
}

getVariableString(variable) {
return variable.getAsString();
}

static getVariableBoolean(variable) {
return variable.getAsBoolean();
}
Expand Down Expand Up @@ -935,7 +943,8 @@ function makeMinimalGDJSMock(options) {
variable: {
getVariableNumber: (variable) => variable.getAsNumber(),
getVariableString: (variable) => variable.getAsString(),
getVariableBoolean: (variable) => variable.getAsBoolean(),
getVariableBoolean: (variable, compareWith) =>
variable.getAsBoolean() === compareWith,
toggleVariableBoolean: (variable) =>
variable.setBoolean(!variable.getAsBoolean()),
variablePushCopy: (array, variable) =>
Expand All @@ -946,8 +955,7 @@ function makeMinimalGDJSMock(options) {
variable.hasChild(childName),
variableRemoveChild: (variable, childName) =>
variable.removeChild(childName),
variableClearChildren: (variable) =>
variable.clearChildren(),
variableClearChildren: (variable) => variable.clearChildren(),
},
object: {
createObjectOnScene,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('libGD.js - GDJS Code Generation integration tests', function () {
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanVariable' },
parameters: ['MyVariable'],
parameters: ['MyVariable', 'True', ''],
},
]);
expect(
Expand All @@ -229,7 +229,7 @@ describe('libGD.js - GDJS Code Generation integration tests', function () {
.setString('Same value');
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanVariable' },
type: { inverted: false, value: 'StringVariable' },
parameters: ['MyVariable', '=', '"Same value"'],
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('libGD.js - GDJS Code Generation integration tests', function () {
object.getVariables().insertNew('MyVariable', 0).setString('Same value');
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanObjectVariable' },
type: { inverted: false, value: 'StringObjectVariable' },
parameters: ['MyObject', 'MyVariable', '=', '"Same value"'],
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,77 @@ describe('libGD.js - GDJS Code Generation integration tests', function () {
).toBe(1);
});

it('can generate a scene boolean variable condition that is true', function () {
it('can generate a scene boolean variable condition that checks true', function () {
scene.getVariables().insertNew('MyVariable', 0).setBool(true);
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanVariable' },
parameters: ['MyVariable'],
parameters: ['MyVariable', 'True', ''],
},
]);
expect(
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
).toBe(1);
});

it('can generate a scene boolean variable condition that checks true (inverted)', function () {
scene.getVariables().insertNew('MyVariable', 0).setBool(false);
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: true, value: 'BooleanVariable' },
parameters: ['MyVariable', 'True', ''],
},
]);
expect(
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
).toBe(1);
});

it('can generate a scene boolean variable condition that checks false', function () {
scene.getVariables().insertNew('MyVariable', 0).setBool(false);
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanVariable' },
parameters: ['MyVariable', 'False', ''],
},
]);
expect(
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
).toBe(1);
});

it('can generate a scene boolean variable condition that checks false (inverted)', function () {
scene.getVariables().insertNew('MyVariable', 0).setBool(true);
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: true, value: 'BooleanVariable' },
parameters: ['MyVariable', 'False', ''],
},
]);
expect(
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
).toBe(1);
});

it('can generate a scene boolean variable condition that checks false (defaulted from an empty string)', function () {
scene.getVariables().insertNew('MyVariable', 0).setBool(false);
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanVariable' },
parameters: ['MyVariable', '', ''],
},
]);
expect(
runtimeScene.getVariables().get('SuccessVariable').getAsNumber()
).toBe(1);
});

it('can generate a scene boolean variable condition that checks false (defaulted from an empty string, inverted)', function () {
scene.getVariables().insertNew('MyVariable', 0).setBool(true);
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: true, value: 'BooleanVariable' },
parameters: ['MyVariable', '', ''],
},
]);
expect(
Expand All @@ -198,7 +263,7 @@ describe('libGD.js - GDJS Code Generation integration tests', function () {
scene.getVariables().insertNew('MyVariable', 0).setString('Same value');
const runtimeScene = generateAndRunVariableAffectationWithConditions([
{
type: { inverted: false, value: 'BooleanVariable' },
type: { inverted: false, value: 'StringVariable' },
parameters: ['MyVariable', '=', '"Same value"'],
},
]);
Expand Down

0 comments on commit e5d77da

Please sign in to comment.