Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmolot committed Jun 17, 2024
1 parent 598a2b6 commit 9ce9b03
Show file tree
Hide file tree
Showing 5 changed files with 9,884 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua/tests/gm_url/tests.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This is a dummy lua file
66 changes: 66 additions & 0 deletions lua/tests/gm_url/tests.yue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import URL, decodeURIComponent from include "url.yue"
urltestdata = include "urltestdata.lua"

-- First let's decode the test data
for test in *urltestdata
if istable(test)
for key, value in pairs test
if isstring value
test[key] = decodeURIComponent(value)

cases = {}
for test in *urltestdata
if isstring(test)
cases[] = { name: test, func: -> }
continue

prefix = (test.base and test.base != "about:blank") and "(#{test.base}) " or ""
name = "#{prefix}#{test.input} -> #{not test.failure and test.href or "failure"}"
func = ->
ok, url = pcall(URL, test.input, --[[test.base != "about:blank" and]] test.base)
if test.failure
if ok
print "expected failure but got: #{url.href}"
-- return -- fix later
expect(ok).to.beFalse()
return

if not ok
print "failed to parse: #{url}"
expect(ok).to.beTrue()

expect(url.protocol).to.eq(test.protocol)

if test.password != ""
expect(url.password).to.eq(test.password)

if test.username != ""
expect(url.username).to.eq(test.username)

if test.hostname != ""
expect(url.hostname).to.eq(test.hostname)

port = tonumber test.port
if port
expect(url.port).to.eq(port)

expect(url.host).to.eq(test.host)
if test.origin and test.origin != "null"
expect(url.origin).to.eq(test.origin)

if test.pathname != ""
expect(url.pathname).to.eq(test.pathname)
-- expect(url.search).to.eq(test.search)
-- expect(url.hash).to.eq(test.hash)
-- expect(url.href).to.eq(test.href)


return


cases[] = { :name, :func }

return {
:cases,
groupName: "gm_url whatwg-url tests"
}
1 change: 1 addition & 0 deletions lua/tests/gm_url/url.yue
Loading

0 comments on commit 9ce9b03

Please sign in to comment.