-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More updates and additional functionality added
- Loading branch information
1 parent
1f6dc52
commit 6c15a11
Showing
5 changed files
with
97 additions
and
8 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
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,27 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace TypeScript.TypeConverter; | ||
|
||
static class TypeMap | ||
{ | ||
internal static readonly Primitives PrimitiveTypes = new(); | ||
|
||
internal class Primitives | ||
{ | ||
internal static readonly Dictionary<string, string> _primitiveTypeMap = | ||
new(StringComparer.OrdinalIgnoreCase) | ||
{ | ||
// The JavaScript Number type is a double-precision 64-bit binary format IEEE 754 value | ||
["number"] = "double", | ||
["string"] = "string", | ||
["boolean"] = "bool", | ||
["enum"] = "enum", | ||
["Date"] = "DateTime", | ||
//["Array"] = "[]" | ||
}; | ||
|
||
internal string this[string typeScriptType] => | ||
_primitiveTypeMap.TryGetValue(typeScriptType, out var csharpType) ? csharpType : typeScriptType; | ||
} | ||
} |
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,45 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics; | ||
using Xunit; | ||
|
||
namespace TypeScript.TypeConverter.Tests; | ||
|
||
public class LibDomParserTests | ||
{ | ||
[Fact] | ||
public async Task InitializesTypeDefinitionsCorrectly() | ||
{ | ||
var stopwatch = Stopwatch.StartNew(); | ||
var sut = new LibDomParser(); | ||
|
||
await sut.InitializeAsync(); | ||
stopwatch.Stop(); | ||
|
||
Assert.True(sut.IsInitialized); | ||
Assert.True(stopwatch.Elapsed < TimeSpan.FromSeconds(1.5)); | ||
} | ||
|
||
[Fact] | ||
public async Task TryParseDefinitionCorrectly() | ||
{ | ||
var sut = new LibDomParser(); | ||
|
||
await sut.InitializeAsync(); | ||
|
||
var expected = @"namespace Microsoft.JSInterop; | ||
public record PositionOptions( | ||
bool? EnableHighAccuracy, | ||
double? MaximumAge, | ||
double? Timeout | ||
); | ||
"; | ||
|
||
var result = sut.TryParseType("PositionOptions", false, out var actual); | ||
|
||
Assert.True(result); | ||
Assert.Equal(expected, actual); | ||
} | ||
} |