-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
can parse type members (functions / variables) now
- Loading branch information
1 parent
ecf7dee
commit e53eaa3
Showing
4 changed files
with
399 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Serenity.Test/CodeGeneration/TypeScriptParserTests/TypeScriptParserTests_Lookup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Serenity.CodeGeneration.Test | ||
{ | ||
public partial class TypeScriptParserTests | ||
{ | ||
[Fact] | ||
public void CanParseMembers() | ||
{ | ||
var parser = new TypeScriptParser(); | ||
var types = new List<TypeScriptParser.TypeInfo>(); | ||
|
||
parser.ReportType += (type) => | ||
{ | ||
types.Add(type); | ||
}; | ||
|
||
parser.Parse(Input_Lookup); | ||
|
||
Assert.Equal(1, types.Count); | ||
|
||
var t0 = types[0]; | ||
Assert.Equal("Lookup<TItem>", t0.Name); | ||
Assert.False(t0.IsDeclaration); | ||
Assert.Equal("Serenity", t0.Namespace.Name); | ||
Assert.False(t0.Namespace.IsDeclaration); | ||
|
||
Assert.Equal(6, t0.Members.Count); | ||
} | ||
|
||
public const string Input_Lookup = @" | ||
namespace Serenity { | ||
export class Lookup<TItem> { | ||
private items: TItem[] = []; | ||
private itemById?: { [key: string]: TItem } = {}; | ||
constructor(private options: LookupOptions<TItem>, items?: TItem[]) { | ||
if (items != null) | ||
this.update(items); | ||
} | ||
update(value: TItem[]) { | ||
this.items = []; | ||
this.itemById = {}; | ||
if (value) { | ||
for (var k of value) | ||
this.items.push(k); | ||
} | ||
var idField = this.options.idField; | ||
if (!Q.isEmptyOrNull(idField)) { | ||
for (var r of this.items) { | ||
var v = r[idField]; | ||
if (v != null) { | ||
this.itemById[v] = r; | ||
} | ||
} | ||
} | ||
} | ||
public get_idField() { | ||
return this.options.idField; | ||
} | ||
protected get_parentIdField() { | ||
return this.options.parentIdField; | ||
} | ||
} | ||
}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.