-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: empty catalog turns into jbanghub catalog to allow things like …
…h2@ and sqlline@/sqlline
- Loading branch information
1 parent
cdbf260
commit bf7232b
Showing
5 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package dev.jbang; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import dev.jbang.catalog.Alias; | ||
import dev.jbang.catalog.Catalog; | ||
import dev.jbang.catalog.ImplicitCatalogRef; | ||
|
||
/** | ||
|
@@ -19,24 +23,44 @@ public class TestImplicitAlias extends BaseTest { | |
@Test | ||
public void testGitImplicitCatalog() { | ||
assertThat(ImplicitCatalogRef.getImplicitCatalogUrl("jbangdev").get(), | ||
Matchers.equalTo("https://github.com/jbangdev/jbang-catalog/blob/HEAD/jbang-catalog.json")); | ||
equalTo("https://github.com/jbangdev/jbang-catalog/blob/HEAD/jbang-catalog.json")); | ||
assertThat(ImplicitCatalogRef.getImplicitCatalogUrl("jbangdev/jbang-examples").get(), | ||
Matchers.equalTo("https://github.com/jbangdev/jbang-examples/blob/HEAD/jbang-catalog.json")); | ||
equalTo("https://github.com/jbangdev/jbang-examples/blob/HEAD/jbang-catalog.json")); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { /* not sure this should be allowed "", */ "/", "/sqlline", "jbanghub/sqlline" }) | ||
public void testGitImplicitCatalogHub(String catalog) { | ||
String cref = ImplicitCatalogRef.getImplicitCatalogUrl(catalog).get(); | ||
assertThat(cref, | ||
startsWith("https://github.com/jbanghub/")); | ||
|
||
Catalog c = Catalog.getByName(catalog); | ||
assertThat(c.catalogRef.getOriginalResource(), | ||
startsWith("https://github.com/jbanghub/")); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "sqlline@", "sqlline@/", "sqlline@/sqlline", "sqlline@jbanghub/sqlline" }) | ||
public void testImplicitHub(String alias) { | ||
Alias a = Alias.get(alias); | ||
assertThat(a.scriptRef, containsString("sqlline:sqlline")); | ||
assertThat(a.catalog.baseRef, containsString("jbanghub")); | ||
} | ||
|
||
@Test | ||
public void testImplictURLAlias() { | ||
|
||
Alias url = Alias.get("[email protected]"); | ||
assertThat(url.scriptRef, Matchers.equalTo("tree/main.java")); | ||
assertThat(url.scriptRef, equalTo("tree/main.java")); | ||
|
||
} | ||
|
||
@Test | ||
public void testImplictExplicitURLAlias() { | ||
|
||
Alias url = Alias.get("tree@https://xam.dk"); | ||
assertThat(url.scriptRef, Matchers.equalTo("tree/main.java")); | ||
assertThat(url.scriptRef, equalTo("tree/main.java")); | ||
|
||
} | ||
|
||
|
@@ -56,7 +80,7 @@ public void testFileURLAlias() throws Exception { | |
|
||
Alias alias = Alias.get(url); | ||
|
||
assertThat(alias.scriptRef, Matchers.equalTo("helloworld.java")); | ||
assertThat(alias.scriptRef, equalTo("helloworld.java")); | ||
|
||
} | ||
} |