コード例 #1
0
  public void test_addAll() {
    ASTNode parent = argumentList();
    ArrayList<ASTNode> firstNodes = new ArrayList<ASTNode>();
    ASTNode firstNode = booleanLiteral(true);
    ASTNode secondNode = booleanLiteral(false);
    firstNodes.add(firstNode);
    firstNodes.add(secondNode);
    NodeList<ASTNode> list = new NodeList<ASTNode>(parent);
    list.addAll(firstNodes);
    assertSize(2, list);
    assertSame(firstNode, list.get(0));
    assertSame(secondNode, list.get(1));
    assertSame(parent, firstNode.getParent());
    assertSame(parent, secondNode.getParent());

    ArrayList<ASTNode> secondNodes = new ArrayList<ASTNode>();
    ASTNode thirdNode = booleanLiteral(true);
    ASTNode fourthNode = booleanLiteral(false);
    secondNodes.add(thirdNode);
    secondNodes.add(fourthNode);
    list.addAll(secondNodes);
    assertSize(4, list);
    assertSame(firstNode, list.get(0));
    assertSame(secondNode, list.get(1));
    assertSame(thirdNode, list.get(2));
    assertSame(fourthNode, list.get(3));
    assertSame(parent, firstNode.getParent());
    assertSame(parent, secondNode.getParent());
    assertSame(parent, thirdNode.getParent());
    assertSame(parent, fourthNode.getParent());
  }
コード例 #2
0
  public void test_remove() {
    ArrayList<ASTNode> nodes = new ArrayList<ASTNode>();
    ASTNode firstNode = booleanLiteral(true);
    ASTNode secondNode = booleanLiteral(false);
    ASTNode thirdNode = booleanLiteral(true);
    nodes.add(firstNode);
    nodes.add(secondNode);
    nodes.add(thirdNode);
    NodeList<ASTNode> list = new NodeList<ASTNode>(argumentList());
    list.addAll(nodes);
    assertSize(3, list);

    assertSame(secondNode, list.remove(1));
    assertSize(2, list);
    assertSame(firstNode, list.get(0));
    assertSame(thirdNode, list.get(1));
  }
コード例 #3
0
  public void test_indexOf() {
    ArrayList<ASTNode> nodes = new ArrayList<ASTNode>();
    ASTNode firstNode = booleanLiteral(true);
    ASTNode secondNode = booleanLiteral(false);
    ASTNode thirdNode = booleanLiteral(true);
    ASTNode fourthNode = booleanLiteral(false);
    nodes.add(firstNode);
    nodes.add(secondNode);
    nodes.add(thirdNode);
    NodeList<ASTNode> list = new NodeList<ASTNode>(argumentList());
    list.addAll(nodes);
    assertSize(3, list);

    assertEquals(0, list.indexOf(firstNode));
    assertEquals(1, list.indexOf(secondNode));
    assertEquals(2, list.indexOf(thirdNode));
    assertEquals(-1, list.indexOf(fourthNode));
    assertEquals(-1, list.indexOf(null));
  }