From df4c3689190ad796b82f91c08e151e1f8de7fd7d Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Wed, 20 Jul 2016 21:25:40 -0700 Subject: [PATCH 1/6] support test macros in typescript definitions --- types/base.d.ts | 7 +++++++ types/make.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/types/base.d.ts b/types/base.d.ts index e1f4f974b..10225ad5c 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -120,5 +120,12 @@ export interface ContextualCallbackTestContext extends CallbackTestContext { context: any; } +export interface Macro { + (t: T, input: I, expected: E): void; + title? (providedTitle: string, input: I, expected: E): string; +} + export function test(name: string, run: ContextualTest): void; export function test(run: ContextualTest): void; +export function test (run: Macro | Macro[], input: I, expected: E): void; +export function test (name: string, run: Macro | Macro[], input: I, expected: E): void; diff --git a/types/make.js b/types/make.js index f33fb2f6f..d723e4b58 100644 --- a/types/make.js +++ b/types/make.js @@ -51,6 +51,8 @@ function generatePrefixed(prefix) { output += '\t' + writeFunction(part, 'name: string', 'void'); } else { const type = testType(parts); + output += '\t' + writeFunction(part + '', 'implementation: Macro, input: I, expected: E'); + output += '\t' + writeFunction(part + '', 'name: string, implementation: Macro, input: I, expected: E'); output += '\t' + writeFunction(part, 'name: string, implementation: ' + type); output += '\t' + writeFunction(part, 'implementation: ' + type); } From 2beeebb993029ab3fc24c4738deff33bbd6d3515 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Sun, 24 Jul 2016 07:01:42 -0700 Subject: [PATCH 2/6] Add type 'Macros', Move tests with macros below standard tests --- types/base.d.ts | 5 +++-- types/make.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/types/base.d.ts b/types/base.d.ts index 10225ad5c..9ff8c7205 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -124,8 +124,9 @@ export interface Macro { (t: T, input: I, expected: E): void; title? (providedTitle: string, input: I, expected: E): string; } +export type Macros = Macro | Macro[]; export function test(name: string, run: ContextualTest): void; export function test(run: ContextualTest): void; -export function test (run: Macro | Macro[], input: I, expected: E): void; -export function test (name: string, run: Macro | Macro[], input: I, expected: E): void; +export function test (name: string, run: Macros, input: I, expected: E): void; +export function test (run: Macros, input: I, expected: E): void; diff --git a/types/make.js b/types/make.js index d723e4b58..f9ce5258f 100644 --- a/types/make.js +++ b/types/make.js @@ -51,10 +51,10 @@ function generatePrefixed(prefix) { output += '\t' + writeFunction(part, 'name: string', 'void'); } else { const type = testType(parts); - output += '\t' + writeFunction(part + '', 'implementation: Macro, input: I, expected: E'); - output += '\t' + writeFunction(part + '', 'name: string, implementation: Macro, input: I, expected: E'); output += '\t' + writeFunction(part, 'name: string, implementation: ' + type); output += '\t' + writeFunction(part, 'implementation: ' + type); + output += '\t' + writeFunction(part + '', 'name: string, implementation: Macros, input: I, expected: E'); + output += '\t' + writeFunction(part + '', 'implementation: Macros, input: I, expected: E'); } } From 5a6c32c06e38eacb195561314667cd9e35517619 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Sat, 30 Jul 2016 08:11:03 -0700 Subject: [PATCH 3/6] Make T first type parameter of Macro --- types/base.d.ts | 8 ++++---- types/make.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/base.d.ts b/types/base.d.ts index 9ff8c7205..28519ba21 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -120,13 +120,13 @@ export interface ContextualCallbackTestContext extends CallbackTestContext { context: any; } -export interface Macro { +export interface Macro { (t: T, input: I, expected: E): void; title? (providedTitle: string, input: I, expected: E): string; } -export type Macros = Macro | Macro[]; +export type Macros = Macro | Macro[]; export function test(name: string, run: ContextualTest): void; export function test(run: ContextualTest): void; -export function test (name: string, run: Macros, input: I, expected: E): void; -export function test (run: Macros, input: I, expected: E): void; +export function test (name: string, run: Macros, input: I, expected: E): void; +export function test (run: Macros, input: I, expected: E): void; diff --git a/types/make.js b/types/make.js index f9ce5258f..79b6deb28 100644 --- a/types/make.js +++ b/types/make.js @@ -53,8 +53,8 @@ function generatePrefixed(prefix) { const type = testType(parts); output += '\t' + writeFunction(part, 'name: string, implementation: ' + type); output += '\t' + writeFunction(part, 'implementation: ' + type); - output += '\t' + writeFunction(part + '', 'name: string, implementation: Macros, input: I, expected: E'); - output += '\t' + writeFunction(part + '', 'implementation: Macros, input: I, expected: E'); + output += '\t' + writeFunction(part + '', 'name: string, implementation: Macros<' + type + 'Context, I, E>, input: I, expected: E'); + output += '\t' + writeFunction(part + '', 'implementation: Macros<' + type + 'Context, I, E>, input: I, expected: E'); } } From 344e0c087f8152b4eadddcb6bc1e7acd36ca9399 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Tue, 2 Aug 2016 11:53:00 -0700 Subject: [PATCH 4/6] Make input and expected optional --- types/base.d.ts | 8 ++++---- types/make.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/base.d.ts b/types/base.d.ts index 28519ba21..25e85b285 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -121,12 +121,12 @@ export interface ContextualCallbackTestContext extends CallbackTestContext { } export interface Macro { - (t: T, input: I, expected: E): void; - title? (providedTitle: string, input: I, expected: E): string; + (t: T, input?: I, expected?: E): void; + title? (providedTitle: string, input?: I, expected?: E): string; } export type Macros = Macro | Macro[]; export function test(name: string, run: ContextualTest): void; export function test(run: ContextualTest): void; -export function test (name: string, run: Macros, input: I, expected: E): void; -export function test (run: Macros, input: I, expected: E): void; +export function test (name: string, run: Macros, input?: I, expected?: E): void; +export function test (run: Macros, input?: I, expected?: E): void; diff --git a/types/make.js b/types/make.js index 79b6deb28..c80a054e8 100644 --- a/types/make.js +++ b/types/make.js @@ -53,8 +53,8 @@ function generatePrefixed(prefix) { const type = testType(parts); output += '\t' + writeFunction(part, 'name: string, implementation: ' + type); output += '\t' + writeFunction(part, 'implementation: ' + type); - output += '\t' + writeFunction(part + '', 'name: string, implementation: Macros<' + type + 'Context, I, E>, input: I, expected: E'); - output += '\t' + writeFunction(part + '', 'implementation: Macros<' + type + 'Context, I, E>, input: I, expected: E'); + output += '\t' + writeFunction(part + '', 'name: string, implementation: Macros<' + type + 'Context, I, E>, input?: I, expected?: E'); + output += '\t' + writeFunction(part + '', 'implementation: Macros<' + type + 'Context, I, E>, input?: I, expected?: E'); } } From e99410b8e09def3c4e6fb769a033a9c1711272f4 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Tue, 2 Aug 2016 12:03:01 -0700 Subject: [PATCH 5/6] input and expected are required for Macro --- types/base.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/base.d.ts b/types/base.d.ts index 25e85b285..10cc8285c 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -121,8 +121,8 @@ export interface ContextualCallbackTestContext extends CallbackTestContext { } export interface Macro { - (t: T, input?: I, expected?: E): void; - title? (providedTitle: string, input?: I, expected?: E): string; + (t: T, input: I, expected: E): void; + title? (providedTitle: string, input: I, expected: E): string; } export type Macros = Macro | Macro[]; From 9e499d451ab01f39520acd56556f59c21b5c4518 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Sat, 6 Aug 2016 09:34:17 -0700 Subject: [PATCH 6/6] Support any number of parameters --- types/base.d.ts | 12 ++++++------ types/make.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/base.d.ts b/types/base.d.ts index 10cc8285c..259a5e370 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -120,13 +120,13 @@ export interface ContextualCallbackTestContext extends CallbackTestContext { context: any; } -export interface Macro { - (t: T, input: I, expected: E): void; - title? (providedTitle: string, input: I, expected: E): string; +export interface Macro { + (t: T, ...args: any[]): void; + title? (providedTitle: string, ...args: any[]): string; } -export type Macros = Macro | Macro[]; +export type Macros = Macro | Macro[]; export function test(name: string, run: ContextualTest): void; export function test(run: ContextualTest): void; -export function test (name: string, run: Macros, input?: I, expected?: E): void; -export function test (run: Macros, input?: I, expected?: E): void; +export function test(name: string, run: Macros, ...args: any[]): void; +export function test(run: Macros, ...args: any[]): void; diff --git a/types/make.js b/types/make.js index c80a054e8..658c5025c 100644 --- a/types/make.js +++ b/types/make.js @@ -53,8 +53,8 @@ function generatePrefixed(prefix) { const type = testType(parts); output += '\t' + writeFunction(part, 'name: string, implementation: ' + type); output += '\t' + writeFunction(part, 'implementation: ' + type); - output += '\t' + writeFunction(part + '', 'name: string, implementation: Macros<' + type + 'Context, I, E>, input?: I, expected?: E'); - output += '\t' + writeFunction(part + '', 'implementation: Macros<' + type + 'Context, I, E>, input?: I, expected?: E'); + output += '\t' + writeFunction(part, 'name: string, implementation: Macros<' + type + 'Context>, ...args: any[]'); + output += '\t' + writeFunction(part, 'implementation: Macros<' + type + 'Context>, ...args: any[]'); } }