Statement Declaration for my tests

I want to test my declaration of variables with expression via test on reference, but there is no createDeclarationStatement where I can create variable with expression, unlike in ASTFactory. Should I use BinaryExpression for that or can I “bind” them somehow?

What exactly do you want to test, and where is there no such function?

If I have such a declaration:
{ int x = 10 + 6; }

As AST it should be Block[Declaration_x[Type_int,Binary_+[Const_10,Const_6]]], right?

If I understand it right, then in the package implementation/tests we can use methods from the class prog2.tests.CompilerTests, which would be cahnged on the server with right implementation. In this class there is method createDeclaration, but it doesn’t take expression 10 + 6.

How can I write such a test?

Ahh, okay, I see what you mean.
However, as far as I know, the implementation of CompilerTest will not actually be changed on the server - what will be changed is the implementation of Compiler, with all the classes that that needs.

That means that you could just create a Compiler and then call getASTFactory on it to get a factory that you can use directly.

However, your tests probably inherit from CompilerTest, which already has a field astFactory that you can use. When the test is executed on the server, this should be the reference implementation of ASTFactory, so you can use this to construct the AST for the test.

1 Like

Thank you!