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";
|
2019-03-06 19:42:24 -05:00
|
|
|
import { assertEquals } 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 19:42:24 -05:00
|
|
|
assertEquals(lookup("json"), "application/json");
|
|
|
|
assertEquals(lookup(".md"), "text/markdown");
|
|
|
|
assertEquals(lookup("folder/file.js"), "application/javascript");
|
|
|
|
assertEquals(lookup("folder/.htaccess"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testContentType() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(contentType("markdown"), "text/markdown; charset=utf-8");
|
|
|
|
assertEquals(contentType("file.json"), "application/json; charset=utf-8");
|
|
|
|
assertEquals(contentType("text/html"), "text/html; charset=utf-8");
|
|
|
|
assertEquals(
|
2019-01-11 00:16:47 -05:00
|
|
|
contentType("text/html; charset=iso-8859-1"),
|
|
|
|
"text/html; charset=iso-8859-1"
|
|
|
|
);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(contentType(".htaccess"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testExtension() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(extension("application/octet-stream"), "bin");
|
|
|
|
assertEquals(extension("application/javascript"), "js");
|
|
|
|
assertEquals(extension("text/html"), "html");
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testCharset() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(charset("text/markdown"), "UTF-8");
|
|
|
|
assertEquals(charset("text/css"), "UTF-8");
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testExtensions() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(extensions.get("application/javascript"), ["js", "mjs"]);
|
|
|
|
assertEquals(extensions.get("foo"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function testTypes() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(types.get("js"), "application/javascript");
|
|
|
|
assertEquals(types.get("foo"), undefined);
|
2019-01-11 00:16:47 -05:00
|
|
|
});
|