2019-03-05 14:58:28 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2019-03-07 09:08:19 -05:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertNotEquals,
|
|
|
|
assertStrContains,
|
|
|
|
assertArrayContains,
|
|
|
|
assertMatch,
|
2019-03-08 02:32:46 -05:00
|
|
|
assertEquals,
|
2019-03-08 16:04:43 -05:00
|
|
|
assertThrows,
|
|
|
|
AssertionError,
|
|
|
|
equal,
|
|
|
|
fail,
|
2019-03-08 02:32:46 -05:00
|
|
|
unimplemented,
|
|
|
|
unreachable
|
2019-03-07 09:08:19 -05:00
|
|
|
} from "./asserts.ts";
|
2019-03-06 16:39:50 -05:00
|
|
|
import { test } from "./mod.ts";
|
2019-03-05 14:58:28 -05:00
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingEqual(): void {
|
2019-03-06 16:39:50 -05:00
|
|
|
assert(equal("world", "world"));
|
|
|
|
assert(!equal("hello", "world"));
|
|
|
|
assert(equal(5, 5));
|
|
|
|
assert(!equal(5, 6));
|
|
|
|
assert(equal(NaN, NaN));
|
|
|
|
assert(equal({ hello: "world" }, { hello: "world" }));
|
|
|
|
assert(!equal({ world: "hello" }, { hello: "world" }));
|
|
|
|
assert(
|
|
|
|
equal(
|
|
|
|
{ hello: "world", hi: { there: "everyone" } },
|
|
|
|
{ hello: "world", hi: { there: "everyone" } }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assert(
|
|
|
|
!equal(
|
|
|
|
{ hello: "world", hi: { there: "everyone" } },
|
|
|
|
{ hello: "world", hi: { there: "everyone else" } }
|
|
|
|
)
|
|
|
|
);
|
2019-03-26 08:15:16 -04:00
|
|
|
assert(equal(/deno/, /deno/));
|
|
|
|
assert(!equal(/deno/, /node/));
|
|
|
|
assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3)));
|
|
|
|
assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3)));
|
2019-04-22 09:39:33 -04:00
|
|
|
assert(equal(new Set([1]), new Set([1])));
|
|
|
|
assert(!equal(new Set([1]), new Set([2])));
|
|
|
|
assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1])));
|
|
|
|
assert(!equal(new Set([1, 2]), new Set([3, 2, 1])));
|
|
|
|
assert(!equal(new Set([1, 2, 3]), new Set([4, 5, 6])));
|
|
|
|
assert(equal(new Set("denosaurus"), new Set("denosaurussss")));
|
2019-03-06 16:39:50 -05:00
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingNotEquals(): void {
|
2019-03-07 09:08:19 -05:00
|
|
|
const a = { foo: "bar" };
|
|
|
|
const b = { bar: "foo" };
|
|
|
|
assertNotEquals(a, b);
|
|
|
|
assertNotEquals("Denosaurus", "Tyrannosaurus");
|
|
|
|
let didThrow;
|
|
|
|
try {
|
|
|
|
assertNotEquals("Raptor", "Raptor");
|
|
|
|
didThrow = false;
|
|
|
|
} catch (e) {
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-07 09:08:19 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assertEquals(didThrow, true);
|
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertStringContains(): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
assertStrContains("Denosaurus", "saur");
|
|
|
|
assertStrContains("Denosaurus", "Deno");
|
|
|
|
assertStrContains("Denosaurus", "rus");
|
2019-03-07 09:08:19 -05:00
|
|
|
let didThrow;
|
|
|
|
try {
|
|
|
|
assertStrContains("Denosaurus", "Raptor");
|
|
|
|
didThrow = false;
|
|
|
|
} catch (e) {
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-07 09:08:19 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assertEquals(didThrow, true);
|
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingArrayContains(): void {
|
2019-03-07 09:08:19 -05:00
|
|
|
const fixture = ["deno", "iz", "luv"];
|
|
|
|
const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
|
|
|
|
assertArrayContains(fixture, ["deno"]);
|
|
|
|
assertArrayContains(fixtureObject, [{ deno: "luv" }]);
|
|
|
|
let didThrow;
|
|
|
|
try {
|
|
|
|
assertArrayContains(fixtureObject, [{ deno: "node" }]);
|
|
|
|
didThrow = false;
|
|
|
|
} catch (e) {
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-07 09:08:19 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assertEquals(didThrow, true);
|
2019-03-05 14:58:28 -05:00
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertStringContainsThrow(): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
assertStrContains("Denosaurus from Jurassic", "Raptor");
|
|
|
|
} catch (e) {
|
|
|
|
assert(
|
|
|
|
e.message ===
|
|
|
|
`actual: "Denosaurus from Jurassic" expected to contains: "Raptor"`
|
|
|
|
);
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-05 14:58:28 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertStringMatching(): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
assertMatch("foobar@deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/));
|
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertStringMatchingThrows(): void {
|
2019-03-05 14:58:28 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/));
|
|
|
|
} catch (e) {
|
|
|
|
assert(
|
|
|
|
e.message ===
|
|
|
|
`actual: "Denosaurus from Jurassic" expected to match: "/Raptor/"`
|
|
|
|
);
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-05 14:58:28 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
2019-03-08 02:32:46 -05:00
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertsUnimplemented(): void {
|
2019-03-08 02:32:46 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
unimplemented();
|
|
|
|
} catch (e) {
|
|
|
|
assert(e.message === "unimplemented");
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-08 02:32:46 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertsUnreachable(): void {
|
2019-03-08 02:32:46 -05:00
|
|
|
let didThrow = false;
|
|
|
|
try {
|
|
|
|
unreachable();
|
|
|
|
} catch (e) {
|
|
|
|
assert(e.message === "unreachable");
|
2019-03-08 16:04:43 -05:00
|
|
|
assert(e instanceof AssertionError);
|
2019-03-08 02:32:46 -05:00
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
assert(didThrow);
|
|
|
|
});
|
2019-03-08 16:04:43 -05:00
|
|
|
|
2019-04-24 07:41:23 -04:00
|
|
|
test(function testingAssertFail(): void {
|
2019-03-08 16:04:43 -05:00
|
|
|
assertThrows(fail, AssertionError, "Failed assertion.");
|
|
|
|
assertThrows(
|
2019-04-24 07:41:23 -04:00
|
|
|
(): void => {
|
2019-03-08 16:04:43 -05:00
|
|
|
fail("foo");
|
|
|
|
},
|
|
|
|
AssertionError,
|
|
|
|
"Failed assertion: foo"
|
|
|
|
);
|
|
|
|
});
|