-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix the insertion order for CtStatementListImpl.insertBegin (#4065)
- Loading branch information
1 parent
55db471
commit c5e8ade
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/spoon/test/ctStatementList/CtStatementListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package spoon.test.ctStatementList; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import spoon.Launcher; | ||
import spoon.reflect.code.CtStatement; | ||
import spoon.reflect.code.CtStatementList; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.support.reflect.code.CtStatementListImpl; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CtStatementListTest { | ||
|
||
@Test | ||
void testInsertBeginWithListOfStatements() { | ||
// contract: insertBegin adds a list of statements at the beginning of the statementList | ||
|
||
// arrange | ||
Factory factory = new Launcher().getFactory(); | ||
|
||
CtStatement initialStatement = factory.Code().createCodeSnippetStatement("int preexisting = 42;").compile(); | ||
|
||
CtStatement firstStatementToBeInserted = factory.Code().createCodeSnippetStatement("int first = 1;").compile(); | ||
CtStatement secondStatementToBeInserted = factory.Code().createCodeSnippetStatement("int second = 2;").compile(); | ||
|
||
CtStatementList mainStatementList = new CtStatementListImpl<CtStatement>(); | ||
mainStatementList.addStatement(initialStatement); | ||
|
||
CtStatementList statementListToBeAddedToTheMainList = new CtStatementListImpl<CtStatement>(); | ||
statementListToBeAddedToTheMainList.addStatement(firstStatementToBeInserted); | ||
statementListToBeAddedToTheMainList.addStatement(secondStatementToBeInserted); | ||
|
||
// act | ||
mainStatementList.insertBegin(statementListToBeAddedToTheMainList); | ||
|
||
// assert | ||
CtStatement statementAtTheBeginningAfterInsertion = mainStatementList.getStatements().get(0); | ||
CtStatement secondStatementAtTheBeginningOfTheListAfterInsertion = mainStatementList.getStatements().get(1); | ||
|
||
assertEquals(firstStatementToBeInserted, statementAtTheBeginningAfterInsertion); | ||
assertEquals(secondStatementToBeInserted, secondStatementAtTheBeginningOfTheListAfterInsertion); | ||
|
||
assertThat(firstStatementToBeInserted.getParent(), is(mainStatementList)); | ||
assertThat(secondStatementToBeInserted.getParent(), is(mainStatementList)); | ||
} | ||
} |