aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index e0c074a126..5137b45c65 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -32,43 +32,45 @@ import org.junit.runners.JUnit4;
import java.util.LinkedList;
import java.util.List;
-
/**
* Tests of parser behaviour.
*/
@RunWith(JUnit4.class)
public class ParserTest extends EvaluationTestCase {
- EvaluationContext buildContext;
- EvaluationContext buildContextWithPython;
+ Environment buildEnvironment;
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- buildContext = EvaluationContext.newBuildContext(getEventHandler());
- buildContextWithPython = EvaluationContext.newBuildContext(
- getEventHandler(), new Environment(), /*parsePython*/true);
+ buildEnvironment = newBuildEnvironment();
}
private Parser.ParseResult parseFileWithComments(String... input) {
- return buildContext.parseFileWithComments(input);
+ return buildEnvironment.parseFileWithComments(input);
}
+
+ /** Parses build code (not Skylark) */
@Override
protected List<Statement> parseFile(String... input) {
- return buildContext.parseFile(input);
+ return buildEnvironment.parseFile(input);
}
+
+ /** Parses a build code (not Skylark) with PythonProcessing enabled */
private List<Statement> parseFileWithPython(String... input) {
- return buildContextWithPython.parseFile(input);
+ return Parser.parseFile(
+ buildEnvironment.createLexer(input),
+ getEventHandler(),
+ Environment.EMPTY_PACKAGE_LOCATOR,
+ /*parsePython=*/true).statements;
}
+
+ /** Parses Skylark code */
private List<Statement> parseFileForSkylark(String... input) {
- return evaluationContext.parseFile(input);
- }
- private Statement parseStatement(String... input) {
- return buildContext.parseStatement(input);
+ return env.parseFile(input);
}
-
private static String getText(String text, ASTNode node) {
return text.substring(node.getLocation().getStartOffset(),
node.getLocation().getEndOffset());
@@ -707,7 +709,7 @@ public class ParserTest extends EvaluationTestCase {
@Test
public void testParserContainsErrors() throws Exception {
setFailFast(false);
- parseStatement("+");
+ parseFile("+");
assertContainsEvent("syntax error at '+'");
}