@@ -4,58 +4,64 @@ import {DATA_TYPES, FUNCTION_SIGNATURES} from "./data";
44import { getTypesFromNode } from "../src" ;
55
66describe ( 'getTypeVariant' , ( ) => {
7- it ( 'sollte PRIMITIVE für einfache Typen zurückgeben ' , ( ) => {
8- expect ( getTypeVariant ( "string" , DATA_TYPES ) ) . toBe ( DataTypeVariant . PRIMITIVE ) ;
9- expect ( getTypeVariant ( "number" , DATA_TYPES ) ) . toBe ( DataTypeVariant . PRIMITIVE ) ;
10- expect ( getTypeVariant ( "boolean" , DATA_TYPES ) ) . toBe ( DataTypeVariant . PRIMITIVE ) ;
7+ it ( 'identifies native TypeScript primitives (string, number, boolean) as PRIMITIVE variant ' , ( ) => {
8+ expect ( getTypeVariant ( "string" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . PRIMITIVE ) ;
9+ expect ( getTypeVariant ( "number" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . PRIMITIVE ) ;
10+ expect ( getTypeVariant ( "boolean" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . PRIMITIVE ) ;
1111 } ) ;
1212
13- it ( 'sollte ARRAY für Array-Typen zurückgeben ' , ( ) => {
14- expect ( getTypeVariant ( "string[]" , DATA_TYPES ) ) . toBe ( DataTypeVariant . ARRAY ) ;
15- expect ( getTypeVariant ( "Array<number>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . ARRAY ) ;
13+ it ( 'recognizes both bracket notation and generic syntax for array types as ARRAY variant ' , ( ) => {
14+ expect ( getTypeVariant ( "string[]" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . ARRAY ) ;
15+ expect ( getTypeVariant ( "Array<number>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . ARRAY ) ;
1616 } ) ;
1717
18- it ( 'sollte OBJECT für Interfaces oder Objekte mit Properties zurückgeben ' , ( ) => {
19- expect ( getTypeVariant ( "{ name: string }" , DATA_TYPES ) ) . toBe ( DataTypeVariant . OBJECT ) ;
20- expect ( getTypeVariant ( "{}" , DATA_TYPES ) ) . toBe ( DataTypeVariant . OBJECT ) ;
21- expect ( getTypeVariant ( "OBJECT<any>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . OBJECT ) ;
18+ it ( 'classifies object literals and interface-like structures as OBJECT variant ' , ( ) => {
19+ expect ( getTypeVariant ( "{ name: string }" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . OBJECT ) ;
20+ expect ( getTypeVariant ( "{}" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . OBJECT ) ;
21+ expect ( getTypeVariant ( "OBJECT<any>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . OBJECT ) ;
2222 } ) ;
2323
24- it ( 'sollte TYPE für einfache Type-Aliase oder void zurückgeben ' , ( ) => {
25- expect ( getTypeVariant ( "void" , DATA_TYPES ) ) . toBe ( DataTypeVariant . TYPE ) ;
26- expect ( getTypeVariant ( "any" , DATA_TYPES ) ) . toBe ( DataTypeVariant . TYPE ) ;
24+ it ( 'marks special types like void and any as TYPE variant ' , ( ) => {
25+ expect ( getTypeVariant ( "void" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . TYPE ) ;
26+ expect ( getTypeVariant ( "any" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . TYPE ) ;
2727 } ) ;
2828
29- it ( 'sollte LIST (NUMBER) als ARRAY erkennen (wenn in DATA_TYPES definiert) ' , ( ) => {
30- // In data.ts ist LIST als T[] definiert
31- expect ( getTypeVariant ( "LIST<NUMBER>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . ARRAY ) ;
32- expect ( getTypeVariant ( "LIST<unknown>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . ARRAY ) ;
33- expect ( getTypeVariant ( "LIST<T>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . ARRAY ) ;
29+ it ( 'resolves generic LIST type aliases to ARRAY variant regardless of type parameter ' , ( ) => {
30+ // LIST<T> is defined as T[] in data.ts, so all LIST variants should be arrays
31+ expect ( getTypeVariant ( "LIST<NUMBER>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . ARRAY ) ;
32+ expect ( getTypeVariant ( "LIST<unknown>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . ARRAY ) ;
33+ expect ( getTypeVariant ( "LIST<T>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . ARRAY ) ;
3434 } ) ;
3535
36- it ( 'sollte NODE für Funktionstypen wie CONSUMER zurückgeben ' , ( ) => {
37- // In data.ts ist CONSUMER als (item:R ) => void definiert
38- expect ( getTypeVariant ( "CONSUMER<NUMBER>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . NODE ) ;
36+ it ( 'identifies CONSUMER function types with generic parameters as NODE variant ' , ( ) => {
37+ // CONSUMER<T> represents a callback function (T ) => void
38+ expect ( getTypeVariant ( "CONSUMER<NUMBER>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . NODE ) ;
3939 } ) ;
4040
41- it ( 'sollte NODE für Funktionstypen wie RUNNABLE zurückgeben ' , ( ) => {
42- // In data.ts ist CONSUMER als (item:R ) => void definiert
43- expect ( getTypeVariant ( "RUNNABLE" , DATA_TYPES ) ) . toBe ( DataTypeVariant . NODE ) ;
41+ it ( 'identifies parameterless function types like RUNNABLE as NODE variant ' , ( ) => {
42+ // RUNNABLE represents ( ) => void with no parameters
43+ expect ( getTypeVariant ( "RUNNABLE" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . NODE ) ;
4444 } ) ;
4545
46- it ( 'sollte NODE für Funktionstypen wie PREDICATE zurückgeben ' , ( ) => {
47- // In data.ts ist CONSUMER als (item:R ) => void definiert
48- expect ( getTypeVariant ( "PREDICATE<NUMBER>" , DATA_TYPES ) ) . toBe ( DataTypeVariant . NODE ) ;
46+ it ( 'identifies PREDICATE function types with generic parameters as NODE variant ' , ( ) => {
47+ // PREDICATE<T> represents a boolean-returning function (T ) => boolean
48+ expect ( getTypeVariant ( "PREDICATE<NUMBER>" , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . NODE ) ;
4949 } ) ;
5050
51+ it ( 'correctly identifies type variants when retrieved directly from DATA_TYPES registry' , ( ) => {
52+ // Verify that types stored in DATA_TYPES are properly classified
53+ expect ( getTypeVariant ( DATA_TYPES . find ( dt => dt . identifier === "LIST" ) , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . ARRAY ) ;
54+ expect ( getTypeVariant ( DATA_TYPES . find ( dt => dt . identifier === "HTTP_METHOD" ) , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . TYPE ) ;
55+ } ) ;
5156
52- it ( "Check if" , ( ) => {
57+ it ( 'recognizes callback parameter types in real function signatures as NODE variant' , ( ) => {
58+ // When extracting types from std::list::for_each, the second parameter (consumer) should be NODE
5359 const types = getTypesFromNode ( {
5460 functionDefinition : {
5561 identifier : "std::list::for_each"
5662 }
5763 } , FUNCTION_SIGNATURES , DATA_TYPES )
58- expect ( getTypeVariant ( types . parameters [ 1 ] , DATA_TYPES ) ) . toBe ( DataTypeVariant . NODE ) ;
64+ expect ( getTypeVariant ( types . parameters [ 1 ] , DATA_TYPES ) [ 0 ] . variant ) . toBe ( DataTypeVariant . NODE ) ;
5965 } ) ;
6066} ) ;
6167
0 commit comments