typia icon indicating copy to clipboard operation
typia copied to clipboard

Question: How are the validations covered by tests ?

Open bogeeee opened this issue 1 year ago • 1 comments

Question

Hi Samchon !

You sayed :

Furthermore, I've enhanced typia through 1,000,000 LOC test codes. Considering characteristics of typia using pure TypeScript type, typia must support every TypeScript type cases.

Can you explain, where in source code you cover the validations ? I.e. by a simple example:

type MyType = number | boolean
assertEquals<MyType>("anEvilString")

So, where under test/src is the code, that covers a union type. I.e. i found this one: test/src/structures/AtomicUnion.ts ? How does it exactly go till there. Also: Is the code under test/src/features all generated ? So, as i see, 1million LOC rather means mostly the generated code, right ?

The next question. As there's already much work put into the tests or structures: Might it be technically possible to take these to test the validation code in the typescript-rtti library ? What could be the hurdes ?

Thx for an answer and keep on that good project !

bogeeee avatar Feb 05 '24 19:02 bogeeee

Yes, all of the test files under the test/features director are automatically generated. All of automatically generated test functions are performing their detailed tests by calling functions of test/src/internal folder.

For ference, the test code generation program starts from the test/build/template.ts file.

Also, I think it may possible to validate the typescript-rtti by same way with me, and it would be meaningful taking test structures of typia and test the typescript-rtti with them. Also, you can utilize typia.random<T>() function to generate random test data, and you can damage the structured data by calling Structure.SPOILERS[i](value) fuction.

https://github.com/samchon/typia/blob/master/test/src/structures/ObjectHierarchical.ts#L112-L178

samchon avatar Feb 08 '24 10:02 samchon

Hey samchon, I had first success on running your test structures against typescript-rtti :) :) :) nice Still i need to somehow filter out the structures that make only sense for typia but i don't understand all the TestStructure flags. So could you please jsdoc these flags here ? Thanks !

bogeeee avatar Feb 25 '24 19:02 bogeeee

As typia is supporting not only validators, but also supporting many other features like protobuf.

By the way, in the protobuf case, its expression power is much lower than TypeScript. Therefore, it is not possible to make protobuf test functions for every structures case. The TestStructure type represents the spec that whether each structure can be used in each feature or not.

For example, NativeSimple structure can't be used in both JSON and Protobuf functions.

  • https://typia.io/docs/protobuf/message/#restrictions
  • https://github.com/samchon/typia/blob/master/test/src/structures/NativeSimple.ts

samchon avatar Feb 26 '24 07:02 samchon