Skip to content

Commit

Permalink
added PreOperatorExpressionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 21, 2023
1 parent 3bf1130 commit 8331097
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PreOperatorExpression extends AbstractLineNumberExpression {
public PreOperatorExpression(int lineNumber, String operator, Expression expression) {
super(lineNumber);
this.operator = operator;
this.expression = expression;
this.setExpression(expression);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.jd.core.v1.model.javasyntax.expression;

import org.jd.core.v1.model.javasyntax.type.PrimitiveType;
import org.jd.core.v1.model.javasyntax.type.Type;
import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.TestVisitor;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class PreOperatorExpressionTest {

@Test
public void testPreOperatorExpression() {
Expression expression = new IntegerConstantExpression(10, PrimitiveType.TYPE_INT, 5);
String operator = "++";
PreOperatorExpression preOperatorExpression = new PreOperatorExpression(10, operator, expression);

// Test getOperator
assertEquals(operator, preOperatorExpression.getOperator());

// Test getExpression
assertEquals(expression, preOperatorExpression.getExpression());

// Test getType
Type expectedType = PrimitiveType.TYPE_INT;
assertEquals(expectedType, preOperatorExpression.getType());

// Test getPriority
assertEquals(2, preOperatorExpression.getPriority());

// Test isPreOperatorExpression
assertTrue(preOperatorExpression.isPreOperatorExpression());

// Test toString
assertEquals("PreOperatorExpression{++ IntegerConstantExpression{type=PrimitiveType{primitive=int}, value=5}}", preOperatorExpression.toString());

// Test copyTo
PreOperatorExpression copiedExpression = (PreOperatorExpression) preOperatorExpression.copyTo(20);
assertEquals(preOperatorExpression.getOperator(), copiedExpression.getOperator());
assertEquals(preOperatorExpression.getExpression(), copiedExpression.getExpression());
assertEquals(20, copiedExpression.getLineNumber());

// Test the accept method with a simple visitor
TestVisitor visitor = new TestVisitor();
copiedExpression.accept(visitor);
assertEquals(1, visitor.getPreOperatorExpressionCount());
}
}

0 comments on commit 8331097

Please sign in to comment.