2727import com .github .gumtreediff .tree .*;
2828import org .junit .jupiter .api .Test ;
2929
30- import javax .lang .model .type .ArrayType ;
31-
3230import static org .junit .jupiter .api .Assertions .*;
3331
3432public class TestTree {
@@ -52,6 +50,27 @@ public void testSearchSubtree() {
5250 assertEquals (0 , results .size ());
5351 }
5452
53+ @ Test
54+ public void testIsRoot () {
55+ Tree tree = new DefaultTree (TypeSet .type ("a" ));
56+ tree .addChild (new DefaultTree (TypeSet .type ("b" )));
57+ tree .addChild (new DefaultTree (TypeSet .type ("c" ), "foo" ));
58+ assertTrue (tree .isRoot ());
59+ assertFalse (tree .getChild (0 ).isRoot ());
60+ assertFalse (tree .getChild (1 ).isRoot ());
61+ }
62+
63+ @ Test
64+ public void testInsertChild () {
65+ Tree tree = new DefaultTree (TypeSet .type ("a" ));
66+ tree .addChild (new DefaultTree (TypeSet .type ("b" )));
67+ tree .addChild (new DefaultTree (TypeSet .type ("c" ), "foo" ));
68+ System .out .println (tree .getChildren ().size ());
69+ tree .insertChild (new DefaultTree (TypeSet .type ("m" )), 1 );
70+ assertEquals (TypeSet .type ("m" ), tree .getChild (1 ).getType ());
71+ assertEquals (tree , tree .getChild (1 ).getParent ());
72+ }
73+
5574 @ Test
5675 public void testTreesBetweenPositions () {
5776 Tree root = TreeLoader .getDummySrc ();
@@ -179,7 +198,9 @@ public void testIsostructure() {
179198 assertTrue (root .isIsoStructuralTo (rootCpy ));
180199 rootCpy .getChild ("0.0" ).setLabel ("foo" );
181200 assertTrue (root .isIsoStructuralTo (rootCpy ));
182- root .getChild ("0.0" ).setLabel ("foo" );
201+ rootCpy .getChild ("0.1" ).setType (TypeSet .type ("foo" ));
202+ assertFalse (root .isIsoStructuralTo (rootCpy ));
203+ root .getChild ("0.1" ).setType (TypeSet .type ("foo" ));
183204 assertTrue (root .isIsoStructuralTo (rootCpy ));
184205 root .addChild (new FakeTree ());
185206 assertFalse (root .isIsoStructuralTo (rootCpy ));
@@ -232,6 +253,13 @@ public void testFakeTree() {
232253
233254 @ Test
234255 public void testTypesAndLabels () {
256+ Type origType = TypeSet .type ("anewtype" );
257+ Type otherType = TypeSet .type ("othernewtype" );
258+ Type origCopyType = TypeSet .type ("anewtype" );
259+ assertNotNull (origType );
260+ assertSame (origType , origCopyType );
261+ assertNotEquals (origType , otherType );
262+ assertEquals ("anewtype" , origType .name );
235263 Tree t1 = new DefaultTree (TypeSet .type ("foo" ));
236264 Tree t2 = new DefaultTree (TypeSet .type ("foo" ));
237265 assertTrue (t1 .hasSameType (t2 ));
0 commit comments