if (!('Deno' in globalThis)) {
	throw new Error('This module requires Deno to run');
}
import { ITestBase } from '../common/types.ts';
import { stdAssert } from './deps.ts';
const {
	assertEquals,
	assertExists,
	assertInstanceOf,
	AssertionError,
	assertNotEquals,
	assertStrictEquals,
} = stdAssert;

export function testSuite(testObj: any) {
	Object.keys(testObj).forEach((group) => {
		const groupObj = testObj[group];
		Object.keys(groupObj).forEach((testName) => {
			Deno.test(testName, groupObj[testName]);
		});
	});
}

const DenoTestBase: ITestBase = {
	assertEquals,
	assertExists,
	assertInstanceOf,
	assertNotEquals,
	assertStrictEquals,
	assertTrue: function (actual: boolean): void {
		if (actual !== true) {
			throw new AssertionError(`actual: "${actual}" expected to be true"`);
		}
	},
	assertFalse(actual: boolean): void {
		if (actual !== false) {
			throw new AssertionError(`actual: "${actual}" expected to be false"`);
		}
	},
	assertNull(actual: boolean): void {
		if (actual !== null) {
			throw new AssertionError(`actual: "${actual}" expected to be null"`);
		}
	},
	testSuite,
};

export default DenoTestBase;