diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs index f6d52daa..c8ef5432 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Globalization; using System.Text; +using ClangSharp.Abstractions; namespace ClangSharp.CSharp; @@ -129,6 +130,20 @@ public void WriteLabel(string name) WriteLine(':'); } + public void WriteNumberLiteral(ReadOnlySpan value) + { + var index = value.IndexOf('\''); + while (index != -1) + { + var part = value[..index]; + Write(part); + Write(['_']); + value = value[(index + 1)..]; + index = value.IndexOf('\''); + } + Write(value); + } + public void WriteLine(T value) { Write(value); diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index 5eaf6372..a8919c77 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -265,7 +265,7 @@ private void VisitCallExpr(CallExpr callExpr) outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); outputBuilder.Write("Unsafe.CopyBlockUnaligned"); } - + VisitArgs(callExpr, args); break; } @@ -1163,7 +1163,7 @@ private void VisitExplicitCastExpr(ExplicitCastExpr explicitCastExpr) { var cursorName = GetCursorName(varDecl); - if (cursorName.StartsWith("ClangSharpMacro_", StringComparison.Ordinal) && _config.WithTransparentStructs.TryGetValue(typeName, out var transparentStruct)) + if (cursorName.StartsWith("ClangSharpMacro_", StringComparison.Ordinal) && _config.WithTransparentStructs.TryGetValue(typeName, out var transparentStruct)) { if (!IsPrimitiveValue(explicitCastExpr, type) || IsConstant(typeName, varDecl.Init)) { @@ -1201,12 +1201,12 @@ private void VisitFloatingLiteral(FloatingLiteral floatingLiteral) var outputBuilder = StartCSharpCode(); if (floatingLiteral.ValueString.EndsWith(".f", StringComparison.Ordinal)) { - outputBuilder.Write(floatingLiteral.ValueString.AsSpan()[..^1]); + outputBuilder.WriteNumberLiteral(floatingLiteral.ValueString.AsSpan()[..^1]); outputBuilder.Write("0f"); } else { - outputBuilder.Write(floatingLiteral.ValueString); + outputBuilder.WriteNumberLiteral(floatingLiteral.ValueString); if (floatingLiteral.ValueString.EndsWith('.')) { @@ -2060,9 +2060,9 @@ private void VisitIntegerLiteral(IntegerLiteral integerLiteral) { valueString = valueString[..^1]; } - + var outputBuilder = StartCSharpCode(); - outputBuilder.Write(valueString); + outputBuilder.WriteNumberLiteral(valueString); outputBuilder.Write(valueSuffix); StopCSharpCode(); } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/DigitsSeparatorTest.cs new file mode 100644 index 00000000..baffbb92 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/DigitsSeparatorTest.cs @@ -0,0 +1,17 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests; + +public abstract class DigitsSeparatorTest : PInvokeGeneratorTest +{ + [TestCase("int", "1'024", "1_024")] + [TestCase("int", "1'000'001", "1_000_001")] + [TestCase("float", "1'024", "1_024")] + [TestCase("float", "1'024.0", "1_024.0")] + public Task StaticConstExprTest(string type, string nativeValue, string expectedValue) => StaticConstExprTestImpl(type, nativeValue, expectedValue); + + protected abstract Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue); +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..b415d8c1 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpCompatibleUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpCompatibleUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..0301621b --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpCompatibleWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..91a4ab4f --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpDefaultUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpDefaultUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..c54271e8 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpDefaultWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpDefaultWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..b835ab0e --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpLatestUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpLatestUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..a1d1fd84 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpLatestWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpLatestWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..17dd8cc7 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewUnix/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpPreviewUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpPreviewUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..191823be --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpPreviewWindows/DigitsSeparatorTest.cs @@ -0,0 +1,35 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.CSharpPreviewWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@"namespace ClangSharp.Test +{{ + public partial struct MyClass + {{ + [NativeTypeName(""const {type}"")] + private const {type} x = {expectedValue}; + }} +}} +"; + + return ValidateGeneratedCSharpPreviewWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..81b04cc5 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/DigitsSeparatorTest.cs @@ -0,0 +1,40 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlCompatibleUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + + return ValidateGeneratedXmlCompatibleUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..ba97af4f --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/DigitsSeparatorTest.cs @@ -0,0 +1,40 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlCompatibleWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + + return ValidateGeneratedXmlCompatibleWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..156044c1 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/DigitsSeparatorTest.cs @@ -0,0 +1,40 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlDefaultUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + + return ValidateGeneratedXmlDefaultUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..6cecde9a --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/DigitsSeparatorTest.cs @@ -0,0 +1,39 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlDefaultWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + return ValidateGeneratedXmlDefaultWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..a50d5265 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/DigitsSeparatorTest.cs @@ -0,0 +1,39 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlLatestUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + return ValidateGeneratedXmlLatestUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..0193daf6 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/DigitsSeparatorTest.cs @@ -0,0 +1,40 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlLatestWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + + return ValidateGeneratedXmlLatestWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/DigitsSeparatorTest.cs new file mode 100644 index 00000000..ff12778e --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewUnix/DigitsSeparatorTest.cs @@ -0,0 +1,40 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlPreviewUnix; + +[Platform("unix")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + + return ValidateGeneratedXmlPreviewUnixBindingsAsync( + inputContents, + expectedOutputContents); + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/DigitsSeparatorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/DigitsSeparatorTest.cs new file mode 100644 index 00000000..c8d82564 --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlPreviewWindows/DigitsSeparatorTest.cs @@ -0,0 +1,40 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests.XmlPreviewWindows; + +[Platform("win")] +public sealed class DigitsSeparatorTest : UnitTests.DigitsSeparatorTest +{ + protected override Task StaticConstExprTestImpl(string type, string nativeValue, string expectedValue) + { + var inputContents = $@"class MyClass +{{ + private: + + static constexpr {type} x = {nativeValue}; +}}; +"; + + var expectedOutputContents = $@" + + + + + {type} + + {expectedValue} + + + + + +"; + + return ValidateGeneratedXmlPreviewWindowsBindingsAsync( + inputContents, + expectedOutputContents); + } +}