-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSharpToCppTransformerTests.cs
More file actions
78 lines (70 loc) · 2.59 KB
/
Copy pathCSharpToCppTransformerTests.cs
File metadata and controls
78 lines (70 loc) · 2.59 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
69
70
71
72
73
74
75
76
77
78
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 ExplicitConstructorTest()
{
const string csharpCode = @"class Range<T>
{
public Range(T value) => { _value = value; };
public static implicit operator Range<T>(T value) { return new Range<T>(value); }
}";
var transformer = new CSharpToCppTransformer();
var actualResult = transformer.Transform(csharpCode);
// For debugging - output the actual result
System.Console.WriteLine("=== ACTUAL RESULT ===");
System.Console.WriteLine(actualResult);
System.Console.WriteLine("=== END ACTUAL RESULT ===");
// Let's just check if explicit is present for now
Assert.Contains("explicit", actualResult);
}
[Fact]
public void ExplicitOperatorTest()
{
const string csharpCode = @"class Range<T>
{
public static implicit operator std::tuple<T, T>(Range<T> range) { return (range.Min, range.Max); }
}";
var transformer = new CSharpToCppTransformer();
var actualResult = transformer.Transform(csharpCode);
// For debugging - output the actual result
System.Console.WriteLine("=== ACTUAL OPERATOR RESULT ===");
System.Console.WriteLine(actualResult);
System.Console.WriteLine("=== END ACTUAL OPERATOR RESULT ===");
// Let's just check if explicit is present for now
Assert.Contains("explicit operator", actualResult);
}
}
}