forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_test.go
87 lines (80 loc) · 2.41 KB
/
os_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2018 Ryan Dahl <[email protected]>
// All rights reserved. MIT License.
package deno
import (
"path"
"testing"
)
func AssertEqual(t *testing.T, actual string, expected string) {
if actual != expected {
t.Fatalf("not equal <<%s>> <<%s>>", actual, expected)
}
}
func TestResolveModule1(t *testing.T) {
createDirs()
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"))
}
func TestResolveModule2(t *testing.T) {
createDirs()
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")
}
func TestResolveModule3(t *testing.T) {
createDirs()
// 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")
}
func TestResolveModule4(t *testing.T) {
createDirs()
// Files in SrcDir should resolve to URLs.
moduleName, filename, err := ResolveModule(
path.Join(SrcDir, "unpkg.com/[email protected]/index.ts"),
".")
if err != nil {
t.Fatalf(err.Error())
}
AssertEqual(t, moduleName,
"http://unpkg.com/[email protected]/index.ts")
AssertEqual(t, filename,
path.Join(SrcDir, "unpkg.com/[email protected]/index.ts"))
}
func TestResolveModuleExtensionsAintSpecial(t *testing.T) {
createDirs()
moduleName, filename, err := ResolveModule(
"./util",
path.Join(SrcDir, "unpkg.com/[email protected]/index.ts"))
if err != nil {
t.Fatalf(err.Error())
}
AssertEqual(t, moduleName,
"http://unpkg.com/[email protected]/util")
AssertEqual(t, filename,
path.Join(SrcDir, "unpkg.com/[email protected]/util"))
}