1+ import { describe , test , expect , beforeEach } from 'vitest' ;
2+ import {
3+ IntConstructor ,
4+ StringConstructor ,
5+ MultipleConstructor ,
6+ ExportedClass ,
7+ ExportedClassConstructor ,
8+ ExportedClassMultipleConstructor ,
9+ ExportedClassArrayConstructor ,
10+ ExportedClassActionConstructor ,
11+ IntStringMixedConstructor
12+ } from '@typeshim/e2e-wasm-lib' ;
13+
14+ describe ( 'Constructors Test' , ( ) => {
15+ test ( 'IntConstructor with int parameter' , async ( ) => {
16+ const instance = new IntConstructor ( 100 ) ;
17+ expect ( instance . Value ) . toBe ( 100 ) ;
18+ } ) ;
19+
20+ test ( 'IntConstructor with different values' , async ( ) => {
21+ const instance1 = new IntConstructor ( 0 ) ;
22+ expect ( instance1 . Value ) . toBe ( 0 ) ;
23+
24+ const instance2 = new IntConstructor ( - 50 ) ;
25+ expect ( instance2 . Value ) . toBe ( - 50 ) ;
26+
27+ const instance3 = new IntConstructor ( 2147483647 ) ;
28+ expect ( instance3 . Value ) . toBe ( 2147483647 ) ;
29+ } ) ;
30+
31+ test ( 'StringConstructor with string parameter' , async ( ) => {
32+ const instance = new StringConstructor ( 'hello' ) ;
33+ expect ( instance . Value ) . toBe ( 'hello' ) ;
34+ } ) ;
35+
36+ test ( 'StringConstructor with different strings' , async ( ) => {
37+ const instance1 = new StringConstructor ( '' ) ;
38+ expect ( instance1 . Value ) . toBe ( '' ) ;
39+
40+ const instance2 = new StringConstructor ( 'test string' ) ;
41+ expect ( instance2 . Value ) . toBe ( 'test string' ) ;
42+
43+ const instance3 = new StringConstructor ( 'special chars: !@#$%' ) ;
44+ expect ( instance3 . Value ) . toBe ( 'special chars: !@#$%' ) ;
45+ } ) ;
46+
47+ test ( 'MultipleConstructor with int and string parameters' , async ( ) => {
48+ const instance = new MultipleConstructor ( 42 , 'test' ) ;
49+ expect ( instance . IntValue ) . toBe ( 42 ) ;
50+ expect ( instance . StringValue ) . toBe ( 'test' ) ;
51+ } ) ;
52+
53+ test ( 'MultipleConstructor with various values' , async ( ) => {
54+ const instance1 = new MultipleConstructor ( 0 , '' ) ;
55+ expect ( instance1 . IntValue ) . toBe ( 0 ) ;
56+ expect ( instance1 . StringValue ) . toBe ( '' ) ;
57+
58+ const instance2 = new MultipleConstructor ( - 100 , 'negative' ) ;
59+ expect ( instance2 . IntValue ) . toBe ( - 100 ) ;
60+ expect ( instance2 . StringValue ) . toBe ( 'negative' ) ;
61+ } ) ;
62+
63+ test ( 'ExportedClassConstructor with ExportedClass parameter' , async ( ) => {
64+ const exported = new ExportedClass ( { Id : 1 } ) ;
65+ const instance = new ExportedClassConstructor ( exported ) ;
66+ expect ( instance . Value ) . toBe ( exported ) ;
67+ } ) ;
68+
69+ test ( 'ExportedClassMultipleConstructor with multiple ExportedClass parameters' , async ( ) => {
70+ const exported1 = new ExportedClass ( { Id : 1 } ) ;
71+ const exported2 = new ExportedClass ( { Id : 2 } ) ;
72+ const instance = new ExportedClassMultipleConstructor ( exported1 , exported2 ) ;
73+ expect ( instance . Value ) . toBe ( exported1 ) ;
74+ expect ( instance . Value2 ) . toBe ( exported2 ) ;
75+ } ) ;
76+
77+ test ( 'ExportedClassArrayConstructor with ExportedClass array parameter' , async ( ) => {
78+ const exported1 = new ExportedClass ( { Id : 1 } ) ;
79+ const exported2 = new ExportedClass ( { Id : 2 } ) ;
80+ const exported3 = new ExportedClass ( { Id : 3 } ) ;
81+ const array = [ exported1 , exported2 , exported3 ] ;
82+ const instance = new ExportedClassArrayConstructor ( array ) ;
83+ expect ( instance . Value ) . toStrictEqual ( array ) ;
84+ expect ( instance . Value . length ) . toBe ( 3 ) ;
85+ } ) ;
86+
87+ test ( 'ExportedClassArrayConstructor with empty array' , async ( ) => {
88+ const array : ExportedClass [ ] = [ ] ;
89+ const instance = new ExportedClassArrayConstructor ( array ) ;
90+ expect ( instance . Value ) . toStrictEqual ( array ) ;
91+ expect ( instance . Value . length ) . toBe ( 0 ) ;
92+ } ) ;
93+
94+ test ( 'ExportedClassActionConstructor with Action<ExportedClass> parameter' , async ( ) => {
95+ let callCount = 0 ;
96+ const action = ( obj : ExportedClass ) => {
97+ callCount ++ ;
98+ } ;
99+ const instance = new ExportedClassActionConstructor ( action ) ;
100+ instance . Value ( new ExportedClass ( { Id : 1 } ) )
101+ expect ( callCount ) . toBe ( 1 ) ;
102+ instance . Value ( new ExportedClass ( { Id : 2 } ) )
103+ expect ( callCount ) . toBe ( 2 ) ;
104+ } ) ;
105+
106+ test ( 'ExportedClassActionConstructor action is callable' , async ( ) => {
107+ let receivedValue : ExportedClass | null = null ;
108+ const action = ( obj : ExportedClass ) => {
109+ receivedValue = obj ;
110+ } ;
111+ const instance = new ExportedClassActionConstructor ( action ) ;
112+ const exported = new ExportedClass ( { Id : 1 } ) ;
113+ instance . Value ( exported ) ;
114+ expect ( receivedValue ) . toBe ( exported ) ;
115+ } ) ;
116+
117+ test ( 'IntStringMixedConstructor with int and string parameters' , ( ) => {
118+ const instance = new IntStringMixedConstructor ( 42 , { StringValue : 'test' } ) ;
119+ expect ( instance . Value ) . toBe ( 42 ) ;
120+ expect ( instance . StringValue ) . toBe ( 'test' ) ;
121+ } )
122+ } ) ;
0 commit comments