public void NestedClassesWork() { Compile(@"class TestClass1 { class TestClass2 { class TestClass3 { } } class TestClass4 {} }"); CompiledTypes.Select(t => t.CSharpTypeDefinition.FullName).Should().BeEquivalentTo(new[] { "TestClass1", "TestClass1.TestClass2", "TestClass1.TestClass2.TestClass3", "TestClass1.TestClass4", }); CompiledTypes.Should().ContainItemsAssignableTo <JsClass>(); }
public void TakenIfWorks() { Compile(new[] { @" class A {} #if true class B {} #endif " }); CompiledTypes.Select(t => t.Name).Should().BeEquivalentTo(new[] { "A", "B" }); }
public void UndefWorks() { Compile(new[] { @" #undef MY_SYMBOL class A {} #if MY_SYMBOL class B {} #endif " }, defineConstants: new[] { "MY_SYMBOL" }); CompiledTypes.Select(t => t.Name).Should().BeEquivalentTo(new[] { "A" }); }
public void DefineWorks() { Compile(new[] { @" #define MY_SYMBOL class A {} #if MY_SYMBOL class B {} #endif " }); CompiledTypes.Select(t => t.Name).Should().BeEquivalentTo(new[] { "A", "B" }); }
public void TakenElseWorks() { Compile(new[] { @" class A {} #if false class B {} #else class C {} #endif " }); CompiledTypes.Select(t => t.Name).Should().BeEquivalentTo(new[] { "A", "C" }); }
public void NotTakenIfWorks() { Compile(new[] { @" class A {} #if false class B {} #endif " }); CompiledTypes.Select(t => t.CSharpTypeDefinition.Name).Should().BeEquivalentTo(new[] { "A" }); }
public void PassingDefineConstantsWorks() { Compile(new[] { @" class A {} #if MY_SYMBOL1 class B {} #endif #if MY_SYMBOL2 class B {} #endif " }, defineConstants: new[] { "MY_SYMBOL1" }); CompiledTypes.Select(t => t.Name).Should().BeEquivalentTo(new[] { "A", "B" }); }
public void ClassesWithGenerateCodeSetToFalseAndTheirNestedClassesAreNotInTheOutput() { var metadataImporter = new MockMetadataImporter { GetTypeSemantics = type => TypeScriptSemantics.NormalType(type.Name, generateCode: type.Name != "C2") }; Compile(new[] { "class C1 {} class C2 { class C3 {} }" }, metadataImporter: metadataImporter); CompiledTypes.Select(t => t.CSharpTypeDefinition.Name).Should().BeEquivalentTo(new[] { "C1", "C3" }); metadataImporter = new MockMetadataImporter { GetTypeSemantics = type => type.Name != "C2" ? TypeScriptSemantics.NormalType(type.Name) : TypeScriptSemantics.NotUsableFromScript() }; Compile(new[] { "class C1 {} class C2 { class C3 {} }" }, metadataImporter: metadataImporter); CompiledTypes.Select(t => t.CSharpTypeDefinition.Name).Should().BeEquivalentTo(new[] { "C1", "C3" }); }
public void TakenElseWorksWithElif() { Compile(new[] { @" class A {} #if false class B {} #elif false class C {} #else class D {} #endif " }); CompiledTypes.Select(t => t.CSharpTypeDefinition.Name).Should().BeEquivalentTo(new[] { "A", "D" }); }
public void NamespacingWorks() { Compile(@"class Test1 { } namespace Nmspace1.Nmspace2 { namespace Nmspace3 { class Test2 {} } class Test3 {} } namespace Nmspace4 { class Test4 {} namespace Nmspace5 { class Test5 {} } namespace Nmspace5 { class Test6 {} } class Test7 {} } class Test8 {} namespace Nmspace1 { namespace Nmspace2 { class Test9 {} } } class Test10 {} "); CompiledTypes.Select(t => t.Name).Should().BeEquivalentTo(new[] { "Test1", "Nmspace1.Nmspace2.Nmspace3.Test2", "Nmspace1.Nmspace2.Test3", "Nmspace4.Test4", "Nmspace4.Nmspace5.Test5", "Nmspace4.Nmspace5.Test6", "Nmspace4.Test7", "Test8", "Nmspace1.Nmspace2.Test9", "Test10", }); CompiledTypes.Should().ContainItemsAssignableTo <JsClass>(); }