diff --git a/GDevelop.js/TestUtils/GDJSMocks.js b/GDevelop.js/TestUtils/GDJSMocks.js index f680b20f0f31..e3b03d2439e1 100644 --- a/GDevelop.js/TestUtils/GDJSMocks.js +++ b/GDevelop.js/TestUtils/GDJSMocks.js @@ -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(); } @@ -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) => @@ -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, diff --git a/GDevelop.js/__tests__/GDJSExtensionVariableCodeGenerationIntegrationTests.js b/GDevelop.js/__tests__/GDJSExtensionVariableCodeGenerationIntegrationTests.js index 6aa0a4767c43..d80496f30636 100644 --- a/GDevelop.js/__tests__/GDJSExtensionVariableCodeGenerationIntegrationTests.js +++ b/GDevelop.js/__tests__/GDJSExtensionVariableCodeGenerationIntegrationTests.js @@ -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( @@ -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"'], }, ]); diff --git a/GDevelop.js/__tests__/GDJSSceneObjectVariableCodeGenerationIntegrationTests.js b/GDevelop.js/__tests__/GDJSSceneObjectVariableCodeGenerationIntegrationTests.js index 96407208ab61..3673c35c73f0 100644 --- a/GDevelop.js/__tests__/GDJSSceneObjectVariableCodeGenerationIntegrationTests.js +++ b/GDevelop.js/__tests__/GDJSSceneObjectVariableCodeGenerationIntegrationTests.js @@ -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"'], }, ]); diff --git a/GDevelop.js/__tests__/GDJSSceneVariableCodeGenerationIntegrationTests.js b/GDevelop.js/__tests__/GDJSSceneVariableCodeGenerationIntegrationTests.js index 00af220fb163..1457bdcf8c02 100644 --- a/GDevelop.js/__tests__/GDJSSceneVariableCodeGenerationIntegrationTests.js +++ b/GDevelop.js/__tests__/GDJSSceneVariableCodeGenerationIntegrationTests.js @@ -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( @@ -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"'], }, ]);