forked from paulirwin/JavaToCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentTests.cs
More file actions
105 lines (85 loc) · 3.58 KB
/
Copy pathCommentTests.cs
File metadata and controls
105 lines (85 loc) · 3.58 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using Microsoft.CodeAnalysis.CSharp;
using Xunit.Abstractions;
namespace JavaToCSharp.Tests;
public class CommentTests(ITestOutputHelper testOutputHelper)
{
[Fact]
public void CommentsBeforePackage_ShouldRemainAtTopOfFile()
{
const string javaCode = """
// 1 comment
// 2 comment
// Red comment
// Blue comment
package com.example.code;
import java.something.Bar;
public class Foo {
}
""";
var options = new JavaConversionOptions
{
StartInterfaceNamesWithI = true,
};
options.Usings.Clear();
var parsed = JavaToCSharpConverter.ConvertText(javaCode, options) ?? "";
testOutputHelper.WriteLine(parsed);
const string expected = """
// 1 comment
// 2 comment
// Red comment
// Blue comment
using Java.Something;
namespace Com.Example.Code
{
public class Foo
{
}
}
""";
Assert.Equal(expected.ReplaceLineEndings(), parsed.ReplaceLineEndings());
}
[Fact]
public void CommentsBeforePackage_ShouldRemainAtTopOfFile_WithUsings()
{
const string javaCode = """
// 1 comment
// 2 comment
// Red comment
// Blue comment
package com.example.code;
// Import some package
import java.something.Bar;
// Import some other package
import java.something.other.Baz;
// Define some class
public class Foo {
}
""";
var options = new JavaConversionOptions
{
StartInterfaceNamesWithI = true,
};
options.Usings.Clear();
var parsed = JavaToCSharpConverter.ConvertText(javaCode, options) ?? "";
testOutputHelper.WriteLine(parsed);
// TODO.PI: improve whitespace
const string expected = """
// 1 comment
// 2 comment
// Red comment
// Blue comment
// Import some package
using Java.Something;
// Import some other package
using Java.Something.Other;
namespace Com.Example.Code
{
// Define some class
public class Foo
{
}
}
""";
Assert.Equal(expected.ReplaceLineEndings(), parsed.ReplaceLineEndings());
}
}