2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-01 21:20:06 -05:00
|
|
|
import { assertEquals } from "../../../test_util/std/assert/mod.ts";
|
2023-03-19 06:49:11 -04:00
|
|
|
import { parse, stringify } from "node:querystring";
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "stringify",
|
|
|
|
fn() {
|
|
|
|
assertEquals(
|
|
|
|
stringify({
|
|
|
|
a: "hello",
|
|
|
|
b: 5,
|
|
|
|
c: true,
|
|
|
|
d: ["foo", "bar"],
|
|
|
|
}),
|
|
|
|
"a=hello&b=5&c=true&d=foo&d=bar",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "parse",
|
|
|
|
fn() {
|
|
|
|
assertEquals(parse("a=hello&b=5&c=true&d=foo&d=bar"), {
|
|
|
|
a: "hello",
|
|
|
|
b: "5",
|
|
|
|
c: "true",
|
|
|
|
d: ["foo", "bar"],
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2024-01-01 23:54:11 -05:00
|
|
|
|
|
|
|
// https://github.com/denoland/deno/issues/21734
|
|
|
|
Deno.test({
|
|
|
|
name: "stringify options no encode",
|
|
|
|
fn() {
|
|
|
|
assertEquals(
|
|
|
|
stringify(
|
|
|
|
{
|
|
|
|
a: "hello",
|
|
|
|
b: 5,
|
|
|
|
c: true,
|
|
|
|
d: ["foo", "bar"],
|
|
|
|
},
|
|
|
|
"&",
|
|
|
|
"=",
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
"a=hello&b=5&c=true&d=foo&d=bar",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|