Skip to content

Commit

Permalink
feat: add KytheURI#toCorpusPath() (#5592)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Apr 21, 2023
1 parent b69b49b commit eb169e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kythe/java/com/google/devtools/kythe/util/KytheURI.java
Expand Up @@ -118,6 +118,15 @@ public VName toVName() {
return vName;
}

/** Returns the {@link CorpusPath} components of the uri. */
public CorpusPath toCorpusPath() {
return CorpusPath.newBuilder()
.setCorpus(vName.getCorpus())
.setRoot(vName.getRoot())
.setPath(vName.getPath())
.build();
}

@Override
public String toString() {
StringBuilder b =
Expand Down
12 changes: 12 additions & 0 deletions kythe/javatests/com/google/devtools/kythe/util/KytheURITest.java
Expand Up @@ -170,6 +170,18 @@ public void testToVName() throws URISyntaxException {
assertThat(vname.getLanguage()).isEqualTo(lang);
}

public void testToCorpusPath() throws URISyntaxException {
String signature = "magic school truck";
String corpus = "crazyTown";
String path = "usa/2.0";
String root = null;
String lang = "c++";
CorpusPath cp = new KytheURI(signature, corpus, root, path, lang).toCorpusPath();
assertThat(cp.getCorpus()).isEqualTo(corpus);
assertThat(cp.getRoot()).isEmpty(); // Proto fields are never null
assertThat(cp.getPath()).isEqualTo(path);
}

public void testParseErrors() {
String[] tests =
new String[] {
Expand Down

0 comments on commit eb169e6

Please sign in to comment.