deno.land / std@0.224.0 / media_types / _util_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { consumeMediaParam, consumeToken, consumeValue, decode2331Encoding, isIterator, isToken, isTSpecial,} from "./_util.ts";
Deno.test({ name: "consumeToken()", fn() { const fixtures = [ ["foo bar", "foo", " bar"], ["bar", "bar", ""], ["", "", ""], [" foo", "", " foo"], ] as const; for (const [fixture, token, rest] of fixtures) { assertEquals(consumeToken(fixture), [token, rest]); } },});
Deno.test({ name: "consumeValue()", fn() { const fixtures = [ ["", "", ""], [`"\n"foo`, "", `"\n"foo`], [`"\r"foo`, "", `"\r"foo`], [`"\\\\;"`, "\\;", ""], ["foo bar", "foo", " bar"], ["bar", "bar", ""], [" bar ", "", " bar "], [`"My value"end`, "My value", "end"], [`"My value" end`, "My value", " end"], [`"\\\\" rest`, "\\", " rest"], [`"My \\" value"end`, 'My " value', "end"], [`"\\" rest`, "", `"\\" rest`], [`"C:\\dev\\go\\robots.txt"`, `C:\\dev\\go\\robots.txt`, ""], [ `"C:\\新建文件夹\\中文第二次测试.mp4"`, `C:\\新建文件夹\\中文第二次测试.mp4`, "", ], ] as const; for (const [fixture, value, rest] of fixtures) { assertEquals(consumeValue(fixture), [value, rest]); } },});
Deno.test({ name: "consumeMediaParam()", fn() { const fixtures = [ ["", "", "", ""], ["foo=bar", "", "", "foo=bar"], [";", "", "", ";"], [";foo", "", "", ";foo"], [" ; foo=bar", "foo", "bar", ""], ["; foo=bar", "foo", "bar", ""], [";foo=bar", "foo", "bar", ""], [";FOO=bar", "foo", "bar", ""], [`;foo="bar"`, "foo", "bar", ""], [`;foo="bar"; `, "foo", "bar", "; "], [`;foo="bar"; foo=baz`, "foo", "bar", "; foo=baz"], [` ; boundary=----CUT;`, "boundary", "----CUT", ";"], [ ` ; key=value; blah="value";name="foo" `, "key", "value", `; blah="value";name="foo" `, ], [`; blah="value";name="foo" `, "blah", "value", `;name="foo" `], [`;name="foo" `, "name", "foo", ` `], ] as const; for (const [fixture, key, value, rest] of fixtures) { assertEquals(consumeMediaParam(fixture), [key, value, rest]); } },});
Deno.test({ name: "decode2331Encoding()", fn() { const fixtures = [ ["", undefined], ["foo", undefined], [`foo'bar'baz`, undefined], [`us-ascii'en-us'`, undefined], [`us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A`, "This is ***fun***"], [`UTF-8''foo-a%cc%88.html`, "foo-ä.html"], ] as const; for (const [fixture, expected] of fixtures) { assertEquals(decode2331Encoding(fixture), expected); } },});
Deno.test({ name: "isIterator()", fn() { const fixtures = [ [null, false], [undefined, false], [{}, false], ["", true], [[], true], [Object.entries({}), true], ] as const; for (const [fixture, expected] of fixtures) { assertEquals(isIterator(fixture), expected); } },});
Deno.test({ name: "isToken()", fn() { const fixtures = [ ["", false], [";", false], ["\\", false], ["foo", true], ] as const; for (const [fixture, expected] of fixtures) { assertEquals(isToken(fixture), expected); } },});
Deno.test({ name: "isTSpecial()", fn() { const fixtues = [ ["", false], [` ()<>@,;:\\"/[]?=`, false], ["(", true], [")", true], ["<", true], [">", true], ["@", true], [",", true], [";", true], [":", true], ["\\", true], ['"', true], ["/", true], ["[", true], ["]", true], ["?", true], ["=", true], [" ", false], ["\t", false], ["\n", false], ["\r", false], ["\f", false], ["\v", false], ["foo", false], ] as const; for (const [fixture, expected] of fixtues) { assertEquals(isTSpecial(fixture), expected); } },});
Version Info