Extremely Popular
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201// Copyright 2018-2019 the oak authors. All rights reserved. MIT license.
import { test, assertEquals } from "./test_deps.ts";import { preferredMediaTypes } from "./mediaType.ts";
test(function testAcceptUndefined() { assertEquals(preferredMediaTypes(), ["*/*"]);});
test(function testAcceptStarStar() { assertEquals(preferredMediaTypes("*/*"), ["*/*"]);});
test(function testAcceptMediaType() { assertEquals(preferredMediaTypes("application/json"), ["application/json"]);});
test(function testAcceptMediaTypeQ0() { assertEquals(preferredMediaTypes("application/json;q=0"), []);});
test(function testAcceptMediaTypeLowQ() { assertEquals(preferredMediaTypes("application/json;q=0.2, text/html"), [ "text/html", "application/json" ]);});
test(function testAcceptTextStar() { assertEquals(preferredMediaTypes("text/*"), ["text/*"]);});
test(function testAcceptComplexQ() { assertEquals( preferredMediaTypes( "text/plain, application/json;q=0.5, text/html, */*;q=0.1" ), ["text/plain", "text/html", "application/json", "*/*"] );});
test(function testAcceptSuperLong() { assertEquals( preferredMediaTypes( "text/plain, application/json;q=0.5, text/html, text/xml, text/yaml, text/javascript, text/csv, text/css, text/rtf, text/markdown, application/octet-stream;q=0.2, */*;q=0.1" ), [ "text/plain", "text/html", "text/xml", "text/yaml", "text/javascript", "text/csv", "text/css", "text/rtf", "text/markdown", "application/json", "application/octet-stream", "*/*" ] );});
test(function testProvidedAcceptUndefined() { assertEquals(preferredMediaTypes(undefined, ["text/html"]), ["text/html"]); assertEquals( preferredMediaTypes(undefined, ["text/html", "application/json"]), ["text/html", "application/json"] ); assertEquals( preferredMediaTypes(undefined, ["application/json", "text/html"]), ["application/json", "text/html"] );});
test(function testProvidedAcceptStarStar() { assertEquals(preferredMediaTypes("*/*", ["text/html"]), ["text/html"]); assertEquals(preferredMediaTypes("*/*", ["text/html", "application/json"]), [ "text/html", "application/json" ]); assertEquals(preferredMediaTypes("*/*", ["application/json", "text/html"]), [ "application/json", "text/html" ]);});
test(function testCaseInsensitive() { assertEquals(preferredMediaTypes("application/json", ["application/JSON"]), [ "application/JSON" ]);});
test(function testOnlyReturnsValue() { assertEquals(preferredMediaTypes("application/json", ["text/html"]), []); assertEquals( preferredMediaTypes("application/json", ["text/html", "application/json"]), ["application/json"] );});
test(function testProvidedButQ0() { assertEquals( preferredMediaTypes("application/json;q=0", ["application/json"]), [] );});
test(function testProvidedAcceptsLowQ() { assertEquals( preferredMediaTypes("application/json;q=0.2, text/html", [ "application/json" ]), ["application/json"] ); assertEquals( preferredMediaTypes("application/json;q=0.2, text/html", [ "application/json", "text/html" ]), ["text/html", "application/json"] ); assertEquals( preferredMediaTypes("application/json;q=0.2, text/html", [ "text/html", "application/json" ]), ["text/html", "application/json"] );});
test(function testTextStar() { assertEquals(preferredMediaTypes("text/*", ["application/json"]), []); assertEquals( preferredMediaTypes("text/*", ["application/json", "text/html"]), ["text/html"] ); assertEquals( preferredMediaTypes("text/*", ["text/html", "application/json"]), ["text/html"] );});
test(function testProvidedPreferredOrder() { assertEquals( preferredMediaTypes( "text/plain, application/json;q=0.5, text/html, */*;q=0.1", ["application/json", "text/plain", "text/html"] ), ["text/plain", "text/html", "application/json"] ); assertEquals( preferredMediaTypes( "text/plain, application/json;q=0.5, text/html, */*;q=0.1", ["image/jpeg", "text/html"] ), ["text/html", "image/jpeg"] ); assertEquals( preferredMediaTypes( "text/plain, application/json;q=0.5, text/html, */*;q=0.1", ["image/jpeg", "image/gif"] ), ["image/jpeg", "image/gif"] );});
test(function testClientPreferredOrder() { assertEquals( preferredMediaTypes( "text/plain, application/json;q=0.5, text/html, text/xml, text/yaml, text/javascript, text/csv, text/css, text/rtf, text/markdown, application/octet-stream;q=0.2, */*;q=0.1", [ "text/plain", "text/html", "text/xml", "text/yaml", "text/javascript", "text/csv", "text/css", "text/rtf", "text/markdown", "application/json", "application/octet-stream" ] ), [ "text/plain", "text/html", "text/xml", "text/yaml", "text/javascript", "text/csv", "text/css", "text/rtf", "text/markdown", "application/json", "application/octet-stream" ] );});