less test clutter

This commit is contained in:
Umur Ozkul 2022-07-18 22:52:19 +02:00
parent fa2561306d
commit 4535041876
3 changed files with 33 additions and 62 deletions

View File

@ -15,7 +15,7 @@ let myIevEvalToString = (aTypeSourceCode: string) =>
let myIevExpectEqual = (aTypeSourceCode, answer) =>
expect(myIevEvalToString(aTypeSourceCode))->toEqual(answer)
let _myIevTest = (test, aTypeSourceCode, answer) =>
let myIevTest = (test, aTypeSourceCode, answer) =>
test(aTypeSourceCode, () => myIevExpectEqual(aTypeSourceCode, answer))
let myTypeEval = (aTypeSourceCode: string) =>
@ -25,38 +25,28 @@ let myTypeEvalToString = (aTypeSourceCode: string) => myTypeEval(aTypeSourceCode
let myTypeExpectEqual = (aTypeSourceCode, answer) =>
expect(myTypeEvalToString(aTypeSourceCode))->toEqual(answer)
let _myTypeTest = (test, aTypeSourceCode, answer) =>
let myTypeTest = (test, aTypeSourceCode, answer) =>
test(aTypeSourceCode, () => myTypeExpectEqual(aTypeSourceCode, answer))
let myIevTest = (aTypeSourceCode, answer) => _myIevTest(test, aTypeSourceCode, answer)
let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(test, aTypeSourceCode, answer)
module MySkip = {
let myIevTest = (aTypeSourceCode, answer) => _myIevTest(Skip.test, aTypeSourceCode, answer)
let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(Skip.test, aTypeSourceCode, answer)
}
module MyOnly = {
let myIevTest = (aTypeSourceCode, answer) => _myIevTest(Only.test, aTypeSourceCode, answer)
let myTypeTest = (aTypeSourceCode, answer) => _myTypeTest(Only.test, aTypeSourceCode, answer)
}
// | ItTypeIdentifier(string)
myTypeTest("number", "number")
myTypeTest("(number)", "number")
myTypeTest(test, "number", "number")
myTypeTest(test, "(number)", "number")
// | ItModifiedType({modifiedType: iType})
myIevTest("number<-min(0)", "Ok({min: 0,typeIdentifier: #number,typeTag: 'typeIdentifier'})")
myTypeTest("number<-min(0)", "number<-min(0)")
myIevTest(test, "number<-min(0)", "Ok({min: 0,typeIdentifier: #number,typeTag: 'typeIdentifier'})")
myTypeTest(test, "number<-min(0)", "number<-min(0)")
// | ItTypeOr({typeOr: array<iType>})
myTypeTest("number | string", "(number | string)")
myTypeTest(test, "number | string", "(number | string)")
// | ItTypeFunction({inputs: array<iType>, output: iType})
myTypeTest("number => number => number", "(number => number => number)")
myTypeTest(test, "number => number => number", "(number => number => number)")
// | ItTypeArray({element: iType})
myIevTest("[number]", "Ok({element: #number,typeTag: 'typeArray'})")
myTypeTest("[number]", "[number]")
myIevTest(test, "[number]", "Ok({element: #number,typeTag: 'typeArray'})")
myTypeTest(test, "[number]", "[number]")
// | ItTypeTuple({elements: array<iType>})
myTypeTest("[number, string]", "[number, string]")
myTypeTest(test, "[number, string]", "[number, string]")
// | ItTypeRecord({properties: Belt.Map.String.t<iType>})
myIevTest(
test,
"{age: number, name: string}",
"Ok({properties: {age: #number,name: #string},typeTag: 'typeRecord'})",
)
myTypeTest("{age: number, name: string}", "{age: number, name: string}")
myTypeTest(test, "{age: number, name: string}", "{age: number, name: string}")

View File

@ -35,18 +35,7 @@ let myCheckArguments = (aTypeSourceCode: string, sourceCode: string): string =>
let myCheckArgumentsExpectEqual = (aTypeSourceCode, sourceCode, answer) =>
expect(myCheckArguments(aTypeSourceCode, sourceCode))->toEqual(answer)
let _myCheckArgumentsTest = (test, aTypeSourceCode, sourceCode, answer) =>
let myCheckArgumentsTest = (test, aTypeSourceCode, sourceCode, answer) =>
test(aTypeSourceCode, () => myCheckArgumentsExpectEqual(aTypeSourceCode, sourceCode, answer))
let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) =>
_myCheckArgumentsTest(test, aTypeSourceCode, sourceCode, answer)
module MySkip = {
let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) =>
_myCheckArgumentsTest(Skip.test, aTypeSourceCode, sourceCode, answer)
}
module MyOnly = {
let myCheckArgumentsTest = (aTypeSourceCode, sourceCode, answer) =>
_myCheckArgumentsTest(Only.test, aTypeSourceCode, sourceCode, answer)
}
myCheckArgumentsTest("number=>number=>number", "[1,2]", "Ok")
myCheckArgumentsTest(test, "number=>number=>number", "[1,2]", "Ok")

View File

@ -33,46 +33,38 @@ let myTypeCheck = (aTypeSourceCode: string, sourceCode: string): string =>
let myTypeCheckExpectEqual = (aTypeSourceCode, sourceCode, answer) =>
expect(myTypeCheck(aTypeSourceCode, sourceCode))->toEqual(answer)
let _myTypeCheckTest = (test, aTypeSourceCode, sourceCode, answer) =>
let myTypeCheckTest = (test, aTypeSourceCode, sourceCode, answer) =>
test(aTypeSourceCode, () => myTypeCheckExpectEqual(aTypeSourceCode, sourceCode, answer))
let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) =>
_myTypeCheckTest(test, aTypeSourceCode, sourceCode, answer)
module MySkip = {
let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) =>
_myTypeCheckTest(Skip.test, aTypeSourceCode, sourceCode, answer)
}
module MyOnly = {
let myTypeCheckTest = (aTypeSourceCode, sourceCode, answer) =>
_myTypeCheckTest(Only.test, aTypeSourceCode, sourceCode, answer)
}
myTypeCheckTest("number", "1", "Ok")
myTypeCheckTest("number", "'2'", "Expected type: number but got: '2'")
myTypeCheckTest("string", "3", "Expected type: string but got: 3")
myTypeCheckTest("string", "'a'", "Ok")
myTypeCheckTest("[number]", "[1,2,3]", "Ok")
myTypeCheckTest("[number]", "['a','a','a']", "Expected type: number but got: 'a'")
myTypeCheckTest("[number]", "[1,'a',3]", "Expected type: number but got: 'a'")
myTypeCheckTest("[number, string]", "[1,'a']", "Ok")
myTypeCheckTest("[number, string]", "[1, 2]", "Expected type: string but got: 2")
myTypeCheckTest(test, "number", "1", "Ok")
myTypeCheckTest(test, "number", "'2'", "Expected type: number but got: '2'")
myTypeCheckTest(test, "string", "3", "Expected type: string but got: 3")
myTypeCheckTest(test, "string", "'a'", "Ok")
myTypeCheckTest(test, "[number]", "[1,2,3]", "Ok")
myTypeCheckTest(test, "[number]", "['a','a','a']", "Expected type: number but got: 'a'")
myTypeCheckTest(test, "[number]", "[1,'a',3]", "Expected type: number but got: 'a'")
myTypeCheckTest(test, "[number, string]", "[1,'a']", "Ok")
myTypeCheckTest(test, "[number, string]", "[1, 2]", "Expected type: string but got: 2")
myTypeCheckTest(
test,
"[number, string, string]",
"[1,'a']",
"Expected type: [number, string, string] but got: [1,'a']",
)
myTypeCheckTest(
test,
"[number, string]",
"[1,'a', 3]",
"Expected type: [number, string] but got: [1,'a',3]",
)
myTypeCheckTest("{age: number, name: string}", "{age: 1, name: 'a'}", "Ok")
myTypeCheckTest(test, "{age: number, name: string}", "{age: 1, name: 'a'}", "Ok")
myTypeCheckTest(
test,
"{age: number, name: string}",
"{age: 1, name: 'a', job: 'IT'}",
"Expected type: {age: number, name: string} but got: {age: 1,job: 'IT',name: 'a'}",
)
myTypeCheckTest("number | string", "1", "Ok")
myTypeCheckTest("date | string", "1", "Expected type: (date | string) but got: 1")
myTypeCheckTest("number<-min(10)", "10", "Ok")
myTypeCheckTest("number<-min(10)", "0", "Expected type: number<-min(10) but got: 0")
myTypeCheckTest(test, "number | string", "1", "Ok")
myTypeCheckTest(test, "date | string", "1", "Expected type: (date | string) but got: 1")
myTypeCheckTest(test, "number<-min(10)", "10", "Ok")
myTypeCheckTest(test, "number<-min(10)", "0", "Expected type: number<-min(10) but got: 0")