Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue124: add LexicalDifferenceCalculatorTest
- Loading branch information
1 parent
918a2d2
commit 1259e56
Showing
2 changed files
with
57 additions
and
22 deletions.
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
36 changes: 36 additions & 0 deletions
36
...va/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculatorTest.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,36 @@ | ||
package com.github.javaparser.printer.lexicalpreservation; | ||
|
||
import com.github.javaparser.ast.PackageDeclaration; | ||
import com.github.javaparser.ast.expr.Name; | ||
import com.github.javaparser.ast.observer.ObservableProperty; | ||
import com.github.javaparser.printer.ConcreteSyntaxModel; | ||
import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; | ||
import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class LexicalDifferenceCalculatorTest extends AbstractLexicalPreservingTest { | ||
|
||
@Test | ||
public void compilationUnitExampleOriginal() { | ||
considerCode("class A {}"); | ||
CsmElement element = ConcreteSyntaxModel.forClass(cu.getClass()); | ||
LexicalDifferenceCalculator.CalculatedSyntaxModel csmOriginal = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(element, cu); | ||
assertEquals(2, csmOriginal.elements.size()); | ||
assertEquals(new LexicalDifferenceCalculator.CsmChild(cu.getType(0)), csmOriginal.elements.get(0)); | ||
assertEquals(new CsmToken(3), csmOriginal.elements.get(1)); | ||
} | ||
|
||
@Test | ||
public void compilationUnitExampleWithPackageSet() { | ||
considerCode("class A {}"); | ||
CsmElement element = ConcreteSyntaxModel.forClass(cu.getClass()); | ||
PackageDeclaration packageDeclaration = new PackageDeclaration(new Name(new Name("foo"), "bar")); | ||
LexicalDifferenceCalculator.CalculatedSyntaxModel csmChanged = new LexicalDifferenceCalculator().calculatedSyntaxModelAfterPropertyChange(element, cu, ObservableProperty.PACKAGE_DECLARATION, null, packageDeclaration); | ||
assertEquals(3, csmChanged.elements.size()); | ||
assertEquals(new LexicalDifferenceCalculator.CsmChild(packageDeclaration), csmChanged.elements.get(0)); | ||
assertEquals(new LexicalDifferenceCalculator.CsmChild(cu.getType(0)), csmChanged.elements.get(1)); | ||
assertEquals(new CsmToken(3), csmChanged.elements.get(2)); | ||
} | ||
} |