From 6ae81cba8fad9973a53a15e2fbf67835899dc3bc Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 1 Apr 2016 11:05:34 +0100 Subject: Add mangling when writing C# namespaces --- .../backends/csharp/CsharpSerializerTests.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/test/java') 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 b16c6b5..781d00a 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 @@ -56,6 +56,18 @@ public class CsharpSerializerTests { assertEquals("typeof(com.example.Example)", output); } + @Test + public void typeLiteralUsesAtSymbolToEscapeReservedIdentifiers() { + String output = serialize(literal(ScalarType.of("internal"))); + assertEquals("typeof(@internal)", output); + } + + @Test + public void typeLiteralDoesntUseAtSymbolForReservedTypeIdentifiers() { + String output = serialize(literal(ScalarType.of("string"))); + assertEquals("typeof(string)", output); + } + @Test public void variableReferenceWritesIdentifier() { String output = serialize(reference(var(TestIds.ANY_ID, "x", ScalarType.of("X")))); @@ -304,6 +316,26 @@ public class CsharpSerializerTests { assertEquals("namespace com.example {\n internal class Example {\n }\n}\n", output); } + @Test + public void namespacePartsInNamespaceDeclarationAreMangledInIfReserved() { + ClassNode classNode = ClassNode.builder("com.example.internal.Example") + .build(); + + String output = serialize(classNode); + + assertEquals("namespace com.example.@internal {\n internal class Example {\n }\n}\n", output); + } + + @Test + public void namespacePartsInNamespaceReferenceAreMangledInIfReserved() { + String output = serialize(localVariableDeclaration( + TestIds.ANY_ID, + "x", + ScalarType.of("com.example.internal.Example"), + literal("[value]"))); + assertEquals("com.example.@internal.Example x = \"[value]\";\n", output); + } + @Test public void classWithTypeParameters() { ClassNode classNode = ClassNode.builder("com.example.Example") -- cgit v1.2.3