Skip to content

Commit

Permalink
can parse type members (functions / variables) now
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Mar 21, 2016
1 parent ecf7dee commit e53eaa3
Show file tree
Hide file tree
Showing 4 changed files with 399 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class EntityDialog<TEntity>
}");

Assert.Equal(1, types.Count);
Assert.Equal("EntityDialog<TEntity>", types[0].Name);
var t0 = types[0];
Assert.Equal("EntityDialog<TEntity>", t0.Name);
Assert.Equal(2, t0.Members.Count);
}

[Fact]
Expand Down
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;
}
}
}";
}
}
1 change: 1 addition & 0 deletions Serenity.Test/Serenity.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CodeGeneration\TypeScriptParserTests\TypeScriptParserTests_Lookup.cs" />
<Compile Include="CodeGeneration\TypeScriptParserTests\TypeScriptParserTests_Declaration.cs" />
<Compile Include="CodeGeneration\TypeScriptParserTests\TypeScriptParserTests_InterfaceDialogFormatter.cs" />
<Compile Include="Core\Config\AppSettingsJsonConfigRepositoryTests.cs" />
Expand Down
Loading

0 comments on commit e53eaa3

Please sign in to comment.