summaryrefslogtreecommitdiff
path: root/modules_test.go
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-05-19 05:38:51 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-05-19 05:39:27 -0400
commit83f436e175643da6d75e1de3fe905b586012bac2 (patch)
treef250b9fdaca68941863caad5c778bccdf45099ca /modules_test.go
parentaeb85efdad3dd705894386aa9aef5e22db1541b8 (diff)
Command line flags
Diffstat (limited to 'modules_test.go')
-rw-r--r--modules_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules_test.go b/modules_test.go
new file mode 100644
index 000000000..ac94b5a3c
--- /dev/null
+++ b/modules_test.go
@@ -0,0 +1,49 @@
+package main
+
+import (
+ "path"
+ "testing"
+)
+
+func AssertEqual(t *testing.T, actual string, expected string) {
+ if actual != expected {
+ t.Fatalf("not equal <<%s>> <<%s>>", actual, expected)
+ }
+}
+
+func TestResolveModule(t *testing.T) {
+ moduleName, filename, err := ResolveModule(
+ "http://localhost:4545/testdata/subdir/print_hello.ts",
+ "/Users/rld/go/src/github.com/ry/deno/testdata/006_url_imports.ts")
+ if err != nil {
+ t.Fatalf(err.Error())
+ }
+ AssertEqual(t, moduleName,
+ "http://localhost:4545/testdata/subdir/print_hello.ts")
+ AssertEqual(t, filename,
+ path.Join(SrcDir, "localhost:4545/testdata/subdir/print_hello.ts"))
+
+ moduleName, filename, err = ResolveModule(
+ "./subdir/print_hello.ts",
+ "/Users/rld/go/src/github.com/ry/deno/testdata/006_url_imports.ts")
+ if err != nil {
+ t.Fatalf(err.Error())
+ }
+ AssertEqual(t, moduleName,
+ "/Users/rld/go/src/github.com/ry/deno/testdata/subdir/print_hello.ts")
+ AssertEqual(t, filename,
+ "/Users/rld/go/src/github.com/ry/deno/testdata/subdir/print_hello.ts")
+
+ // In the case where the containingFile is a directory (indicated with a
+ // trailing slash)
+ moduleName, filename, err = ResolveModule(
+ "testdata/001_hello.js",
+ "/Users/rld/go/src/github.com/ry/deno/")
+ if err != nil {
+ t.Fatalf(err.Error())
+ }
+ AssertEqual(t, moduleName,
+ "/Users/rld/go/src/github.com/ry/deno/testdata/001_hello.js")
+ AssertEqual(t, filename,
+ "/Users/rld/go/src/github.com/ry/deno/testdata/001_hello.js")
+}