mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
f5e46c9bf2
This looks like a massive PR, but it's only a move from cli/tests -> tests, and updates of relative paths for files. This is the first step towards aggregate all of the integration test files under tests/, which will lead to a set of integration tests that can run without the CLI binary being built. While we could leave these tests under `cli`, it would require us to keep a more complex directory structure for the various test runners. In addition, we have a lot of complexity to ignore various test files in the `cli` project itself (cargo publish exclusion rules, autotests = false, etc). And finally, the `tests/` folder will eventually house the `test_ffi`, `test_napi` and other testing code, reducing the size of the root repo directory. For easier review, the extremely large and noisy "move" is in the first commit (with no changes -- just a move), while the remainder of the changes to actual files is in the second commit.
167 lines
5.2 KiB
TypeScript
167 lines
5.2 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||
import { assertEquals } from "@test_util/std/assert/mod.ts";
|
||
import { Buffer } from "node:buffer";
|
||
import { StringDecoder } from "node:string_decoder";
|
||
|
||
Deno.test({
|
||
name: "String decoder is encoding utf8 correctly",
|
||
fn() {
|
||
let decoder;
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
assertEquals(decoder.write(Buffer.from("E1", "hex")), "");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
assertEquals(decoder.write(Buffer.from("E18B", "hex")), "");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
assertEquals(decoder.write(Buffer.from("\ufffd")), "\ufffd");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
assertEquals(
|
||
decoder.write(Buffer.from("\ufffd\ufffd\ufffd")),
|
||
"\ufffd\ufffd\ufffd",
|
||
);
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
assertEquals(decoder.write(Buffer.from("EFBFBDE2", "hex")), "\ufffd");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
assertEquals(decoder.write(Buffer.from("F1", "hex")), "");
|
||
assertEquals(decoder.write(Buffer.from("41F2", "hex")), "\ufffdA");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
},
|
||
});
|
||
|
||
Deno.test({
|
||
name: "String decoder is encoding base64 correctly",
|
||
fn() {
|
||
let decoder;
|
||
|
||
decoder = new StringDecoder("base64");
|
||
assertEquals(decoder.write(Buffer.from("E1", "hex")), "");
|
||
assertEquals(decoder.end(), "4Q==");
|
||
|
||
decoder = new StringDecoder("base64");
|
||
assertEquals(decoder.write(Buffer.from("E18B", "hex")), "");
|
||
assertEquals(decoder.end(), "4Ys=");
|
||
|
||
decoder = new StringDecoder("base64");
|
||
assertEquals(decoder.write(Buffer.from("\ufffd")), "77+9");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("base64");
|
||
assertEquals(
|
||
decoder.write(Buffer.from("\ufffd\ufffd\ufffd")),
|
||
"77+977+977+9",
|
||
);
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("base64");
|
||
assertEquals(decoder.write(Buffer.from("EFBFBDE2", "hex")), "77+9");
|
||
assertEquals(decoder.end(), "4g==");
|
||
|
||
decoder = new StringDecoder("base64");
|
||
assertEquals(decoder.write(Buffer.from("F1", "hex")), "");
|
||
assertEquals(decoder.write(Buffer.from("41F2", "hex")), "8UHy");
|
||
assertEquals(decoder.end(), "");
|
||
},
|
||
});
|
||
|
||
Deno.test({
|
||
name: "String decoder is encoding hex correctly",
|
||
fn() {
|
||
let decoder;
|
||
|
||
decoder = new StringDecoder("hex");
|
||
assertEquals(decoder.write(Buffer.from("E1", "hex")), "e1");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("hex");
|
||
assertEquals(decoder.write(Buffer.from("E18B", "hex")), "e18b");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("hex");
|
||
assertEquals(decoder.write(Buffer.from("\ufffd")), "efbfbd");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("hex");
|
||
assertEquals(
|
||
decoder.write(Buffer.from("\ufffd\ufffd\ufffd")),
|
||
"efbfbdefbfbdefbfbd",
|
||
);
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("hex");
|
||
assertEquals(decoder.write(Buffer.from("EFBFBDE2", "hex")), "efbfbde2");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder("hex");
|
||
assertEquals(decoder.write(Buffer.from("F1", "hex")), "f1");
|
||
assertEquals(decoder.write(Buffer.from("41F2", "hex")), "41f2");
|
||
assertEquals(decoder.end(), "");
|
||
},
|
||
});
|
||
|
||
Deno.test({
|
||
name:
|
||
"String decoder with utf8 would handle incomplete character correctly when append",
|
||
fn() {
|
||
let decoder;
|
||
const specialCharactersText = "不完全な文字のテスト";
|
||
const encodedBuffer = Buffer.from(specialCharactersText);
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
let str = "";
|
||
str += decoder.write(encodedBuffer.slice(0, 4));
|
||
assertEquals(str, "不");
|
||
str += decoder.write(encodedBuffer.slice(4));
|
||
assertEquals(str, "不完全な文字のテスト");
|
||
|
||
decoder = new StringDecoder("utf8");
|
||
str = "";
|
||
str += decoder.write(encodedBuffer.slice(0, 4));
|
||
str += decoder.write(encodedBuffer.slice(5));
|
||
assertEquals(str, "不<>全な文字のテスト");
|
||
},
|
||
});
|
||
|
||
Deno.test({
|
||
name: "String decoder would have default encoding option as utf8",
|
||
fn() {
|
||
let decoder;
|
||
|
||
decoder = new StringDecoder();
|
||
assertEquals(decoder.write(Buffer.from("E1", "hex")), "");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
|
||
decoder = new StringDecoder();
|
||
assertEquals(decoder.write(Buffer.from("E18B", "hex")), "");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
|
||
decoder = new StringDecoder();
|
||
assertEquals(decoder.write(Buffer.from("\ufffd")), "\ufffd");
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder();
|
||
assertEquals(
|
||
decoder.write(Buffer.from("\ufffd\ufffd\ufffd")),
|
||
"\ufffd\ufffd\ufffd",
|
||
);
|
||
assertEquals(decoder.end(), "");
|
||
|
||
decoder = new StringDecoder();
|
||
assertEquals(decoder.write(Buffer.from("EFBFBDE2", "hex")), "\ufffd");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
|
||
decoder = new StringDecoder();
|
||
assertEquals(decoder.write(Buffer.from("F1", "hex")), "");
|
||
assertEquals(decoder.write(Buffer.from("41F2", "hex")), "\ufffdA");
|
||
assertEquals(decoder.end(), "\ufffd");
|
||
},
|
||
});
|