Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ public void EndValue(in ValueDesc desc)
WriteLine(';');
}
}
else
{
WriteLine(';');
}
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. 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 sealed class GlobalStructInitializerTest : PInvokeGeneratorTest
{
// Regression test for https://github.com/dotnet/clangsharp/issues/503
// A non-const global variable initialized with a struct initializer list was
// missing its terminating semicolon, which corrupted the rest of the file.
[Test]
public Task NonConstGlobalTest()
{
var inputContents = @"typedef struct Point { int x; int y; } Point;

Point MyGlobalPoint = { .x = 10, .y = 20 };
";

var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct Point
{
public int x;

public int y;
}

public static partial class Methods
{
public static Point MyGlobalPoint = new Point
{
x = 10,
y = 20,
};
}
}
";

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents);
}
}
Loading