MCPcopy
hub / github.com/4ian/GDevelop / testExpression

Function testExpression

GDevelop.js/__tests__/Core.js:3881–3933  ·  view source on GitHub ↗
(
      type,
      expression,
      expectedError,
      expectedErrorPosition,
      expectedError2,
      expectedErrorPosition2
    )

Source from the content-addressed store, hash-verified

3879 });
3880
3881 function testExpression(
3882 type,
3883 expression,
3884 expectedError,
3885 expectedErrorPosition,
3886 expectedError2,
3887 expectedErrorPosition2
3888 ) {
3889 const parser = new gd.ExpressionParser2();
3890 const expressionNode = parser.parseExpression(expression).get();
3891
3892 const expressionValidator = new gd.ExpressionValidator(
3893 gd.JsPlatform.get(),
3894 gd.ProjectScopedContainers.makeNewProjectScopedContainersForProjectAndLayout(
3895 project,
3896 layout
3897 ),
3898 type,
3899 ''
3900 );
3901 expressionNode.visit(expressionValidator);
3902 if (expectedError2) {
3903 expect(expressionValidator.getAllErrors().size()).toBe(2);
3904 expect(expressionValidator.getAllErrors().at(0).getMessage()).toBe(
3905 expectedError
3906 );
3907 if (expectedErrorPosition)
3908 expect(
3909 expressionValidator.getAllErrors().at(0).getStartPosition()
3910 ).toBe(expectedErrorPosition);
3911 expect(expressionValidator.getAllErrors().at(1).getMessage()).toBe(
3912 expectedError2
3913 );
3914 if (expectedErrorPosition2)
3915 expect(
3916 expressionValidator.getAllErrors().at(1).getStartPosition()
3917 ).toBe(expectedErrorPosition2);
3918 } else if (expectedError) {
3919 expect(expressionValidator.getAllErrors().size()).toBe(1);
3920 expect(expressionValidator.getAllErrors().at(0).getMessage()).toBe(
3921 expectedError
3922 );
3923 if (expectedErrorPosition)
3924 expect(
3925 expressionValidator.getAllErrors().at(0).getStartPosition()
3926 ).toBe(expectedErrorPosition);
3927 } else {
3928 expect(expressionValidator.getAllErrors().size()).toBe(0);
3929 }
3930
3931 expressionValidator.delete();
3932 parser.delete();
3933 }
3934
3935 it('can parse valid expressions (number)', function () {
3936 testExpression('number', '1+1');

Callers 1

Core.jsFile · 0.85

Calls 5

toBeMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected