-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSharpToCppTransformerTests.cs
More file actions
68 lines (62 loc) · 1.98 KB
/
Copy pathCSharpToCppTransformerTests.cs
File metadata and controls
68 lines (62 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Xunit;
namespace Platform.RegularExpressions.Transformer.CSharpToCpp.Tests
{
public class CSharpToCppTransformerTests
{
[Fact]
public void EmptyLineTest()
{
// This test can help to test basic problems with regular expressions like incorrect syntax
var transformer = new CSharpToCppTransformer();
var actualResult = transformer.Transform("");
Assert.Equal("", actualResult);
}
[Fact]
public void HelloWorldTest()
{
const string helloWorldCode = @"using System;
class Program
{
public static void Main(string[] args)
{
Console.WriteLine(""Hello, world!"");
}
}";
const string expectedResult = @"class Program
{
public: static void Main(std::string args[])
{
printf(""Hello, world!\n"");
}
};";
var transformer = new CSharpToCppTransformer();
var actualResult = transformer.Transform(helloWorldCode);
Assert.Equal(expectedResult, actualResult);
}
[Fact]
public void SafeHashSpecializationTest()
{
const string inputCode = @"
namespace Platform.Ranges
{
template <typename T> struct Range
{
T Minimum;
T Maximum;
public: override std::int32_t GetHashCode()
{
return {Minimum, Maximum}.GetHashCode();
}
};
}";
var transformer = new CSharpToCppTransformer();
var actualResult = transformer.Transform(inputCode);
// Should generate safe specialization syntax
Assert.Contains("template <typename T>", actualResult);
Assert.Contains("struct std::hash<Platform::Ranges::Range<T>>", actualResult);
// Should NOT contain unsafe namespace std opening
Assert.DoesNotContain("namespace std\n{", actualResult);
Assert.DoesNotContain("namespace std {", actualResult);
}
}
}