diff options
author | 2015-02-26 13:39:28 +0000 | |
---|---|---|
committer | 2015-02-26 13:39:28 +0000 | |
commit | 89f012dd8b5c75573668c0a5a984d814da31c46f (patch) | |
tree | 74d4c305f67ab2be73d18e22eb7597e8da6ec588 /src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java | |
parent | 5a4f28664237fd5d53273c791f5f2decbf27d45b (diff) |
Open source all the tests under lib/syntax/.
--
MOS_MIGRATED_REVID=87244284
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java b/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java new file mode 100644 index 0000000000..75fed7d4e2 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/syntax/GlobCriteriaTest.java @@ -0,0 +1,169 @@ +// Copyright 2009 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 +// +// 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.devtools.build.lib.syntax; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.testutil.Suite; +import com.google.devtools.build.lib.testutil.TestSpec; + +import junit.framework.TestCase; + +/** + * Links for {@link GlobCriteria} + */ +@TestSpec(size = Suite.SMALL_TESTS) +public class GlobCriteriaTest extends TestCase { + + public void testParse_EmptyList() throws Exception { + GlobCriteria gc = GlobCriteria.parse("[]"); + assertFalse(gc.isGlob()); + assertTrue(gc.getIncludePatterns().isEmpty()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_SingleList() throws Exception { + GlobCriteria gc = GlobCriteria.parse("['abc']"); + assertFalse(gc.isGlob()); + assertEquals(ImmutableList.of("abc"), gc.getIncludePatterns()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_MultipleList() throws Exception { + GlobCriteria gc = GlobCriteria.parse("['abc', 'def', 'ghi']"); + assertFalse(gc.isGlob()); + assertEquals(ImmutableList.of("abc", "def", "ghi"), gc.getIncludePatterns()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_EmptyGlob() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob([])"); + assertTrue(gc.isGlob()); + assertTrue(gc.getIncludePatterns().isEmpty()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_SingleGlob() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob(['abc'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("abc"), gc.getIncludePatterns()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_MultipleGlob() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("abc", "def", "ghi"), gc.getIncludePatterns()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_EmptyGlobWithExclude() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob([], exclude=['xyz'])"); + assertTrue(gc.isGlob()); + assertTrue(gc.getIncludePatterns().isEmpty()); + assertEquals(ImmutableList.of("xyz"), gc.getExcludePatterns()); + } + + public void testParse_SingleGlobWithExclude() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob(['abc'], exclude=['xyz'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("abc"), gc.getIncludePatterns()); + assertEquals(ImmutableList.of("xyz"), gc.getExcludePatterns()); + } + + public void testParse_MultipleGlobWithExclude() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("abc", "def", "ghi"), gc.getIncludePatterns()); + assertEquals(ImmutableList.of("xyz"), gc.getExcludePatterns()); + } + + public void testParse_MultipleGlobWithMultipleExclude() throws Exception { + GlobCriteria gc = GlobCriteria.parse( + "glob(['abc', 'def', 'ghi'], exclude=['rst', 'uvw', 'xyz'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("abc", "def", "ghi"), gc.getIncludePatterns()); + assertEquals(ImmutableList.of("rst", "uvw", "xyz"), gc.getExcludePatterns()); + } + + public void testParse_GlobWithSlashesAndWildcards() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob(['java/src/net/jsunit/*.java'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("java/src/net/jsunit/*.java"), gc.getIncludePatterns()); + assertTrue(gc.getExcludePatterns().isEmpty()); + } + + public void testParse_ExcludeWithInvalidLabel() throws Exception { + GlobCriteria gc = GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz~'])"); + assertTrue(gc.isGlob()); + assertEquals(ImmutableList.of("abc", "def", "ghi"), gc.getIncludePatterns()); + assertEquals(ImmutableList.of("xyz~"), gc.getExcludePatterns()); + } + + public void testParse_InvalidFormat_TooManySpacesList() throws Exception { + try { + GlobCriteria.parse("glob(['abc, 'def', 'ghi'], exclude=['xyz~'])"); + fail(); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testParse_InvalidFormat_MissingQuote() throws Exception { + try { + GlobCriteria.parse("glob(['abc, 'def', 'ghi'], exclude=['xyz~'])"); + fail(); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testParse_InvalidFormat_TooManySpacesExclude() throws Exception { + try { + GlobCriteria.parse("glob(['abc', 'def', 'ghi'], exclude=['xyz~'])"); + fail(); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testParse_InvalidFormat_MissingQuoteExclude() throws Exception { + try { + GlobCriteria.parse("glob(['abc, 'def', 'ghi'], exclude=['xyz~])"); + fail(); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testParse_InvalidFormat_ExcludeWithList() throws Exception { + try { + GlobCriteria.parse("['abc, 'def', 'ghi'], exclude=['xyz~']"); + fail(); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testParse_veryLongString() throws Exception { + StringBuilder builder = new StringBuilder(); + builder.append("['File0.java'"); + for (int i = 1; i < 5000; ++i) { + builder.append(", 'File").append(i).append(".java'"); + } + builder.append("]"); + String s = builder.toString(); + GlobCriteria gc = GlobCriteria.parse(s); + assertEquals(s, gc.toString()); + } +} |