aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-04-01 10:50:28 +0100
committerMichael Williamson <mike@zwobble.org>2016-04-01 10:50:28 +0100
commitd1e7efbf5adab7516a19fd35c9fa9a3fdca2e769 (patch)
treeb767d5de3b8953b0c773d1228c1c285d0f2776e2 /src/test/java/org
parente855df09f88d1e18e99d8a1d8be75fb944a19a99 (diff)
Mangle reserved identifiers in C# backend
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/csharp/CsharpSerializerTests.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/csharp/CsharpSerializerTests.java b/src/test/java/org/zwobble/couscous/tests/backends/csharp/CsharpSerializerTests.java
index 89cb9c1..b16c6b5 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/csharp/CsharpSerializerTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/csharp/CsharpSerializerTests.java
@@ -63,6 +63,12 @@ public class CsharpSerializerTests {
}
@Test
+ public void identifierIsEscapedWithAtSymbolIfItsAReservedWord() {
+ String output = serialize(reference(var(TestIds.ANY_ID, "internal", ScalarType.of("X"))));
+ assertEquals("@internal", output);
+ }
+
+ @Test
public void thisReferenceUsesThisKeyword() {
String output = serialize(thisReference(ScalarType.of("X")));
assertEquals("this", output);
@@ -194,6 +200,16 @@ public class CsharpSerializerTests {
String output = serialize(localVariableDeclaration(
TestIds.ANY_ID,
"x",
+ ScalarType.of("X"),
+ literal("[value]")));
+ assertEquals("X x = \"[value]\";\n", output);
+ }
+
+ @Test
+ public void builtinTypesAreNotMangled() {
+ String output = serialize(localVariableDeclaration(
+ TestIds.ANY_ID,
+ "x",
ScalarType.of("string"),
literal("[value]")));
assertEquals("string x = \"[value]\";\n", output);
@@ -384,14 +400,14 @@ public class CsharpSerializerTests {
@Test
public void interfaceWithMethod() {
- MethodNode method = MethodNode.builder("get").isAbstract().returns(Types.INT).build();
+ MethodNode method = MethodNode.builder("get").isAbstract().returns(ScalarType.of("X")).build();
Node node = new ClassNodeBuilder(ScalarType.of("com.example.Example"))
.method(method)
.buildInterface();
String output = serialize(node);
- assertEquals("namespace com.example {\n internal interface Example {\n int get();\n }\n}\n", output);
+ assertEquals("namespace com.example {\n internal interface Example {\n X get();\n }\n}\n", output);
}
private String serialize(Node node) {