diff options
author | 2015-07-23 14:44:36 +0000 | |
---|---|---|
committer | 2015-07-27 08:31:45 +0000 | |
commit | 9d659ad0a1024544eb6275391b56660a1d981109 (patch) | |
tree | 8865a1fee36d2c6fc0f8117163b1e5944d97ceb0 /src/test/java/com/google | |
parent | 6234080eb9eba204f1ce66d2761ac7d531765e7a (diff) |
Skylark: load() allows the loading of symbols via an alias.
E.g. load("/foo/bla", my_rule = "old_name") will introduce the symbol "my_rule" as an alias for "old_name".
--
MOS_MIGRATED_REVID=98933635
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java | 43 |
1 files changed, 43 insertions, 0 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 dad2d46e89..93e14a8c56 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 @@ -29,8 +29,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import java.util.LinkedList; import java.util.List; + /** * Tests of parser behaviour. */ @@ -1069,6 +1071,47 @@ public class ParserTest extends EvaluationTestCase { } @Test + public void testLoadAlias() throws Exception { + runLoadAliasTestForSymbols("my_alias = 'lawl'", "my_alias"); + } + + @Test + public void testLoadAliasMultiple() throws Exception { + runLoadAliasTestForSymbols( + "my_alias = 'lawl', 'lol', next_alias = 'rofl'", "my_alias", "lol", "next_alias"); + } + + private void runLoadAliasTestForSymbols(String loadSymbolString, String... expectedSymbols) { + List<Statement> statements = + parseFileForSkylark(String.format("load('/foo/bar/file', %s)\n", loadSymbolString)); + LoadStatement stmt = (LoadStatement) statements.get(0); + ImmutableList<Identifier> actualSymbols = stmt.getSymbols(); + + assertThat(actualSymbols).hasSize(expectedSymbols.length); + + List<String> actualSymbolNames = new LinkedList<>(); + + for (Identifier identifier : actualSymbols) { + actualSymbolNames.add(identifier.getName()); + } + + assertThat(actualSymbolNames).containsExactly((Object[]) expectedSymbols); + } + + @Test + public void testLoadAliasSyntaxError() throws Exception { + setFailFast(false); + parseFileForSkylark("load('/foo', test1 = )\n"); + assertContainsEvent("syntax error at ')': expected string"); + + parseFileForSkylark("load('/foo', test2 = 1)\n"); + assertContainsEvent("syntax error at '1': expected string"); + + parseFileForSkylark("load('/foo', test3 = old)\n"); + assertContainsEvent("syntax error at 'old': expected string"); + } + + @Test public void testParseErrorNotComparison() throws Exception { setFailFast(false); parseFile("2 < not 3"); |