-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from nenoNaninu/support_partial_class
Support partial class
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 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
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,12 @@ | ||
namespace Tapper.Test.SourceTypes; | ||
|
||
[TranspilationSource] | ||
public partial class PartialClass | ||
{ | ||
public int Value1 { get; set; } | ||
} | ||
|
||
public partial class PartialClass | ||
{ | ||
public int Value2 { get; set; } | ||
} |
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
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,56 @@ | ||
using Tapper.Test.SourceTypes; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Tapper.Tests; | ||
|
||
public class PartialClassTest | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public PartialClassTest(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public void Test() | ||
{ | ||
var compilation = CompilationSingleton.Compilation; | ||
|
||
var options = new TranspilationOptions( | ||
compilation, | ||
SerializerOption.Json, | ||
NamingStyle.CamelCase, | ||
EnumStyle.Value, | ||
NewLineOption.Lf, | ||
2, | ||
false, | ||
true | ||
); | ||
|
||
var codeGenerator = new TypeScriptCodeGenerator(compilation, options); | ||
|
||
var type = typeof(PartialClass); | ||
var typeSymbol = compilation.GetTypeByMetadataName(type.FullName!)!; | ||
|
||
var writer = new CodeWriter(); | ||
|
||
codeGenerator.AddType(typeSymbol, ref writer); | ||
|
||
var code = writer.ToString(); | ||
var gt = @"/** Transpiled from Tapper.Test.SourceTypes.PartialClass */ | ||
export type PartialClass = { | ||
/** Transpiled from int */ | ||
value1: number; | ||
/** Transpiled from int */ | ||
value2: number; | ||
} | ||
"; | ||
|
||
_output.WriteLine(code); | ||
_output.WriteLine(gt); | ||
|
||
Assert.Equal(gt, code, ignoreLineEndingDifferences: true); | ||
} | ||
} |