-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable jbang [email protected] and jbang tree@https:/jbang.dev
- Loading branch information
1 parent
238ef90
commit cb4c50c
Showing
3 changed files
with
83 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dev.jbang; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import dev.jbang.catalog.Alias; | ||
import dev.jbang.catalog.ImplicitCatalogRef; | ||
|
||
/** | ||
* TODO: use mock to handle https lookups instead of jbang.dev | ||
*/ | ||
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")); | ||
assertThat(ImplicitCatalogRef.getImplicitCatalogUrl("jbangdev/jbang-examples").get(), | ||
Matchers.equalTo("https://github.com/jbangdev/jbang-examples/blob/HEAD/jbang-catalog.json")); | ||
} | ||
|
||
@Test | ||
public void testImplictURLAlias() { | ||
|
||
Alias url = Alias.get("[email protected]"); | ||
assertThat(url.scriptRef, Matchers.equalTo("tree/main.java")); | ||
|
||
} | ||
|
||
@Test | ||
public void testImplictExplicitURLAlias() { | ||
|
||
Alias url = Alias.get("tree@https://xam.dk"); | ||
assertThat(url.scriptRef, Matchers.equalTo("tree/main.java")); | ||
|
||
} | ||
|
||
// @Test needs fixing to not generate absolute paths but instead relative paths. | ||
public void testFileURLAlias() throws IOException { | ||
|
||
assertThat(jbangTempDir.resolve("inner").toFile().mkdirs(), Matchers.is(true)); | ||
|
||
Files.copy(examplesTestFolder.resolve("helloworld.java"), jbangTempDir.resolve("inner/helloworld.java")); | ||
String src = jbangTempDir.resolve("inner/helloworld.java").toString(); | ||
Path path = jbangTempDir.resolve("jbang-catalog.json"); | ||
|
||
checkedRun(null, "alias", "add", "-f", path.toString(), "--name=apptest", src); | ||
|
||
String url = "apptest@" + path.toUri(); | ||
assertThat(url, Matchers.stringContainsInOrder("file://")); | ||
|
||
Alias alias = Alias.get(url); | ||
|
||
assertThat(alias.scriptRef, Matchers.equalTo("helloworld.java")); | ||
|
||
} | ||
} |