diff options
| author | Vincent LE GOFF <g_n_s@hotmail.fr> | 2019-05-01 18:13:23 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-05-01 12:13:23 -0400 |
| commit | 80161217d38acd76cd09f40e40986cc4a90e14ac (patch) | |
| tree | 91608ff77abec36e743de8825f3273dfc1759d31 /textproto/test.ts | |
| parent | adf9cf9949bff27ab1332957078cf4436aebea85 (diff) | |
textproto: fix invalid header error and move tests (denoland/deno_std#369)
Original: https://github.com/denoland/deno_std/commit/b6aaddbcc060287e8c349a875a19df8fcd0620f3
Diffstat (limited to 'textproto/test.ts')
| -rw-r--r-- | textproto/test.ts | 87 |
1 files changed, 3 insertions, 84 deletions
diff --git a/textproto/test.ts b/textproto/test.ts index 5218d20f4..71caddef9 100644 --- a/textproto/test.ts +++ b/textproto/test.ts @@ -3,84 +3,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -import { BufReader } from "../io/bufio.ts"; -import { TextProtoReader, append } from "./mod.ts"; -import { stringsReader } from "../io/util.ts"; -import { assert, assertEquals } from "../testing/asserts.ts"; +import { append } from "./mod.ts"; +import { assertEquals } from "../testing/asserts.ts"; import { test } from "../testing/mod.ts"; - -function reader(s: string): TextProtoReader { - return new TextProtoReader(new BufReader(stringsReader(s))); -} - -test(async function textprotoReader(): Promise<void> { - let r = reader("line1\nline2\n"); - let [s, err] = await r.readLine(); - assertEquals(s, "line1"); - assert(err == null); - - [s, err] = await r.readLine(); - assertEquals(s, "line2"); - assert(err == null); - - [s, err] = await r.readLine(); - assertEquals(s, ""); - assert(err == "EOF"); -}); - -/* -test(async function textprotoReadMIMEHeader() { - let r = reader("my-key: Value 1 \r\nLong-key: Even \n Longer Value\r\nmy-Key: Value 2\r\n\n"); - let [m, err] = await r.readMIMEHeader(); - - console.log("Got headers", m.toString()); - want := MIMEHeader{ - "My-Key": {"Value 1", "Value 2"}, - "Long-Key": {"Even Longer Value"}, - } - if !reflect.DeepEqual(m, want) || err != nil { - t.Fatalf("ReadMIMEHeader: %v, %v; want %v", m, err, want) - } -}); -*/ - -test(async function textprotoReadMIMEHeaderSingle(): Promise<void> { - let r = reader("Foo: bar\n\n"); - let [m, err] = await r.readMIMEHeader(); - assertEquals(m.get("Foo"), "bar"); - assert(!err); -}); - -// Test that we read slightly-bogus MIME headers seen in the wild, -// with spaces before colons, and spaces in keys. -test(async function textprotoReadMIMEHeaderNonCompliant(): Promise<void> { - // Invalid HTTP response header as sent by an Axis security - // camera: (this is handled by IE, Firefox, Chrome, curl, etc.) - let r = reader( - "Foo: bar\r\n" + - "Content-Language: en\r\n" + - "SID : 0\r\n" + - // TODO Re-enable Currently fails with: - // "TypeError: audio mode is not a legal HTTP header name" - // "Audio Mode : None\r\n" + - "Privilege : 127\r\n\r\n" - ); - let [m, err] = await r.readMIMEHeader(); - console.log(m.toString()); - assert(!err); - /* - let want = MIMEHeader{ - "Foo": {"bar"}, - "Content-Language": {"en"}, - "Sid": {"0"}, - "Audio Mode": {"None"}, - "Privilege": {"127"}, - } - if !reflect.DeepEqual(m, want) || err != nil { - t.Fatalf("ReadMIMEHeader =\n%v, %v; want:\n%v", m, err, want) - } - */ -}); +import "./reader_test.ts"; test(async function textprotoAppend(): Promise<void> { const enc = new TextEncoder(); @@ -90,10 +16,3 @@ test(async function textprotoAppend(): Promise<void> { const joined = append(u1, u2); assertEquals(dec.decode(joined), "Hello World"); }); - -test(async function textprotoReadEmpty(): Promise<void> { - let r = reader(""); - let [, err] = await r.readMIMEHeader(); - // Should not crash! - assertEquals(err, "EOF"); -}); |
