2019-01-11 00:16:47 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2019-03-06 16:39:50 -05:00
|
|
|
import { test } from "../testing/mod.ts";
|
|
|
|
import { assertEq } from "../testing/asserts.ts";
|
2019-01-11 00:16:47 -05:00
|
|
|
import {
|
|
|
|
lookup,
|
|
|
|
contentType,
|
|
|
|
extension,
|
|
|
|
charset,
|
|
|
|
extensions,
|
|
|
|
types
|
|
|
|
} from "./mod.ts";
|
|
|
|
|
|
|
|
test(function testLookup() {
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(lookup("json"), "application/json");
|
|
|
|
assertEq(lookup(".md"), "text/markdown");
|
|
|
|
assertEq(lookup("folder/file.js"), "application/javascript");
|
|
|
|
assertEq(lookup("folder/.htaccess"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testContentType() {
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(contentType("markdown"), "text/markdown; charset=utf-8");
|
|
|
|
assertEq(contentType("file.json"), "application/json; charset=utf-8");
|
|
|
|
assertEq(contentType("text/html"), "text/html; charset=utf-8");
|
|
|
|
assertEq(
|
2019-01-11 00:16:47 -05:00
|
|
|
contentType("text/html; charset=iso-8859-1"),
|
|
|
|
"text/html; charset=iso-8859-1"
|
|
|
|
);
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(contentType(".htaccess"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testExtension() {
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(extension("application/octet-stream"), "bin");
|
|
|
|
assertEq(extension("application/javascript"), "js");
|
|
|
|
assertEq(extension("text/html"), "html");
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testCharset() {
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(charset("text/markdown"), "UTF-8");
|
|
|
|
assertEq(charset("text/css"), "UTF-8");
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testExtensions() {
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(extensions.get("application/javascript"), ["js", "mjs"]);
|
|
|
|
assertEq(extensions.get("foo"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testTypes() {
|
2019-03-06 16:39:50 -05:00
|
|
|
assertEq(types.get("js"), "application/javascript");
|
|
|
|
assertEq(types.get("foo"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|