Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kniazkov committed Jun 14, 2024
1 parent 49b80ac commit 0a6be82
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/java/org/cqfn/astranaut/core/BaseNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package org.cqfn.astranaut.core;

import java.util.Iterator;
import java.util.NoSuchElementException;
import org.cqfn.astranaut.core.example.LittleTrees;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -46,4 +48,25 @@ void testDeepCompareMethod() {
Assertions.assertTrue(deleted);
Assertions.assertFalse(first.deepCompare(second));
}

/**
* Testing {@link Node#deepCompare(Node)} method.
*/
@Test
void testNodeIterator() {
final Node root = DraftNode.createByDescription("A(B,C)");
final Iterator<Node> iterator = root.iterator();
Assertions.assertTrue(iterator.hasNext());
Assertions.assertEquals("B", iterator.next().getTypeName());
Assertions.assertTrue(iterator.hasNext());
Assertions.assertEquals("C", iterator.next().getTypeName());
Assertions.assertFalse(iterator.hasNext());
boolean oops = false;
try {
iterator.next();
} catch (final NoSuchElementException ignored) {
oops = true;
}
Assertions.assertTrue(oops);
}
}
21 changes: 21 additions & 0 deletions src/test/java/org/cqfn/astranaut/core/DifferenceNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ void testInsertNodeFails() {
Assertions.assertFalse(result);
}

/**
* Tests {@link DifferenceNode#getParent()} method.
*/
@Test
void testParentReference() {
final DifferenceNode root = new DifferenceNode(DraftNode.createByDescription("A(B,C)"));
final Node child = root.getChild(0);
Assertions.assertTrue(child instanceof DifferenceNode);
Assertions.assertSame(((DifferenceNode) child).getParent(), root);
}

/**
* Tests {@link DifferenceNode#getParent()} method.
*/
@Test
void testDiffNodeAsString() {
final String description = "X(Y, Z)";
final DifferenceNode root = new DifferenceNode(DraftNode.createByDescription(description));
Assertions.assertEquals(description, root.toString());
}

/**
* Returns content of the specified file.
* @param name The name of the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Set;
import java.util.TreeMap;
import org.cqfn.astranaut.core.Builder;
import org.cqfn.astranaut.core.DifferenceNode;
import org.cqfn.astranaut.core.DraftNode;
import org.cqfn.astranaut.core.Insertion;
import org.cqfn.astranaut.core.Node;
Expand All @@ -49,6 +50,19 @@
* @since 1.1.5
*/
class PatcherTest {
@Test
void patchingByPatternThatDoesNotMatch() {
final Node source = DraftNode.createByDescription("A(B,C,D)");
final PatternNode pattern = new PatternNode(
new DifferenceNode(
DraftNode.createByDescription("D")
)
);
final Patcher patcher = new DefaultPatcher();
final Node result = patcher.patch(source, pattern);
Assertions.assertTrue(source.deepCompare(result));
}

@Test
void patchPatternWithInsertion() {
final Map<String, Set<Node>> nodes = new TreeMap<>();
Expand Down

0 comments on commit 0a6be82

Please sign in to comment.