Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/utilities/ast/ASTNodesTest.java |
| diff --git a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/utilities/ast/ASTNodesTest.java b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/utilities/ast/ASTNodesTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3c9c19564ffc219c81065cdfd7d5924e92b94232 |
| --- /dev/null |
| +++ b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/utilities/ast/ASTNodesTest.java |
| @@ -0,0 +1,121 @@ |
| +/* |
| + * Copyright (c) 2013, the Dart project authors. |
| + * |
| + * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except |
| + * in compliance with the License. You may obtain a copy of the License at |
| + * |
| + * http://www.eclipse.org/legal/epl-v10.html |
| + * |
| + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| + * or implied. See the License for the specific language governing permissions and limitations under |
| + * the License. |
| + */ |
| +package com.google.dart.engine.utilities.ast; |
| + |
| +import com.google.dart.engine.ast.BinaryExpression; |
| +import com.google.dart.engine.ast.MethodInvocation; |
| +import com.google.dart.engine.ast.PostfixExpression; |
| +import com.google.dart.engine.ast.PrefixExpression; |
| +import com.google.dart.engine.ast.SimpleIdentifier; |
| +import com.google.dart.engine.scanner.Token; |
| +import com.google.dart.engine.scanner.TokenType; |
| + |
| +import junit.framework.TestCase; |
| + |
| +import static org.mockito.Mockito.mock; |
| +import static org.mockito.Mockito.when; |
| + |
| +public class ASTNodesTest extends TestCase { |
| + public void test_inGetterContext_isBinaryParent_isPureAssignment() throws Exception { |
| + BinaryExpression parent = mock(BinaryExpression.class); |
|
Brian Wilkerson
2013/01/07 21:27:18
Using mocks here feels like overkill. AST nodes ar
Brian Wilkerson
2013/01/07 21:27:18
This should be an AssignmentExpression.
scheglov
2013/01/07 22:45:41
Agree.
Tests for SimpleIdentifier will use ASTFact
|
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.EQ, 0)); |
| + when(parent.getLeftOperand()).thenReturn(identifier); |
| + when(identifier.getParent()).thenReturn(parent); |
| + // verify |
| + assertEquals(false, ASTNodes.inGetterContext(identifier)); |
| + } |
| + |
| + public void test_inGetterContext_isBinaryParent_notPureAssignment() throws Exception { |
| + BinaryExpression parent = mock(BinaryExpression.class); |
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.PLUS_EQ, 0)); |
| + when(parent.getLeftOperand()).thenReturn(identifier); |
| + when(identifier.getParent()).thenReturn(parent); |
| + // verify |
| + assertEquals(true, ASTNodes.inGetterContext(identifier)); |
| + } |
| + |
| + public void test_inGetterContext_notBinaryParent() throws Exception { |
| + MethodInvocation parent = mock(MethodInvocation.class); |
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(identifier.getParent()).thenReturn(parent); |
| + assertEquals(true, ASTNodes.inGetterContext(identifier)); |
| + } |
| + |
| + public void test_inSetterContext_binaryParent() throws Exception { |
| + BinaryExpression parent = mock(BinaryExpression.class); |
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(parent.getLeftOperand()).thenReturn(identifier); |
| + when(identifier.getParent()).thenReturn(parent); |
| + // = |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.EQ, 0)); |
| + assertEquals(true, ASTNodes.inSetterContext(identifier)); |
| + } |
| + // += |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.PLUS_EQ, 0)); |
| + assertEquals(true, ASTNodes.inSetterContext(identifier)); |
| + } |
| + // |= |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.BAR_EQ, 0)); |
| + assertEquals(true, ASTNodes.inSetterContext(identifier)); |
| + } |
| + // + |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.PLUS, 0)); |
| + assertEquals(false, ASTNodes.inSetterContext(identifier)); |
| + } |
| + } |
| + |
| + public void test_inSetterContext_notInterestingParent() throws Exception { |
| + MethodInvocation parent = mock(MethodInvocation.class); |
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(identifier.getParent()).thenReturn(parent); |
| + assertEquals(false, ASTNodes.inSetterContext(identifier)); |
| + } |
| + |
| + public void test_inSetterContext_postfixParent() throws Exception { |
| + PostfixExpression parent = mock(PostfixExpression.class); |
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(parent.getOperand()).thenReturn(identifier); |
| + when(identifier.getParent()).thenReturn(parent); |
| + // always |
| + assertEquals(true, ASTNodes.inSetterContext(identifier)); |
| + } |
| + |
| + public void test_inSetterContext_prefixParent() throws Exception { |
| + PrefixExpression parent = mock(PrefixExpression.class); |
| + SimpleIdentifier identifier = mock(SimpleIdentifier.class); |
| + when(parent.getOperand()).thenReturn(identifier); |
| + when(identifier.getParent()).thenReturn(parent); |
| + // ++ |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.PLUS_PLUS, 0)); |
| + assertEquals(true, ASTNodes.inSetterContext(identifier)); |
| + } |
| + // -- |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.MINUS_MINUS, 0)); |
| + assertEquals(true, ASTNodes.inSetterContext(identifier)); |
| + } |
| + // ! |
| + { |
| + when(parent.getOperator()).thenReturn(new Token(TokenType.BANG, 0)); |
| + assertEquals(false, ASTNodes.inSetterContext(identifier)); |
| + } |
| + } |
| +} |