Skip to content

Commit

Permalink
refactor: rewrite tests in to use Deno.test (denoland/deno#3930)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and denobot committed Feb 1, 2021
1 parent 85619cd commit 82a5236
Show file tree
Hide file tree
Showing 94 changed files with 328 additions and 1,185 deletions.
9 changes: 3 additions & 6 deletions archive/tar_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
* **to run this test**
* deno run --allow-read archive/tar_test.ts
*/
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";

import { resolve } from "../path/mod.ts";
import { Tar, Untar } from "./tar.ts";

const filePath = resolve("archive", "testdata", "example.txt");

test(async function createTarArchive(): Promise<void> {
Deno.test(async function createTarArchive(): Promise<void> {
// initialize
const tar = new Tar();

Expand All @@ -41,7 +40,7 @@ test(async function createTarArchive(): Promise<void> {
assertEquals(wrote, 3072);
});

test(async function deflateTarArchive(): Promise<void> {
Deno.test(async function deflateTarArchive(): Promise<void> {
const fileName = "output.txt";
const text = "hello tar world!";

Expand All @@ -64,7 +63,7 @@ test(async function deflateTarArchive(): Promise<void> {
assertEquals(untarText, text);
});

test(async function appendFileWithLongNameToTarArchive(): Promise<void> {
Deno.test(async function appendFileWithLongNameToTarArchive(): Promise<void> {
// 9 * 15 + 13 = 148 bytes
const fileName = new Array(10).join("long-file-name/") + "file-name.txt";
const text = "hello tar world!";
Expand All @@ -87,5 +86,3 @@ test(async function appendFileWithLongNameToTarArchive(): Promise<void> {
assertEquals(result.fileName, fileName);
assertEquals(untarText, text);
});

runIfMain(import.meta);
15 changes: 7 additions & 8 deletions bytes/test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

import { findIndex, findLastIndex, equal, hasPrefix, repeat } from "./mod.ts";
import { test } from "../testing/mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";

test(function bytesfindIndex1(): void {
Deno.test(function bytesfindIndex1(): void {
const i = findIndex(
new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]),
new Uint8Array([0, 1, 2])
);
assertEquals(i, 2);
});

test(function bytesfindIndex2(): void {
Deno.test(function bytesfindIndex2(): void {
const i = findIndex(new Uint8Array([0, 0, 1]), new Uint8Array([0, 1]));
assertEquals(i, 1);
});

test(function bytesfindLastIndex1(): void {
Deno.test(function bytesfindLastIndex1(): void {
const i = findLastIndex(
new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]),
new Uint8Array([0, 1, 2])
);
assertEquals(i, 3);
});

test(function bytesfindLastIndex2(): void {
Deno.test(function bytesfindLastIndex2(): void {
const i = findLastIndex(new Uint8Array([0, 1, 1]), new Uint8Array([0, 1]));
assertEquals(i, 0);
});

test(function bytesBytesequal(): void {
Deno.test(function bytesBytesequal(): void {
const v = equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3]));
assertEquals(v, true);
});

test(function byteshasPrefix(): void {
Deno.test(function byteshasPrefix(): void {
const v = hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1]));
assertEquals(v, true);
});

test(function bytesrepeat(): void {
Deno.test(function bytesrepeat(): void {
// input / output / count / error message
const repeatTestCase = [
["", "", 0],
Expand Down
17 changes: 8 additions & 9 deletions datetime/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";
import * as datetime from "./mod.ts";

test(function parseDateTime(): void {
Deno.test(function parseDateTime(): void {
assertEquals(
datetime.parseDateTime("01-03-2019 16:30", "mm-dd-yyyy hh:mm"),
new Date(2019, 0, 3, 16, 30)
Expand All @@ -30,7 +29,7 @@ test(function parseDateTime(): void {
);
});

test(function invalidParseDateTimeFormatThrows(): void {
Deno.test(function invalidParseDateTimeFormatThrows(): void {
assertThrows(
(): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -41,7 +40,7 @@ test(function invalidParseDateTimeFormatThrows(): void {
);
});

test(function parseDate(): void {
Deno.test(function parseDate(): void {
assertEquals(
datetime.parseDate("01-03-2019", "mm-dd-yyyy"),
new Date(2019, 0, 3)
Expand All @@ -56,7 +55,7 @@ test(function parseDate(): void {
);
});

test(function invalidParseDateFormatThrows(): void {
Deno.test(function invalidParseDateFormatThrows(): void {
assertThrows(
(): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -67,17 +66,17 @@ test(function invalidParseDateFormatThrows(): void {
);
});

test(function DayOfYear(): void {
Deno.test(function DayOfYear(): void {
assertEquals(1, datetime.dayOfYear(new Date("2019-01-01T03:24:00")));
assertEquals(70, datetime.dayOfYear(new Date("2019-03-11T03:24:00")));
assertEquals(365, datetime.dayOfYear(new Date("2019-12-31T03:24:00")));
});

test(function currentDayOfYear(): void {
Deno.test(function currentDayOfYear(): void {
assertEquals(datetime.currentDayOfYear(), datetime.dayOfYear(new Date()));
});

test({
Deno.test({
name: "[DateTime] to IMF",
fn(): void {
const actual = datetime.toIMF(new Date(Date.UTC(1994, 3, 5, 15, 32)));
Expand All @@ -86,7 +85,7 @@ test({
}
});

test({
Deno.test({
name: "[DateTime] to IMF 0",
fn(): void {
const actual = datetime.toIMF(new Date(0));
Expand Down
11 changes: 4 additions & 7 deletions encoding/base32_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Test cases copied from https://github.com/LinusU/base32-encode/blob/master/test.js
// Copyright (c) 2016-2017 Linus Unnebäck. MIT license.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";
import { encode, decode } from "./base32.ts";

Expand Down Expand Up @@ -87,7 +86,7 @@ const testCases = [
]
];

test({
Deno.test({
name: "[encoding.base32] encode",
fn(): void {
for (const [bin, b32] of testCases) {
Expand All @@ -96,7 +95,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.base32] decode",
fn(): void {
for (const [bin, b32] of testCases) {
Expand All @@ -105,7 +104,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.base32] decode bad length",
fn(): void {
let errorCaught = false;
Expand All @@ -121,7 +120,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.base32] decode bad padding",
fn(): void {
let errorCaught = false;
Expand All @@ -134,5 +133,3 @@ test({
assert(errorCaught);
}
});

runIfMain(import.meta);
7 changes: 2 additions & 5 deletions encoding/csv_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Test ported from Golang
// https://github.com/golang/go/blob/2cc15b1/src/encoding/csv/reader_test.go
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";
import { readMatrix, parse } from "./csv.ts";
import { StringReader } from "../io/readers.ts";
Expand Down Expand Up @@ -450,7 +449,7 @@ x,,,
}
];
for (const t of testCases) {
test({
Deno.test({
name: `[CSV] ${t.Name}`,
async fn(): Promise<void> {
let comma = ",";
Expand Down Expand Up @@ -605,7 +604,7 @@ const parseTestCases = [
];

for (const testCase of parseTestCases) {
test({
Deno.test({
name: `[CSV] Parse ${testCase.name}`,
async fn(): Promise<void> {
const r = await parse(testCase.in, {
Expand All @@ -616,5 +615,3 @@ for (const testCase of parseTestCases) {
}
});
}

runIfMain(import.meta);
19 changes: 8 additions & 11 deletions encoding/hex_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";

import {
Expand Down Expand Up @@ -46,7 +45,7 @@ const errCases = [
["ffeed", "\xff\xee", errLength()]
];

test({
Deno.test({
name: "[encoding.hex] encodedLen",
fn(): void {
assertEquals(encodedLen(0), 0);
Expand All @@ -57,7 +56,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] encode",
fn(): void {
{
Expand Down Expand Up @@ -92,7 +91,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] encodeToString",
fn(): void {
for (const [enc, dec] of testCases) {
Expand All @@ -101,7 +100,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] decodedLen",
fn(): void {
assertEquals(decodedLen(0), 0);
Expand All @@ -112,7 +111,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] decode",
fn(): void {
// Case for decoding uppercase hex characters, since
Expand All @@ -133,7 +132,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] decodeString",
fn(): void {
for (const [enc, dec] of testCases) {
Expand All @@ -144,7 +143,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] decode error",
fn(): void {
for (const [input, output, expectedErr] of errCases) {
Expand All @@ -159,7 +158,7 @@ test({
}
});

test({
Deno.test({
name: "[encoding.hex] decodeString error",
fn(): void {
for (const [input, output, expectedErr] of errCases) {
Expand All @@ -178,5 +177,3 @@ test({
}
}
});

runIfMain(import.meta);
Loading

0 comments on commit 82a5236

Please sign in to comment.