Skip to content

Commit 0ce364c

Browse files
committed
Fix tests
1 parent 6ca0244 commit 0ce364c

File tree

3 files changed

+3
-93
lines changed

3 files changed

+3
-93
lines changed

browser_test/example_output.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ var Address = /** @class */ (function () {
1717
this.number = source["number"];
1818
this.country = source["country"];
1919
}
20-
Address.createFrom = function (source) {
21-
if (source === void 0) { source = {}; }
22-
return new Address(source);
23-
};
2420
return Address;
2521
}());
2622
exports.Address = Address;
@@ -37,10 +33,6 @@ var PersonalInfo = /** @class */ (function () {
3733
this.hobby = source["hobby"];
3834
this.pet_name = source["pet_name"];
3935
}
40-
PersonalInfo.createFrom = function (source) {
41-
if (source === void 0) { source = {}; }
42-
return new PersonalInfo(source);
43-
};
4436
return PersonalInfo;
4537
}());
4638
exports.PersonalInfo = PersonalInfo;
@@ -62,10 +54,6 @@ var Person = /** @class */ (function () {
6254
this.metadata = source["metadata"];
6355
this.friends = this.convertValues(source["friends"], Person);
6456
}
65-
Person.createFrom = function (source) {
66-
if (source === void 0) { source = {}; }
67-
return new Person(source);
68-
};
6957
Person.prototype.convertValues = function (a, classs, asMap) {
7058
var _this = this;
7159
if (asMap === void 0) { asMap = false; }

browser_test/example_output.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ export class Address {
66
number: number;
77
country?: string;
88

9-
static createFrom(source: any = {}) {
10-
return new Address(source);
11-
}
12-
139
constructor(source: any = {}) {
1410
if ('string' === typeof source) source = JSON.parse(source);
1511
this.city = source["city"];
@@ -29,10 +25,6 @@ export class PersonalInfo {
2925
hobby: string[];
3026
pet_name: string;
3127

32-
static createFrom(source: any = {}) {
33-
return new PersonalInfo(source);
34-
}
35-
3628
constructor(source: any = {}) {
3729
if ('string' === typeof source) source = JSON.parse(source);
3830
this.hobby = source["hobby"];
@@ -55,10 +47,6 @@ export class Person {
5547
metadata: {[key:string]:string};
5648
friends: Person[];
5749

58-
static createFrom(source: any = {}) {
59-
return new Person(source);
60-
}
61-
6250
constructor(source: any = {}) {
6351
if ('string' === typeof source) source = JSON.parse(source);
6452
this.name = source["name"];

typescriptify/typescriptify_test.go

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func TestTypescriptifyWithTypes(t *testing.T) {
4646
converter := New()
4747

4848
converter.AddType(reflect.TypeOf(Person{}))
49-
converter.CreateFromMethod = false
5049
converter.CreateConstructor = false
5150
converter.BackupDir = ""
5251

@@ -74,7 +73,6 @@ func TestTypescriptifyWithCustomImports(t *testing.T) {
7473
converter := New()
7574

7675
converter.AddType(reflect.TypeOf(Person{}))
77-
converter.CreateFromMethod = false
7876
converter.BackupDir = ""
7977
converter.AddImport("//import { Decimal } from 'decimal.js'")
8078
converter.CreateConstructor = false
@@ -107,7 +105,6 @@ func TestTypescriptifyWithInstances(t *testing.T) {
107105

108106
converter.Add(Person{})
109107
converter.Add(Dummy{})
110-
converter.CreateFromMethod = false
111108
converter.DontExport = true
112109
converter.BackupDir = ""
113110
converter.CreateConstructor = false
@@ -137,7 +134,6 @@ func TestTypescriptifyWithInterfaces(t *testing.T) {
137134

138135
converter.Add(Person{})
139136
converter.Add(Dummy{})
140-
converter.CreateFromMethod = false
141137
converter.DontExport = true
142138
converter.BackupDir = ""
143139
converter.CreateInterface = true
@@ -167,7 +163,6 @@ func TestTypescriptifyWithDoubleClasses(t *testing.T) {
167163

168164
converter.AddType(reflect.TypeOf(Person{}))
169165
converter.AddType(reflect.TypeOf(Person{}))
170-
converter.CreateFromMethod = false
171166
converter.CreateConstructor = false
172167
converter.BackupDir = ""
173168

@@ -198,18 +193,12 @@ func TestWithPrefixes(t *testing.T) {
198193
converter.Suffix = "_test"
199194

200195
converter.Add(Person{})
201-
converter.CreateFromMethod = false
202196
converter.DontExport = true
203197
converter.BackupDir = ""
204-
converter.CreateFromMethod = true
205198

206199
desiredResult := `class test_Dummy_test {
207200
something: string;
208201
209-
static createFrom(source: any = {}) {
210-
return new test_Dummy_test(source);
211-
}
212-
213202
constructor(source: any = {}) {
214203
if ('string' === typeof source) source = JSON.parse(source);
215204
this.something = source["something"];
@@ -219,10 +208,6 @@ class test_Address_test {
219208
duration: number;
220209
text?: string;
221210
222-
static createFrom(source: any = {}) {
223-
return new test_Address_test(source);
224-
}
225-
226211
constructor(source: any = {}) {
227212
if ('string' === typeof source) source = JSON.parse(source);
228213
this.duration = source["duration"];
@@ -238,10 +223,6 @@ class test_Person_test {
238223
friends: test_Person_test[];
239224
a: test_Dummy_test;
240225
241-
static createFrom(source: any = {}) {
242-
return new test_Person_test(source);
243-
}
244-
245226
constructor(source: any = {}) {
246227
if ('string' === typeof source) source = JSON.parse(source);
247228
this.name = source["name"];
@@ -281,6 +262,8 @@ func testConverter(t *testing.T, converter *TypeScriptify, strictMode bool, desi
281262
panic(err.Error())
282263
}
283264

265+
fmt.Println("----------------------------------------------------------------------------------------------------")
266+
fmt.Println(desiredResult)
284267
fmt.Println("----------------------------------------------------------------------------------------------------")
285268
fmt.Println(typeScriptCode)
286269
fmt.Println("----------------------------------------------------------------------------------------------------")
@@ -356,7 +339,6 @@ func TestTypescriptifyCustomType(t *testing.T) {
356339
converter := New()
357340

358341
converter.AddType(reflect.TypeOf(TestCustomType{}))
359-
converter.CreateFromMethod = false
360342
converter.BackupDir = ""
361343
converter.CreateConstructor = false
362344

@@ -374,16 +356,11 @@ func TestDate(t *testing.T) {
374356

375357
converter := New()
376358
converter.AddType(reflect.TypeOf(TestCustomType{}))
377-
converter.CreateFromMethod = true
378359
converter.BackupDir = ""
379360

380361
desiredResult := `export class TestCustomType {
381362
time: Date;
382363
383-
static createFrom(source: any = {}) {
384-
return new TestCustomType(source);
385-
}
386-
387364
constructor(source: any = {}) {
388365
if ('string' === typeof source) source = JSON.parse(source);
389366
this.time = new Date(source["time"]);
@@ -407,24 +384,18 @@ func TestDateWithoutTags(t *testing.T) {
407384
// Test with custom field options defined per-one-struct:
408385
converter1 := New()
409386
converter1.Add(NewStruct(TestCustomType{}).WithFieldOpts(time.Time{}, TypeOptions{TSType: "Date", TSTransform: "new Date(__VALUE__)"}))
410-
converter1.CreateFromMethod = true
411387
converter1.BackupDir = ""
412388

413389
// Test with custom field options defined globally:
414390
converter2 := New()
415391
converter2.Add(reflect.TypeOf(TestCustomType{}))
416392
converter2.ManageType(time.Time{}, TypeOptions{TSType: "Date", TSTransform: "new Date(__VALUE__)"})
417-
converter2.CreateFromMethod = true
418393
converter2.BackupDir = ""
419394

420395
for _, converter := range []*TypeScriptify{converter1, converter2} {
421396
desiredResult := `export class TestCustomType {
422397
time: Date;
423398
424-
static createFrom(source: any = {}) {
425-
return new TestCustomType(source);
426-
}
427-
428399
constructor(source: any = {}) {
429400
if ('string' === typeof source) source = JSON.parse(source);
430401
this.time = new Date(source["time"]);
@@ -449,16 +420,11 @@ func TestRecursive(t *testing.T) {
449420
converter := New()
450421

451422
converter.AddType(reflect.TypeOf(Test{}))
452-
converter.CreateFromMethod = true
453423
converter.BackupDir = ""
454424

455425
desiredResult := `export class Test {
456426
children: Test[];
457427
458-
static createFrom(source: any = {}) {
459-
return new Test(source);
460-
}
461-
462428
constructor(source: any = {}) {
463429
if ('string' === typeof source) source = JSON.parse(source);
464430
this.children = this.convertValues(source["children"], Test);
@@ -481,16 +447,11 @@ func TestArrayOfArrays(t *testing.T) {
481447
converter := New()
482448

483449
converter.AddType(reflect.TypeOf(Keyboard{}))
484-
converter.CreateFromMethod = true
485450
converter.BackupDir = ""
486451

487452
desiredResult := `export class Key {
488453
key: string;
489454
490-
static createFrom(source: any = {}) {
491-
return new Key(source);
492-
}
493-
494455
constructor(source: any = {}) {
495456
if ('string' === typeof source) source = JSON.parse(source);
496457
this.key = source["key"];
@@ -499,10 +460,6 @@ func TestArrayOfArrays(t *testing.T) {
499460
export class Keyboard {
500461
keys: Key[][];
501462
502-
static createFrom(source: any = {}) {
503-
return new Keyboard(source);
504-
}
505-
506463
constructor(source: any = {}) {
507464
if ('string' === typeof source) source = JSON.parse(source);
508465
this.keys = this.convertValues(source["keys"], Key);
@@ -524,7 +481,6 @@ func TestFixedArray(t *testing.T) {
524481
converter := New()
525482

526483
converter.AddType(reflect.TypeOf(Tmp{}))
527-
converter.CreateFromMethod = false
528484
converter.BackupDir = ""
529485

530486
desiredResult := `export class Sub {
@@ -560,16 +516,11 @@ func TestAny(t *testing.T) {
560516
converter := New()
561517

562518
converter.AddType(reflect.TypeOf(Test{}))
563-
converter.CreateFromMethod = true
564519
converter.BackupDir = ""
565520

566521
desiredResult := `export class Test {
567522
field: any;
568523
569-
static createFrom(source: any = {}) {
570-
return new Test(source);
571-
}
572-
573524
constructor(source: any = {}) {
574525
if ('string' === typeof source) source = JSON.parse(source);
575526
this.field = source["field"];
@@ -593,7 +544,6 @@ func TestTypeAlias(t *testing.T) {
593544
converter := New()
594545

595546
converter.AddType(reflect.TypeOf(Person{}))
596-
converter.CreateFromMethod = false
597547
converter.BackupDir = ""
598548
converter.CreateConstructor = false
599549

@@ -622,7 +572,6 @@ func TestOverrideCustomType(t *testing.T) {
622572
converter := New()
623573

624574
converter.AddType(reflect.TypeOf(SomeStruct{}))
625-
converter.CreateFromMethod = false
626575
converter.BackupDir = ""
627576
converter.CreateConstructor = false
628577

@@ -704,8 +653,7 @@ func TestEnum(t *testing.T) {
704653
converter := New().
705654
AddType(reflect.TypeOf(Holliday{})).
706655
AddEnum(allWeekdays).
707-
WithConstructor(false).
708-
WithCreateFromMethod(true).
656+
WithConstructor(true).
709657
WithBackupDir("")
710658

711659
desiredResult := `export enum Weekday {
@@ -721,10 +669,6 @@ export class Holliday {
721669
name: string;
722670
weekday: Weekday;
723671
724-
static createFrom(source: any = {}) {
725-
return new Holliday(source);
726-
}
727-
728672
constructor(source: any = {}) {
729673
if ('string' === typeof source) source = JSON.parse(source);
730674
this.name = source["name"];
@@ -755,7 +699,6 @@ func TestEnumWithStringValues(t *testing.T) {
755699
converter := New().
756700
AddEnum(allGenders).
757701
WithConstructor(false).
758-
WithCreateFromMethod(false).
759702
WithBackupDir("")
760703

761704
desiredResult := `
@@ -773,7 +716,6 @@ func TestConstructorWithReferences(t *testing.T) {
773716
AddType(reflect.TypeOf(Person{})).
774717
AddEnum(allWeekdaysV2).
775718
WithConstructor(true).
776-
WithCreateFromMethod(false).
777719
WithBackupDir("")
778720

779721
desiredResult := `export enum Weekday {
@@ -839,7 +781,6 @@ func TestMaps(t *testing.T) {
839781
converter := New().
840782
AddType(reflect.TypeOf(WithMap{})).
841783
WithConstructor(true).
842-
WithCreateFromMethod(false).
843784
WithBackupDir("")
844785

845786
desiredResult := `
@@ -895,7 +836,6 @@ func TestPTR(t *testing.T) {
895836
}
896837

897838
converter := New()
898-
converter.CreateFromMethod = false
899839
converter.BackupDir = ""
900840
converter.CreateConstructor = false
901841
converter.Add(Person{})
@@ -918,7 +858,6 @@ func TestAnonymousPtr(t *testing.T) {
918858
converter := New().
919859
AddType(reflect.TypeOf(PersonWithPtrName{})).
920860
WithConstructor(true).
921-
WithCreateFromMethod(false).
922861
WithBackupDir("")
923862

924863
desiredResult := `
@@ -992,7 +931,6 @@ func TestIgnoredPTR(t *testing.T) {
992931
}
993932

994933
converter := New()
995-
converter.CreateFromMethod = false
996934
converter.BackupDir = ""
997935
converter.Add(PersonWithIgnoredPtr{})
998936

@@ -1022,10 +960,6 @@ func TestMapWithPrefix(t *testing.T) {
1022960
export class prefix_Example {
1023961
variable: {[key: string]: string};
1024962
1025-
static createFrom(source: any = {}) {
1026-
return new prefix_Example(source);
1027-
}
1028-
1029963
constructor(source: any = {}) {
1030964
if ('string' === typeof source) source = JSON.parse(source);
1031965
this.variable = source["variable"];

0 commit comments

Comments
 (0)