@@ -46,7 +46,6 @@ func TestTypescriptifyWithTypes(t *testing.T) {
46
46
converter := New ()
47
47
48
48
converter .AddType (reflect .TypeOf (Person {}))
49
- converter .CreateFromMethod = false
50
49
converter .CreateConstructor = false
51
50
converter .BackupDir = ""
52
51
@@ -74,7 +73,6 @@ func TestTypescriptifyWithCustomImports(t *testing.T) {
74
73
converter := New ()
75
74
76
75
converter .AddType (reflect .TypeOf (Person {}))
77
- converter .CreateFromMethod = false
78
76
converter .BackupDir = ""
79
77
converter .AddImport ("//import { Decimal } from 'decimal.js'" )
80
78
converter .CreateConstructor = false
@@ -107,7 +105,6 @@ func TestTypescriptifyWithInstances(t *testing.T) {
107
105
108
106
converter .Add (Person {})
109
107
converter .Add (Dummy {})
110
- converter .CreateFromMethod = false
111
108
converter .DontExport = true
112
109
converter .BackupDir = ""
113
110
converter .CreateConstructor = false
@@ -137,7 +134,6 @@ func TestTypescriptifyWithInterfaces(t *testing.T) {
137
134
138
135
converter .Add (Person {})
139
136
converter .Add (Dummy {})
140
- converter .CreateFromMethod = false
141
137
converter .DontExport = true
142
138
converter .BackupDir = ""
143
139
converter .CreateInterface = true
@@ -167,7 +163,6 @@ func TestTypescriptifyWithDoubleClasses(t *testing.T) {
167
163
168
164
converter .AddType (reflect .TypeOf (Person {}))
169
165
converter .AddType (reflect .TypeOf (Person {}))
170
- converter .CreateFromMethod = false
171
166
converter .CreateConstructor = false
172
167
converter .BackupDir = ""
173
168
@@ -198,18 +193,12 @@ func TestWithPrefixes(t *testing.T) {
198
193
converter .Suffix = "_test"
199
194
200
195
converter .Add (Person {})
201
- converter .CreateFromMethod = false
202
196
converter .DontExport = true
203
197
converter .BackupDir = ""
204
- converter .CreateFromMethod = true
205
198
206
199
desiredResult := `class test_Dummy_test {
207
200
something: string;
208
201
209
- static createFrom(source: any = {}) {
210
- return new test_Dummy_test(source);
211
- }
212
-
213
202
constructor(source: any = {}) {
214
203
if ('string' === typeof source) source = JSON.parse(source);
215
204
this.something = source["something"];
@@ -219,10 +208,6 @@ class test_Address_test {
219
208
duration: number;
220
209
text?: string;
221
210
222
- static createFrom(source: any = {}) {
223
- return new test_Address_test(source);
224
- }
225
-
226
211
constructor(source: any = {}) {
227
212
if ('string' === typeof source) source = JSON.parse(source);
228
213
this.duration = source["duration"];
@@ -238,10 +223,6 @@ class test_Person_test {
238
223
friends: test_Person_test[];
239
224
a: test_Dummy_test;
240
225
241
- static createFrom(source: any = {}) {
242
- return new test_Person_test(source);
243
- }
244
-
245
226
constructor(source: any = {}) {
246
227
if ('string' === typeof source) source = JSON.parse(source);
247
228
this.name = source["name"];
@@ -281,6 +262,8 @@ func testConverter(t *testing.T, converter *TypeScriptify, strictMode bool, desi
281
262
panic (err .Error ())
282
263
}
283
264
265
+ fmt .Println ("----------------------------------------------------------------------------------------------------" )
266
+ fmt .Println (desiredResult )
284
267
fmt .Println ("----------------------------------------------------------------------------------------------------" )
285
268
fmt .Println (typeScriptCode )
286
269
fmt .Println ("----------------------------------------------------------------------------------------------------" )
@@ -356,7 +339,6 @@ func TestTypescriptifyCustomType(t *testing.T) {
356
339
converter := New ()
357
340
358
341
converter .AddType (reflect .TypeOf (TestCustomType {}))
359
- converter .CreateFromMethod = false
360
342
converter .BackupDir = ""
361
343
converter .CreateConstructor = false
362
344
@@ -374,16 +356,11 @@ func TestDate(t *testing.T) {
374
356
375
357
converter := New ()
376
358
converter .AddType (reflect .TypeOf (TestCustomType {}))
377
- converter .CreateFromMethod = true
378
359
converter .BackupDir = ""
379
360
380
361
desiredResult := `export class TestCustomType {
381
362
time: Date;
382
363
383
- static createFrom(source: any = {}) {
384
- return new TestCustomType(source);
385
- }
386
-
387
364
constructor(source: any = {}) {
388
365
if ('string' === typeof source) source = JSON.parse(source);
389
366
this.time = new Date(source["time"]);
@@ -407,24 +384,18 @@ func TestDateWithoutTags(t *testing.T) {
407
384
// Test with custom field options defined per-one-struct:
408
385
converter1 := New ()
409
386
converter1 .Add (NewStruct (TestCustomType {}).WithFieldOpts (time.Time {}, TypeOptions {TSType : "Date" , TSTransform : "new Date(__VALUE__)" }))
410
- converter1 .CreateFromMethod = true
411
387
converter1 .BackupDir = ""
412
388
413
389
// Test with custom field options defined globally:
414
390
converter2 := New ()
415
391
converter2 .Add (reflect .TypeOf (TestCustomType {}))
416
392
converter2 .ManageType (time.Time {}, TypeOptions {TSType : "Date" , TSTransform : "new Date(__VALUE__)" })
417
- converter2 .CreateFromMethod = true
418
393
converter2 .BackupDir = ""
419
394
420
395
for _ , converter := range []* TypeScriptify {converter1 , converter2 } {
421
396
desiredResult := `export class TestCustomType {
422
397
time: Date;
423
398
424
- static createFrom(source: any = {}) {
425
- return new TestCustomType(source);
426
- }
427
-
428
399
constructor(source: any = {}) {
429
400
if ('string' === typeof source) source = JSON.parse(source);
430
401
this.time = new Date(source["time"]);
@@ -449,16 +420,11 @@ func TestRecursive(t *testing.T) {
449
420
converter := New ()
450
421
451
422
converter .AddType (reflect .TypeOf (Test {}))
452
- converter .CreateFromMethod = true
453
423
converter .BackupDir = ""
454
424
455
425
desiredResult := `export class Test {
456
426
children: Test[];
457
427
458
- static createFrom(source: any = {}) {
459
- return new Test(source);
460
- }
461
-
462
428
constructor(source: any = {}) {
463
429
if ('string' === typeof source) source = JSON.parse(source);
464
430
this.children = this.convertValues(source["children"], Test);
@@ -481,16 +447,11 @@ func TestArrayOfArrays(t *testing.T) {
481
447
converter := New ()
482
448
483
449
converter .AddType (reflect .TypeOf (Keyboard {}))
484
- converter .CreateFromMethod = true
485
450
converter .BackupDir = ""
486
451
487
452
desiredResult := `export class Key {
488
453
key: string;
489
454
490
- static createFrom(source: any = {}) {
491
- return new Key(source);
492
- }
493
-
494
455
constructor(source: any = {}) {
495
456
if ('string' === typeof source) source = JSON.parse(source);
496
457
this.key = source["key"];
@@ -499,10 +460,6 @@ func TestArrayOfArrays(t *testing.T) {
499
460
export class Keyboard {
500
461
keys: Key[][];
501
462
502
- static createFrom(source: any = {}) {
503
- return new Keyboard(source);
504
- }
505
-
506
463
constructor(source: any = {}) {
507
464
if ('string' === typeof source) source = JSON.parse(source);
508
465
this.keys = this.convertValues(source["keys"], Key);
@@ -524,7 +481,6 @@ func TestFixedArray(t *testing.T) {
524
481
converter := New ()
525
482
526
483
converter .AddType (reflect .TypeOf (Tmp {}))
527
- converter .CreateFromMethod = false
528
484
converter .BackupDir = ""
529
485
530
486
desiredResult := `export class Sub {
@@ -560,16 +516,11 @@ func TestAny(t *testing.T) {
560
516
converter := New ()
561
517
562
518
converter .AddType (reflect .TypeOf (Test {}))
563
- converter .CreateFromMethod = true
564
519
converter .BackupDir = ""
565
520
566
521
desiredResult := `export class Test {
567
522
field: any;
568
523
569
- static createFrom(source: any = {}) {
570
- return new Test(source);
571
- }
572
-
573
524
constructor(source: any = {}) {
574
525
if ('string' === typeof source) source = JSON.parse(source);
575
526
this.field = source["field"];
@@ -593,7 +544,6 @@ func TestTypeAlias(t *testing.T) {
593
544
converter := New ()
594
545
595
546
converter .AddType (reflect .TypeOf (Person {}))
596
- converter .CreateFromMethod = false
597
547
converter .BackupDir = ""
598
548
converter .CreateConstructor = false
599
549
@@ -622,7 +572,6 @@ func TestOverrideCustomType(t *testing.T) {
622
572
converter := New ()
623
573
624
574
converter .AddType (reflect .TypeOf (SomeStruct {}))
625
- converter .CreateFromMethod = false
626
575
converter .BackupDir = ""
627
576
converter .CreateConstructor = false
628
577
@@ -704,8 +653,7 @@ func TestEnum(t *testing.T) {
704
653
converter := New ().
705
654
AddType (reflect .TypeOf (Holliday {})).
706
655
AddEnum (allWeekdays ).
707
- WithConstructor (false ).
708
- WithCreateFromMethod (true ).
656
+ WithConstructor (true ).
709
657
WithBackupDir ("" )
710
658
711
659
desiredResult := `export enum Weekday {
@@ -721,10 +669,6 @@ export class Holliday {
721
669
name: string;
722
670
weekday: Weekday;
723
671
724
- static createFrom(source: any = {}) {
725
- return new Holliday(source);
726
- }
727
-
728
672
constructor(source: any = {}) {
729
673
if ('string' === typeof source) source = JSON.parse(source);
730
674
this.name = source["name"];
@@ -755,7 +699,6 @@ func TestEnumWithStringValues(t *testing.T) {
755
699
converter := New ().
756
700
AddEnum (allGenders ).
757
701
WithConstructor (false ).
758
- WithCreateFromMethod (false ).
759
702
WithBackupDir ("" )
760
703
761
704
desiredResult := `
@@ -773,7 +716,6 @@ func TestConstructorWithReferences(t *testing.T) {
773
716
AddType (reflect .TypeOf (Person {})).
774
717
AddEnum (allWeekdaysV2 ).
775
718
WithConstructor (true ).
776
- WithCreateFromMethod (false ).
777
719
WithBackupDir ("" )
778
720
779
721
desiredResult := `export enum Weekday {
@@ -839,7 +781,6 @@ func TestMaps(t *testing.T) {
839
781
converter := New ().
840
782
AddType (reflect .TypeOf (WithMap {})).
841
783
WithConstructor (true ).
842
- WithCreateFromMethod (false ).
843
784
WithBackupDir ("" )
844
785
845
786
desiredResult := `
@@ -895,7 +836,6 @@ func TestPTR(t *testing.T) {
895
836
}
896
837
897
838
converter := New ()
898
- converter .CreateFromMethod = false
899
839
converter .BackupDir = ""
900
840
converter .CreateConstructor = false
901
841
converter .Add (Person {})
@@ -918,7 +858,6 @@ func TestAnonymousPtr(t *testing.T) {
918
858
converter := New ().
919
859
AddType (reflect .TypeOf (PersonWithPtrName {})).
920
860
WithConstructor (true ).
921
- WithCreateFromMethod (false ).
922
861
WithBackupDir ("" )
923
862
924
863
desiredResult := `
@@ -992,7 +931,6 @@ func TestIgnoredPTR(t *testing.T) {
992
931
}
993
932
994
933
converter := New ()
995
- converter .CreateFromMethod = false
996
934
converter .BackupDir = ""
997
935
converter .Add (PersonWithIgnoredPtr {})
998
936
@@ -1022,10 +960,6 @@ func TestMapWithPrefix(t *testing.T) {
1022
960
export class prefix_Example {
1023
961
variable: {[key: string]: string};
1024
962
1025
- static createFrom(source: any = {}) {
1026
- return new prefix_Example(source);
1027
- }
1028
-
1029
963
constructor(source: any = {}) {
1030
964
if ('string' === typeof source) source = JSON.parse(source);
1031
965
this.variable = source["variable"];
0 commit comments