-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for JS::RequireRemote::URLResolver
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
packages/npm-packages/ruby-wasm-wasi/test/unit/require_remote/url_resolver.rb
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,66 @@ | ||
require "test-unit" | ||
require "js" | ||
require "js/require_remote" | ||
|
||
class TestURLResolver < Test::Unit::TestCase | ||
def test_get_location | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com") | ||
script_location = url_resolver.get_location("foo.rb") | ||
assert_equal "https://example.com/foo.rb", script_location.url.to_s | ||
assert_equal "foo.rb", script_location.filename | ||
end | ||
|
||
def test_get_location_with_relative_path | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com") | ||
script_location = url_resolver.get_location("./foo.rb") | ||
assert_equal "https://example.com/foo.rb", script_location.url.to_s | ||
assert_equal "./foo.rb", script_location.filename | ||
end | ||
|
||
def test_get_location_with_relative_path_and_filename | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com/bar.rb") | ||
script_location = url_resolver.get_location("./foo.rb") | ||
assert_equal "https://example.com/foo.rb", script_location.url.to_s | ||
assert_equal "./foo.rb", script_location.filename | ||
end | ||
|
||
def test_get_location_with_relative_path_and_filename_without_extension | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com/bar") | ||
script_location = url_resolver.get_location("./foo") | ||
assert_equal "https://example.com/foo.rb", script_location.url.to_s | ||
assert_equal "./foo.rb", script_location.filename | ||
end | ||
|
||
def test_get_location_with_relative_path_and_directory | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com/bar/") | ||
script_location = url_resolver.get_location("./foo.rb") | ||
assert_equal "https://example.com/bar/foo.rb", script_location.url.to_s | ||
assert_equal "./foo.rb", script_location.filename | ||
end | ||
|
||
def test_get_location_with_backward_relative_path | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com/bar/") | ||
script_location = url_resolver.get_location("../foo.rb") | ||
assert_equal "https://example.com/foo.rb", script_location.url.to_s | ||
assert_equal "../foo.rb", script_location.filename | ||
end | ||
|
||
def test_get_location_with_backward_relative_path_and_filename | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com/baz.rb") | ||
script_location = url_resolver.get_location("../foo.rb") | ||
assert_equal "https://example.com/foo.rb", script_location.url.to_s | ||
assert_equal "../foo.rb", script_location.filename | ||
end | ||
|
||
def test_push_and_pop | ||
url_resolver = JS::RequireRemote::URLResolver.new("https://example.com") | ||
url_resolver.push("https://example.com/foo/bar.rb") | ||
script_location = url_resolver.get_location("./baz.rb") | ||
assert_equal "https://example.com/foo/baz.rb", script_location.url.to_s | ||
assert_equal "./baz.rb", script_location.filename | ||
url_resolver.pop | ||
script_location = url_resolver.get_location("./baz.rb") | ||
assert_equal "https://example.com/baz.rb", script_location.url.to_s | ||
assert_equal "./baz.rb", script_location.filename | ||
end | ||
end |