test: write some tests and fix bugs

This commit is contained in:
tkqubo
2015-10-24 23:54:39 +09:00
parent 072851d225
commit 28eaae8ef1
2 changed files with 123 additions and 5 deletions
+116
View File
@@ -2477,6 +2477,7 @@ var greetPartial = function (greeting: string, name: string) { return greeting +
var hi = _.partial(greetPartial, 'hi');
hi('moe');
var defaultsDeep = <Function>_.partialRight(_.merge, _.defaults);
var optionsPartialRight = {
@@ -3866,3 +3867,118 @@ result = <_.TemplateSettings>_.templateSettings;
result = _(42).times(testTimesFn).value();
result = _(42).times(testTimesFn, any).value();
}
// _.partial & _.partialRight
{
function func0(): number {
return 42;
}
function func1(arg1: number): number {
return arg1 * 2;
}
function func2(arg1: number, arg2: string): number {
return arg1 * arg2.length;
}
function func3(arg1: number, arg2: string, arg3: boolean): number {
return arg1 * arg2.length + (arg3 ? 1 : 0);
}
function func4(arg1: number, arg2: string, arg3: boolean, arg4: number): number {
return arg1 * arg2.length + (arg3 ? 1 : 0) - arg4;
}
let res____: () => number;
let res1___: (arg1: number ) => number;
let res_2__: ( arg2: string ) => number;
let res__3_: ( arg3: boolean ) => number;
let res___4: ( arg4: number) => number;
let res12__: (arg1: number, arg2: string ) => number;
let res1_3_: (arg1: number, arg3: boolean ) => number;
let res1__4: (arg1: number, arg4: number) => number;
let res_23_: ( arg2: string, arg3: boolean ) => number;
let res_2_4: ( arg2: string, arg4: number) => number;
let res__34: ( arg3: boolean, arg4: number) => number;
let res123_: (arg1: number, arg2: string, arg3: boolean ) => number;
let res12_4: (arg1: number, arg2: string, arg4: number) => number;
let res1_34: (arg1: number, arg3: boolean, arg4: number) => number;
let res_234: ( arg2: string, arg3: boolean, arg4: number) => number;
let res1234: (arg1: number, arg2: string, arg3: boolean, arg4: number) => number;
//
// _.partial
//
// with arity 0 function
res____ = _.partial(func0);
// with arity 1 function
res____ = _.partial(func1, 42 );
res1___ = _.partial(func1 );
// with arity 2 function
res12__ = _.partial(func2 );
res_2__ = _.partial(func2, 42 );
res1___ = _.partial(func2, _, "foo");
res____ = _.partial(func2, 42, "foo");
// with arity 3 function
res123_ = _.partial(func3 );
res_23_ = _.partial(func3, 42 );
res1_3_ = _.partial(func3, _, "foo" );
res__3_ = _.partial(func3, 42, "foo" );
res12__ = _.partial(func3, _, _, true);
res_2__ = _.partial(func3, 42, _, true);
res1___ = _.partial(func3, _, "foo", true);
res____ = _.partial(func3, 42, "foo", true);
// with arity 4 function
res1234 = _.partial(func4 );
res_234 = _.partial(func4, 42 );
res1_34 = _.partial(func4, _, "foo" );
res__34 = _.partial(func4, 42, "foo" );
res12_4 = _.partial(func4, _, _, true );
res_2_4 = _.partial(func4, 42, _, true );
res1__4 = _.partial(func4, _, "foo", true );
res___4 = _.partial(func4, 42, "foo", true );
res123_ = _.partial(func4, _, _, _, 100);
res_23_ = _.partial(func4, 42, _, _, 100);
res1_3_ = _.partial(func4, _, "foo", _, 100);
res__3_ = _.partial(func4, 42, "foo", _, 100);
res12__ = _.partial(func4, _, _, true, 100);
res_2__ = _.partial(func4, 42, _, true, 100);
res1___ = _.partial(func4, _, "foo", true, 100);
res____ = _.partial(func4, 42, "foo", true, 100);
//
// _.partialRight
//
// with arity 0 function
res____ = _.partialRight(func0);
// with arity 1 function
res____ = _.partialRight(func1, 42 );
res1___ = _.partialRight(func1 );
// with arity 2 function
res12__ = _.partialRight(func2 );
res_2__ = _.partialRight(func2, 42, _);
res1___ = _.partialRight(func2, "foo");
res____ = _.partialRight(func2, 42, "foo");
// with arity 3 function
res123_ = _.partialRight(func3 );
res_23_ = _.partialRight(func3, 42, _, _);
res1_3_ = _.partialRight(func3, "foo", _);
res__3_ = _.partialRight(func3, 42, "foo", _);
res12__ = _.partialRight(func3, true);
res_2__ = _.partialRight(func3, 42, _, true);
res1___ = _.partialRight(func3, "foo", true);
res____ = _.partialRight(func3, 42, "foo", true);
// with arity 4 function
res1234 = _.partialRight(func4 );
res_234 = _.partialRight(func4, 42, _, _, _);
res1_34 = _.partialRight(func4, "foo", _, _);
res__34 = _.partialRight(func4, 42, "foo", _, _);
res12_4 = _.partialRight(func4, true, _);
res_2_4 = _.partialRight(func4, 42, _, true, _);
res1__4 = _.partialRight(func4, "foo", true, _);
res___4 = _.partialRight(func4, 42, "foo", true, _);
res123_ = _.partialRight(func4, 100);
res_23_ = _.partialRight(func4, 42, _, _, 100);
res1_3_ = _.partialRight(func4, "foo", _, 100);
res__3_ = _.partialRight(func4, 42, "foo", _, 100);
res12__ = _.partialRight(func4, true, 100);
res_2__ = _.partialRight(func4, 42, _, true, 100);
res1___ = _.partialRight(func4, "foo", true, 100);
res____ = _.partialRight(func4, 42, "foo", true, 100);
}
+7 -5
View File
@@ -6554,6 +6554,7 @@ declare module _ {
type Function4<T1, T2, T3, T4, R> = (t1: T1, t2: T2, t3: T3, t4: T4) => R;
interface Partial {
// arity 0
<R>(func: Function0<R>): Function0<R>;
// arity 1
<T1, R>(func: Function1<T1, R>): Function1<T1, R>;
@@ -6604,6 +6605,7 @@ declare module _ {
}
interface PartialRight {
// arity 0
<R>(func: Function0<R>): Function0<R>;
// arity 1
<T1, R>(func: Function1<T1, R>): Function1<T1, R>;
@@ -6616,7 +6618,7 @@ declare module _ {
// arity 3
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>): Function3<T1, T2, T3, R>;
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg1: T1, plc2: PH, plc3: PH): Function2< T2, T3, R>;
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, plc1: PH, arg2: T2, plc3: PH): Function2<T1, T3, R>;
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg2: T2, plc3: PH): Function2<T1, T3, R>;
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg1: T1, arg2: T2, plc3: PH): Function1< T3, R>;
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg3: T3): Function2<T1, T2, R>;
<T1, T2, T3, R>(func: Function3<T1, T2, T3, R>, arg1: T1, plc2: PH, arg3: T3): Function1< T2, R>;
@@ -6625,17 +6627,17 @@ declare module _ {
// arity 4
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>): Function4<T1, T2, T3, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: PH, plc3: PH, plc4: PH): Function3< T2, T3, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: PH, arg2: T2, plc3: PH, plc4: PH): Function3<T1, T3, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg2: T2, plc3: PH, plc4: PH): Function3<T1, T3, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, plc3: PH, plc4: PH): Function2< T3, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: PH, plc2: PH, arg3: T3, plc4: PH): Function3<T1, T2, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg3: T3, plc4: PH): Function3<T1, T2, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: PH, arg3: T3, plc4: PH): Function2< T2, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg2: T2, arg3: T3, plc4: PH): Function2<T1, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3, plc4: PH): Function1< T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg4: T4): Function3<T1, T2, T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: PH, plc3: PH, arg4: T4): Function2< T2, T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: PH, arg2: T2, plc3: PH, arg4: T4): Function2<T1, T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg2: T2, plc3: PH, arg4: T4): Function2<T1, T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, plc3: PH, arg4: T4): Function1< T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: PH, plc2: PH, arg3: T3, arg4: T4): Function2<T1, T2, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg3: T3, arg4: T4): Function2<T1, T2, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: PH, arg3: T3, arg4: T4): Function1< T2, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg2: T2, arg3: T3, arg4: T4): Function1<T1, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3, arg4: T4): Function0< R>;