Skip to content

Commit

Permalink
unary, binary, and assignment op test.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 1, 2023
1 parent 45c76ac commit c4ebec6
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Issue;
Expand Down Expand Up @@ -509,6 +512,57 @@ public K.When visitWhen(K.When when, AtomicBoolean found) {
);
}

@ParameterizedTest
@CsvSource({
"n++,kotlin.Int",
"--n,kotlin.Int",
"n += a,kotlin.Int",
"n = a + b,kotlin.Int{name=plus,return=kotlin.Int,parameters=[kotlin.Int]}"
})
void operatorOverload(String p1, String p2) {
rewriteRun(
kotlin(
"""
class Foo {
fun bar(a: Int, b: Int) {
var n = 0
%s
}
}
""".formatted(p1), spec -> spec.afterRecipe(cu -> {
AtomicBoolean found = new AtomicBoolean(false);
new KotlinIsoVisitor<AtomicBoolean>() {
@Override
public J.AssignmentOperation visitAssignmentOperation(J.AssignmentOperation assignOp, AtomicBoolean atomicBoolean) {
if (p2.equals(assignOp.getType().toString())) {
found.set(true);
}
return super.visitAssignmentOperation(assignOp, atomicBoolean);
}

@Override
public J.Unary visitUnary(J.Unary unary, AtomicBoolean b) {
if (p2.equals(unary.getType().toString())) {
found.set(true);
}
return super.visitUnary(unary, b);
}

@Override
public J.Binary visitBinary(J.Binary binary, AtomicBoolean b) {
JavaType.Method mt = (JavaType.Method) binary.getType();
if (p2.equals(mt.toString())) {
found.set(true);
}
return super.visitBinary(binary, b);
}
}.visit(cu, found);
assertThat(found.get()).isEqualTo(true);
})
)
);
}

@Test
void operatorOverload() {
rewriteRun(
Expand Down

0 comments on commit c4ebec6

Please sign in to comment.