summaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-03-06 22:39:50 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-06 16:39:50 -0500
commite36edfdb3fd4709358a5f499f13cfe3d53c2b4f7 (patch)
tree1baef3f876a5e75288c3ec9056cdb93dd6b5787f /io
parentd29957ad17956016c35a04f5f1f98565e58e8a2e (diff)
Testing refactor (denoland/deno_std#240)
Original: https://github.com/denoland/deno_std/commit/e1d5c00279132aa639030c6c6d9b4e308bd4775e
Diffstat (limited to 'io')
-rw-r--r--io/bufio.ts2
-rw-r--r--io/bufio_test.ts63
-rw-r--r--io/ioutil.ts4
-rw-r--r--io/ioutil_test.ts23
-rw-r--r--io/readers_test.ts25
-rw-r--r--io/util_test.ts15
-rw-r--r--io/writers_test.ts7
7 files changed, 72 insertions, 67 deletions
diff --git a/io/bufio.ts b/io/bufio.ts
index 33cddea2b..f583a2ff9 100644
--- a/io/bufio.ts
+++ b/io/bufio.ts
@@ -5,7 +5,7 @@
import { Reader, ReadResult, Writer } from "deno";
import { charCode, copyBytes } from "./util.ts";
-import { assert } from "../testing/mod.ts";
+import { assert } from "../testing/asserts.ts";
const DEFAULT_BUF_SIZE = 4096;
const MIN_BUF_SIZE = 16;
diff --git a/io/bufio_test.ts b/io/bufio_test.ts
index 41151b681..e291ebfec 100644
--- a/io/bufio_test.ts
+++ b/io/bufio_test.ts
@@ -5,7 +5,8 @@
const { Buffer } = Deno;
import { Reader, ReadResult } from "deno";
-import { test, assert, assertEqual } from "../testing/mod.ts";
+import { test } from "../testing/mod.ts";
+import { assert, assertEq } from "../testing/asserts.ts";
import { BufReader, BufWriter } from "./bufio.ts";
import * as iotest from "./iotest.ts";
import { charCode, copyBytes, stringsReader } from "./util.ts";
@@ -31,7 +32,7 @@ test(async function bufioReaderSimple() {
const data = "hello world";
const b = new BufReader(stringsReader(data));
const s = await readBytes(b);
- assert.equal(s, data);
+ assertEq(s, data);
});
interface ReadMaker {
@@ -113,7 +114,7 @@ test(async function bufioBufReader() {
const debugStr =
`reader=${readmaker.name} ` +
`fn=${bufreader.name} bufsize=${bufsize} want=${text} got=${s}`;
- assertEqual(s, text, debugStr);
+ assertEq(s, text, debugStr);
}
}
}
@@ -128,12 +129,12 @@ test(async function bufioBufferFull() {
const decoder = new TextDecoder();
let actual = decoder.decode(line);
- assertEqual(err, "BufferFull");
- assertEqual(actual, "And now, hello, ");
+ assertEq(err, "BufferFull");
+ assertEq(actual, "And now, hello, ");
[line, err] = await buf.readSlice(charCode("!"));
actual = decoder.decode(line);
- assertEqual(actual, "world!");
+ assertEq(actual, "world!");
assert(err == null);
});
@@ -177,20 +178,20 @@ async function testReadLine(input: Uint8Array): Promise<void> {
if (line.byteLength > 0 && err != null) {
throw Error("readLine returned both data and error");
}
- assertEqual(isPrefix, false);
+ assertEq(isPrefix, false);
if (err == "EOF") {
break;
}
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
let want = testOutput.subarray(done, done + line.byteLength);
- assertEqual(
+ assertEq(
line,
want,
`Bad line at stride ${stride}: want: ${want} got: ${line}`
);
done += line.byteLength;
}
- assertEqual(
+ assertEq(
done,
testOutput.byteLength,
`readLine didn't return everything: got: ${done}, ` +
@@ -214,54 +215,54 @@ test(async function bufioPeek() {
);
let [actual, err] = await buf.peek(1);
- assertEqual(decoder.decode(actual), "a");
+ assertEq(decoder.decode(actual), "a");
assert(err == null);
[actual, err] = await buf.peek(4);
- assertEqual(decoder.decode(actual), "abcd");
+ assertEq(decoder.decode(actual), "abcd");
assert(err == null);
[actual, err] = await buf.peek(32);
- assertEqual(decoder.decode(actual), "abcdefghijklmnop");
- assertEqual(err, "BufferFull");
+ assertEq(decoder.decode(actual), "abcdefghijklmnop");
+ assertEq(err, "BufferFull");
await buf.read(p.subarray(0, 3));
- assertEqual(decoder.decode(p.subarray(0, 3)), "abc");
+ assertEq(decoder.decode(p.subarray(0, 3)), "abc");
[actual, err] = await buf.peek(1);
- assertEqual(decoder.decode(actual), "d");
+ assertEq(decoder.decode(actual), "d");
assert(err == null);
[actual, err] = await buf.peek(1);
- assertEqual(decoder.decode(actual), "d");
+ assertEq(decoder.decode(actual), "d");
assert(err == null);
[actual, err] = await buf.peek(1);
- assertEqual(decoder.decode(actual), "d");
+ assertEq(decoder.decode(actual), "d");
assert(err == null);
[actual, err] = await buf.peek(2);
- assertEqual(decoder.decode(actual), "de");
+ assertEq(decoder.decode(actual), "de");
assert(err == null);
let { eof } = await buf.read(p.subarray(0, 3));
- assertEqual(decoder.decode(p.subarray(0, 3)), "def");
+ assertEq(decoder.decode(p.subarray(0, 3)), "def");
assert(!eof);
assert(err == null);
[actual, err] = await buf.peek(4);
- assertEqual(decoder.decode(actual), "ghij");
+ assertEq(decoder.decode(actual), "ghij");
assert(err == null);
await buf.read(p);
- assertEqual(decoder.decode(p), "ghijklmnop");
+ assertEq(decoder.decode(p), "ghijklmnop");
[actual, err] = await buf.peek(0);
- assertEqual(decoder.decode(actual), "");
+ assertEq(decoder.decode(actual), "");
assert(err == null);
[actual, err] = await buf.peek(1);
- assertEqual(decoder.decode(actual), "");
+ assertEq(decoder.decode(actual), "");
assert(err == "EOF");
/* TODO
// Test for issue 3022, not exposing a reader's error on a successful Peek.
@@ -301,15 +302,15 @@ test(async function bufioWriter() {
const context = `nwrite=${nwrite} bufsize=${bs}`;
const n = await buf.write(data.subarray(0, nwrite));
- assertEqual(n, nwrite, context);
+ assertEq(n, nwrite, context);
await buf.flush();
const written = w.bytes();
- assertEqual(written.byteLength, nwrite);
+ assertEq(written.byteLength, nwrite);
for (let l = 0; l < written.byteLength; l++) {
- assertEqual(written[l], data[l]);
+ assertEq(written[l], data[l]);
}
}
}
@@ -324,15 +325,15 @@ test(async function bufReaderReadFull() {
{
const buf = new Uint8Array(6);
const [nread, err] = await bufr.readFull(buf);
- assertEqual(nread, 6);
+ assertEq(nread, 6);
assert(!err);
- assertEqual(dec.decode(buf), "Hello ");
+ assertEq(dec.decode(buf), "Hello ");
}
{
const buf = new Uint8Array(6);
const [nread, err] = await bufr.readFull(buf);
- assertEqual(nread, 5);
- assertEqual(err, "EOF");
- assertEqual(dec.decode(buf.subarray(0, 5)), "World");
+ assertEq(nread, 5);
+ assertEq(err, "EOF");
+ assertEq(dec.decode(buf.subarray(0, 5)), "World");
}
});
diff --git a/io/ioutil.ts b/io/ioutil.ts
index 6590c0f66..2d189620d 100644
--- a/io/ioutil.ts
+++ b/io/ioutil.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { BufReader } from "./bufio.ts";
import { Reader, Writer } from "deno";
-import { assert } from "../testing/mod.ts";
+import { assert } from "../testing/asserts.ts";
/** copy N size at the most. If read size is lesser than N, then returns nread */
export async function copyN(
@@ -19,7 +19,7 @@ export async function copyN(
bytesRead += nread;
if (nread > 0) {
const n = await dest.write(buf.slice(0, nread));
- assert.assert(n === nread, "could not write");
+ assert(n === nread, "could not write");
}
if (eof) {
break;
diff --git a/io/ioutil_test.ts b/io/ioutil_test.ts
index 08d0d677e..aabdf015b 100644
--- a/io/ioutil_test.ts
+++ b/io/ioutil_test.ts
@@ -1,7 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
const { Buffer } = Deno;
import { Reader, ReadResult } from "deno";
-import { assert, assertEqual, test } from "../testing/mod.ts";
+import { test } from "../testing/mod.ts";
+import { assertEq } from "../testing/asserts.ts";
import {
copyN,
readInt,
@@ -27,13 +28,13 @@ class BinaryReader implements Reader {
test(async function testReadShort() {
const r = new BinaryReader(new Uint8Array([0x12, 0x34]));
const short = await readShort(new BufReader(r));
- assertEqual(short, 0x1234);
+ assertEq(short, 0x1234);
});
test(async function testReadInt() {
const r = new BinaryReader(new Uint8Array([0x12, 0x34, 0x56, 0x78]));
const int = await readInt(new BufReader(r));
- assertEqual(int, 0x12345678);
+ assertEq(int, 0x12345678);
});
test(async function testReadLong() {
@@ -41,7 +42,7 @@ test(async function testReadLong() {
new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78])
);
const long = await readLong(new BufReader(r));
- assertEqual(long, 0x1234567812345678);
+ assertEq(long, 0x1234567812345678);
});
test(async function testReadLong2() {
@@ -49,7 +50,7 @@ test(async function testReadLong2() {
new Uint8Array([0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78])
);
const long = await readLong(new BufReader(r));
- assertEqual(long, 0x12345678);
+ assertEq(long, 0x12345678);
});
test(async function testSliceLongToBytes() {
@@ -62,26 +63,26 @@ test(async function testSliceLongToBytes() {
)
)
);
- assertEqual(actual, expected);
+ assertEq(actual, expected);
});
test(async function testSliceLongToBytes2() {
const arr = sliceLongToBytes(0x12345678);
- assertEqual(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]);
+ assertEq(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]);
});
test(async function testCopyN1() {
const w = new Buffer();
const r = stringsReader("abcdefghij");
const n = await copyN(w, r, 3);
- assert.equal(n, 3);
- assert.equal(w.toString(), "abc");
+ assertEq(n, 3);
+ assertEq(w.toString(), "abc");
});
test(async function testCopyN2() {
const w = new Buffer();
const r = stringsReader("abcdefghij");
const n = await copyN(w, r, 11);
- assert.equal(n, 10);
- assert.equal(w.toString(), "abcdefghij");
+ assertEq(n, 10);
+ assertEq(w.toString(), "abcdefghij");
});
diff --git a/io/readers_test.ts b/io/readers_test.ts
index 8da9d6e73..17410804f 100644
--- a/io/readers_test.ts
+++ b/io/readers_test.ts
@@ -1,5 +1,6 @@
const { copy } = Deno;
-import { assert, test } from "../testing/mod.ts";
+import { test } from "../testing/mod.ts";
+import { assertEq } from "../testing/asserts.ts";
import { MultiReader, StringReader } from "./readers.ts";
import { StringWriter } from "./writers.ts";
import { copyN } from "./ioutil.ts";
@@ -8,29 +9,29 @@ import { decode } from "../strings/strings.ts";
test(async function ioStringReader() {
const r = new StringReader("abcdef");
const { nread, eof } = await r.read(new Uint8Array(6));
- assert.equal(nread, 6);
- assert.equal(eof, true);
+ assertEq(nread, 6);
+ assertEq(eof, true);
});
test(async function ioStringReader() {
const r = new StringReader("abcdef");
const buf = new Uint8Array(3);
let res1 = await r.read(buf);
- assert.equal(res1.nread, 3);
- assert.equal(res1.eof, false);
- assert.equal(decode(buf), "abc");
+ assertEq(res1.nread, 3);
+ assertEq(res1.eof, false);
+ assertEq(decode(buf), "abc");
let res2 = await r.read(buf);
- assert.equal(res2.nread, 3);
- assert.equal(res2.eof, true);
- assert.equal(decode(buf), "def");
+ assertEq(res2.nread, 3);
+ assertEq(res2.eof, true);
+ assertEq(decode(buf), "def");
});
test(async function ioMultiReader() {
const r = new MultiReader(new StringReader("abc"), new StringReader("def"));
const w = new StringWriter();
const n = await copyN(w, r, 4);
- assert.equal(n, 4);
- assert.equal(w.toString(), "abcd");
+ assertEq(n, 4);
+ assertEq(w.toString(), "abcd");
await copy(w, r);
- assert.equal(w.toString(), "abcdef");
+ assertEq(w.toString(), "abcdef");
});
diff --git a/io/util_test.ts b/io/util_test.ts
index 62cdfe533..2fca41d31 100644
--- a/io/util_test.ts
+++ b/io/util_test.ts
@@ -1,6 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
const { remove } = Deno;
-import { test, assert } from "../testing/mod.ts";
+import { test } from "../testing/mod.ts";
+import { assert, assertEq } from "../testing/asserts.ts";
import { copyBytes, tempFile } from "./util.ts";
import * as path from "../fs/path.ts";
@@ -11,31 +12,31 @@ test(function testCopyBytes() {
let src = Uint8Array.of(1, 2);
let len = copyBytes(dst, src, 0);
assert(len === 2);
- assert.equal(dst, Uint8Array.of(1, 2, 0, 0));
+ assertEq(dst, Uint8Array.of(1, 2, 0, 0));
dst.fill(0);
src = Uint8Array.of(1, 2);
len = copyBytes(dst, src, 1);
assert(len === 2);
- assert.equal(dst, Uint8Array.of(0, 1, 2, 0));
+ assertEq(dst, Uint8Array.of(0, 1, 2, 0));
dst.fill(0);
src = Uint8Array.of(1, 2, 3, 4, 5);
len = copyBytes(dst, src);
assert(len === 4);
- assert.equal(dst, Uint8Array.of(1, 2, 3, 4));
+ assertEq(dst, Uint8Array.of(1, 2, 3, 4));
dst.fill(0);
src = Uint8Array.of(1, 2);
len = copyBytes(dst, src, 100);
assert(len === 0);
- assert.equal(dst, Uint8Array.of(0, 0, 0, 0));
+ assertEq(dst, Uint8Array.of(0, 0, 0, 0));
dst.fill(0);
src = Uint8Array.of(3, 4);
len = copyBytes(dst, src, -2);
assert(len === 2);
- assert.equal(dst, Uint8Array.of(3, 4, 0, 0));
+ assertEq(dst, Uint8Array.of(3, 4, 0, 0));
});
test(async function ioTempfile() {
@@ -45,6 +46,6 @@ test(async function ioTempfile() {
});
console.log(f.file, f.filepath);
const base = path.basename(f.filepath);
- assert.assert(!!base.match(/^prefix-.+?-postfix$/));
+ assert(!!base.match(/^prefix-.+?-postfix$/));
await remove(f.filepath);
});
diff --git a/io/writers_test.ts b/io/writers_test.ts
index ba4d7ed89..847fc059b 100644
--- a/io/writers_test.ts
+++ b/io/writers_test.ts
@@ -1,5 +1,6 @@
const { copy } = Deno;
-import { assert, test } from "../testing/mod.ts";
+import { test } from "../testing/mod.ts";
+import { assertEq } from "../testing/asserts.ts";
import { StringWriter } from "./writers.ts";
import { StringReader } from "./readers.ts";
import { copyN } from "./ioutil.ts";
@@ -8,7 +9,7 @@ test(async function ioStringWriter() {
const w = new StringWriter("base");
const r = new StringReader("0123456789");
await copyN(w, r, 4);
- assert.equal(w.toString(), "base0123");
+ assertEq(w.toString(), "base0123");
await copy(w, r);
- assert.equal(w.toString(), "base0123456789");
+ assertEq(w.toString(), "base0123456789");
});