Move all packages to a types directory

This commit is contained in:
Andy Hanson
2017-03-24 14:27:52 -07:00
parent f9869dc191
commit 354cec620d
13846 changed files with 0 additions and 0 deletions
+161
View File
@@ -0,0 +1,161 @@
import { expect, settings, fail, count, incomplete, thrownAt } from "code";
expect(10).to.be.above(5);
expect("abc").to.be.a.string();
expect([1, 2]).to.be.an.array();
expect(20).to.be.at.least(20);
expect("abc").to.have.length(3);
expect("abc").to.be.a.string().and.contain(["a", "b"]);
expect(6).to.be.in.range(5, 6);
expect(10).to.not.be.above(20);
expect([1, 2, 3]).to.shallow.include(3);
expect([1, 1, 2]).to.only.include([1, 2]);
expect([1, 2]).to.once.include([1, 2]);
expect([1, 2, 3]).to.part.include([1, 4]);
expect(10, "Age").to.be.above(5);
const func = function() { return arguments; };
expect(func()).to.be.arguments();
expect([1, 2]).to.be.an.array();
expect(true).to.be.a.boolean();
expect(new Date()).to.be.a.date();
const err = new Error("Oops an error occured.");
expect(err).to.be.an.error();
expect(err).to.be.an.error(Error);
expect(err).to.be.an.error("Oops an error occured.");
expect(err).to.be.an.error(Error, /occured/);
expect(func).to.be.a.function();
expect(123).to.be.a.number();
expect(/abc/).to.be.a.regexp();
expect("abc").to.be.a.string();
expect({ a: "1" }).to.be.an.object();
expect(true).to.be.true();
expect(false).to.be.false();
expect(null).to.be.null();
expect(undefined).to.be.undefined();
expect("abc").to.include("ab");
expect("abc").to.only.include("abc");
expect("aaa").to.only.include("a");
expect("abc").to.once.include("b");
expect("abc").to.include(["a", "c"]);
expect("abc").to.part.include(["a", "d"]);
expect([1, 2, 3]).to.include(1);
expect([{ a: 1 }]).to.include({ a: 1 });
expect([1, 2, 3]).to.include([1, 2]);
expect([{ a: 1 }]).to.include([{ a: 1 }]);
expect([1, 1, 2]).to.only.include([1, 2]);
expect([1, 2]).to.once.include([1, 2]);
expect([1, 2, 3]).to.part.include([1, 4]);
expect([[1], [2]]).to.include([[1]]);
interface TestType {
a: number;
b?: number;
c?: number;
d?: number;
}
interface TestType2 {
a: number[];
b?: number[];
c: number[];
}
expect({ a: 1, b: 2, c: 3 }).to.include("a");
expect({ a: 1, b: 2, c: 3 }).to.include(["a", "c"]);
expect({ a: 1, b: 2, c: 3 }).to.only.include(["a", "b", "c"]);
expect<TestType>({ a: 1, b: 2, c: 3 }).to.include({ a: 1 });
expect<any>({ a: 1, b: 2, c: 3 }).to.include({ a: 1 });
expect<TestType>({ a: 1, b: 2, c: 3 }).to.include({ a: 1, c: 3 });
expect<TestType>({ a: 1, b: 2, c: 3 }).to.part.include({ a: 1, d: 4 });
expect<any>({ a: 1, b: 2, c: 3 }).to.part.include({ a: 1, d: 4 });
expect({ a: 1, b: 2, c: 3 }).to.only.include({ a: 1, b: 2, c: 3 });
expect<TestType2>({ a: [1], b: [2], c: [3] }).to.include({ a: [1], c: [3] });
expect<any>({ a: [1], b: [2], c: [3] }).to.include({ a: [1], c: [3] });
expect("https://example.org/secure").to.startWith("https://");
expect("http://example.org/relative").to.endWith("/relative");
expect(4).to.exist();
expect(null).to.not.exist();
expect("abc").to.be.empty();
expect("abcd").to.have.length(4);
expect(5).to.equal(5);
expect({ a: 1 }).to.equal({ a: 1 });
expect(Object.create(null)).to.equal({}, { prototype: false });
expect(5).to.shallow.equal(5);
expect({ a: 1 }).to.shallow.equal({ a: 1 });
expect(10).to.be.above(5);
expect(10).to.be.at.least(10);
expect(10).to.be.below(20);
expect(10).to.be.at.most(10);
expect(10).to.be.within(10, 20);
expect(20).to.be.within(10, 20);
expect(15).to.be.between(10, 20);
expect(10).to.be.about(9, 1);
expect(new Date()).to.be.an.instanceof(Date);
expect("a5").to.match(/\w\d/);
expect(["abc", "def"]).to.match(/^[\w\d,]*$/);
expect(1).to.match(/^\d$/);
expect("x").to.satisfy(value => value === "x");
class CustomError extends Error {
call: (message: string) => Error;
}
const throws = () => {
throw new CustomError("Oh no!");
};
expect(throws).to.throw(CustomError, "Oh no!");
fail("This should not occur");
expect(count()).to.be.a.number();
expect(incomplete() as null).to.be.null().and.not.be.an.array();
const error = thrownAt(new Error("oops"));
expect(error).to.not.be.undefined();
expect(error.column).to.exist();
const foo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
settings.truncateMessages = false;
expect<number[]>(foo).to.equal([]);
const bar = Object.create(null);
settings.comparePrototypes = false;
expect(bar).to.equal({});
+190
View File
@@ -0,0 +1,190 @@
// Type definitions for code 4.0
// Project: https://github.com/hapijs/code
// Definitions by: Prashant Tiwari <https://github.com/prashaantt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/** Generates an assertion object. */
export function expect<T>(value: T | T[], prefix?: string): AssertionChain<T>;
/** Makes the test fail with the given message. */
export function fail(message: string): void;
/** Returns the total number of assertions created using the expect() method. */
export function count(): number;
/** Returns an array of the locations where incomplete assertions were declared or null if no incomplete assertions found. */
export function incomplete(): string[] | null;
/** Returns the filename, line number, and column number of where the error was created. */
export function thrownAt(error?: Error): CodeError;
/** Configure code. */
export const settings: Settings;
type AssertionChain<T> = Assertion<T> & Expectation<T>;
type Assertion<T> = Grammar<T> & Flags<T>;
type Expectation<T> = Types<T> & Values<T>;
interface Grammar<T> {
/** Connecting word. */
a: AssertionChain<T>;
/** Connecting word. */
an: AssertionChain<T>;
/** Connecting word. */
and: AssertionChain<T>;
/** Connecting word. */
at: AssertionChain<T>;
/** Connecting word. */
be: AssertionChain<T>;
/** Connecting word. */
have: AssertionChain<T>;
/** Connecting word. */
in: AssertionChain<T>;
/** Connecting word. */
to: AssertionChain<T>;
}
interface Flags<T> {
/** Inverses the expected result of any assertion */
not: AssertionChain<T>;
/**
* Requires that inclusion matches appear only once in the provided value.
* Used by include().
*/
once: AssertionChain<T>;
/**
* Requires that only the provided elements appear in the provided value.
* Used by include().
*/
only: AssertionChain<T>;
/**
* Allows a partial match when asserting inclusion
* Used by include(). Defaults to false.
*/
part: AssertionChain<T>;
/**
* Performs a comparison using strict equality (===).
* Code defaults to deep comparison. Used by equal() and include().
*/
shallow: AssertionChain<T>;
}
interface Types<T> {
/** Asserts that the reference value is an arguments object. */
arguments(): AssertionChain<T>;
/** Asserts that the reference value is an Array. */
array(): AssertionChain<T>;
/** Asserts that the reference value is a boolean. */
boolean(): AssertionChain<T>;
/** Asserts that the reference value is a Buffer. */
buffer(): AssertionChain<T>;
/** Asserts that the reference value is a Date. */
date(): AssertionChain<T>;
/** Asserts that the reference value is an error. */
error(type?: any, message?: string | RegExp): AssertionChain<T>;
/** Asserts that the reference value is a function. */
function(): AssertionChain<T>;
/** Asserts that the reference value is a number. */
number(): AssertionChain<T>;
/** Asserts that the reference value is a RegExp. */
regexp(): AssertionChain<T>;
/** Asserts that the reference value is a string. */
string(): AssertionChain<T>;
/** Asserts that the reference value is an object (excluding array, buffer, or other native objects). */
object(): AssertionChain<T>;
}
interface Values<T> {
/** Asserts that the reference value is true. */
true(): AssertionChain<T>;
/** Asserts that the reference value is false. */
false(): AssertionChain<T>;
/** Asserts that the reference value is null. */
null(): AssertionChain<T>;
/** Asserts that the reference value is undefined. */
undefined(): AssertionChain<T>;
/** Asserts that the reference value (a string, array, or object) includes the provided values. */
include(values: string | string[] | T | T[]): AssertionChain<T>;
/** Asserts that the reference value (a string, array, or object) includes the provided values. */
includes(values: string | string[] | T | T[]): AssertionChain<T>;
/** Asserts that the reference value (a string, array, or object) includes the provided values. */
contain(values: string | string[] | T | T[]): AssertionChain<T>;
/** Asserts that the reference value (a string, array, or object) includes the provided values. */
contains(values: string | string[] | T | T[]): AssertionChain<T>;
/** Asserts that the reference value (a string) starts with the provided value. */
startWith(value: string): AssertionChain<T>;
/** Asserts that the reference value (a string) starts with the provided value. */
startsWith(value: string): AssertionChain<T>;
/** Asserts that the reference value (a string) ends with the provided value. */
endWith(value: string): AssertionChain<T>;
/** Asserts that the reference value (a string) ends with the provided value. */
endsWith(value: string): AssertionChain<T>;
/** Asserts that the reference value exists (not null or undefined). */
exist(): AssertionChain<T>;
/** Asserts that the reference value exists (not null or undefined). */
exists(): AssertionChain<T>;
/** Asserts that the reference value has a length property equal to zero or an object with no keys. */
empty(): AssertionChain<T>;
/** Asserts that the reference value has a length property matching the provided size or an object with the specified number of keys. */
length(size: number): AssertionChain<T>;
/** Asserts that the reference value equals the provided value. */
equal(value: T, options?: any): AssertionChain<T>;
/** Asserts that the reference value equals the provided value. */
equals(value: T, options?: any): AssertionChain<T>;
/** Asserts that the reference value is greater than (>) the provided value. */
above(value: T): AssertionChain<T>;
/** Asserts that the reference value is greater than (>) the provided value. */
greaterThan(value: T): AssertionChain<T>;
/** Asserts that the reference value is at least (>=) the provided value. */
least(value: T): AssertionChain<T>;
/** Asserts that the reference value is at least (>=) the provided value. */
min(value: T): AssertionChain<T>;
/** Asserts that the reference value is less than (<) the provided value. */
below(value: T): AssertionChain<T>;
/** Asserts that the reference value is less than (<) the provided value. */
lessThan(value: T): AssertionChain<T>;
/** Asserts that the reference value is at most (<=) the provided value. */
most(value: T): AssertionChain<T>;
/** Asserts that the reference value is at most (<=) the provided value. */
max(value: T): AssertionChain<T>;
/** Asserts that the reference value is within (from <= value <= to) the provided values. */
within(from: T, to: T): AssertionChain<T>;
/** Asserts that the reference value is within (from <= value <= to) the provided values. */
range(from: T, to: T): AssertionChain<T>;
/** Asserts that the reference value is between but not equal (from < value < to) the provided values. */
between(from: T, to: T): AssertionChain<T>;
/** Asserts that the reference value is about the provided value within a delta margin of difference. */
about(value: number, delta: number): AssertionChain<T>;
/** Asserts that the reference value has the provided instanceof value. */
instanceof(type: any): AssertionChain<T>;
/** Asserts that the reference value has the provided instanceof value. */
instanceOf(type: any): AssertionChain<T>;
/** Asserts that the reference value's toString() representation matches the provided regular expression. */
match(regex: RegExp): AssertionChain<T>;
/** Asserts that the reference value's toString() representation matches the provided regular expression. */
matches(regex: RegExp): AssertionChain<T>;
/** Asserts that the reference value satisfies the provided validator function. */
satisfy(validator: (value: T) => boolean): AssertionChain<T>;
/** Asserts that the reference value satisfies the provided validator function. */
satisfies(validator: (value: T) => boolean): AssertionChain<T>;
/** Asserts that the function reference value throws an exception when called. */
throw(type?: any, message?: string | RegExp): AssertionChain<T>;
/** Asserts that the function reference value throws an exception when called. */
throws(type?: any, message?: string | RegExp): AssertionChain<T>;
}
interface Settings {
/**
* Truncate long assertion error messages for readability?
* Defaults to true.
*/
truncateMessages?: boolean;
/**
* Ignore object prototypes when doing a deep comparison?
* Defaults to false.
*/
comparePrototypes?: boolean;
}
interface CodeError {
filename: string;
line: string;
column: string;
}
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"code-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../tslint.json" }