aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Paul Roberts <pwroberts@google.com>2016-10-18 02:04:25 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-10-18 10:57:41 +0000
commit8c443ef37880c2dd5f674751ee8453c4e37ff8a0 (patch)
treed41f1afcce3c9d8fb67beebc18ef773e8c483515 /src/test/java/com
parente3bf9869e8d6efaedeea8f63d2bbf766cfc387d3 (diff)
Add file extension property to Skylark
RELNOTES[NEW]: Files now have an "extension" property in Skylark. -- MOS_MIGRATED_REVID=136425934
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java15
-rw-r--r--src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java14
2 files changed, 24 insertions, 5 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java
index e43ddd1b28..81b64b2b40 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java
@@ -33,16 +33,14 @@ import com.google.devtools.build.lib.rules.java.JavaSemantics;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
-
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
@RunWith(JUnit4.class)
public class ArtifactTest {
private Scratch scratch;
@@ -149,6 +147,13 @@ public class ArtifactTest {
}
@Test
+ public void testGetExtension() throws Exception {
+ Root root = Root.asSourceRoot(scratch.dir("/foo"));
+ Artifact javaFile = new Artifact(scratch.file("/foo/Bar.java"), root);
+ assertThat(javaFile.getExtension()).isEqualTo("java");
+ }
+
+ @Test
public void testMangledPath() {
String path = "dir/sub_dir/name:end";
assertEquals("dir_Ssub_Udir_Sname_Cend", Actions.escapedPath(path));
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java
index 71b7decf9e..c4ac7c1b32 100644
--- a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java
+++ b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentTest.java
@@ -280,6 +280,20 @@ public class PathFragmentTest {
assertThat(new PathFragment("").getBaseName()).isEmpty();
}
+ @Test
+ public void testFileExtension() throws Exception {
+ assertThat(new PathFragment("foo.bar").getFileExtension()).isEqualTo("bar");
+ assertThat(new PathFragment("foo.barr").getFileExtension()).isEqualTo("barr");
+ assertThat(new PathFragment("foo.b").getFileExtension()).isEqualTo("b");
+ assertThat(new PathFragment("foo.").getFileExtension()).isEmpty();
+ assertThat(new PathFragment("foo").getFileExtension()).isEmpty();
+ assertThat(new PathFragment(".").getFileExtension()).isEmpty();
+ assertThat(new PathFragment("").getFileExtension()).isEmpty();
+ assertThat(new PathFragment("foo/bar.baz").getFileExtension()).isEqualTo("baz");
+ assertThat(new PathFragment("foo.bar.baz").getFileExtension()).isEqualTo("baz");
+ assertThat(new PathFragment("foo.bar/baz").getFileExtension()).isEmpty();
+ }
+
private static void assertPath(String expected, PathFragment actual) {
assertEquals(expected, actual.getPathString());
}