diff --git a/ext/url/Cargo.toml b/ext/url/Cargo.toml new file mode 100644 index 0000000..3ba1a1e --- /dev/null +++ b/ext/url/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "bueno_ext_url" +description = "Bueno URL API extension" +edition.workspace = true +version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true + +[lib] +path = "lib.rs" + +[dependencies] +deno_core.workspace = true +tokio.workspace = true +url = { version = "2" } diff --git a/ext/url/lib.rs b/ext/url/lib.rs new file mode 100644 index 0000000..6749c23 --- /dev/null +++ b/ext/url/lib.rs @@ -0,0 +1,4 @@ +use deno_core::{error::AnyError, op2, OpState}; +use url::Url; + +// #[op2] diff --git a/ext/url/mod.js b/ext/url/mod.js new file mode 100644 index 0000000..e69de29 diff --git a/ext/url/url.js b/ext/url/url.js new file mode 100644 index 0000000..9828b4b --- /dev/null +++ b/ext/url/url.js @@ -0,0 +1,4 @@ +class URL { + static canParse(url, base) { + } +} diff --git a/tests/url.test.js b/tests/url.test.js new file mode 100644 index 0000000..d02ea00 --- /dev/null +++ b/tests/url.test.js @@ -0,0 +1,51 @@ +// Ported from WPT +const { test } = Bueno.testing; + +// https://github.com/web-platform-tests/wpt/blob/master/url/url-tojson.any.js +test((ctx) => { + const a = new URL("https://example.com/"); + ctx.equals(JSON.stringify(a), '"https://example.com/"'); +}); + +// https://github.com/web-platform-tests/wpt/blob/master/url/url-statics-canparse.any.js +[ + { + url: undefined, + base: undefined, + expected: false, + }, + { + url: "a:b", + base: undefined, + expected: true, + }, + { + url: undefined, + base: "a:b", + expected: false, + }, + { + url: "a:/b", + base: undefined, + expected: true, + }, + { + url: undefined, + base: "a:/b", + expected: true, + }, + { + url: "https://test:test", + base: undefined, + expected: false, + }, + { + url: "a", + base: "https://b/", + expected: true, + }, +].forEach(({ url, base, expected }) => { + test((ctx) => { + ctx.equals(URL.canParse(url, base), expected); + }, `URL.canParse(${url}, ${base})`); +});