public void DeclaresSimpleClass()
 {
     var compiler = new TypeScript.TypeScriptCompiler();
     var result = compiler.Compile("class Person{}");
     result.Should().Be(
     @"var Person = (function () {
     function Person() { }
     return Person;
     })();");
 }
Exemplo n.º 2
0
 public void Throws()
 {
     var compiler = new TypeScript.TypeScriptCompiler();
     try
     {
         compiler.Compile("var a = ;");
         Assert.Fail("Compilation did not fail.");
     }
     catch (TypeScript.TypeScriptCompilerException exception)
     {
         exception.Message.Should().Be("Compilation error: Check format of expression term\nCode block: 1\nStart position: 8\nLength: 1");
     }
 }
        public void PlayScriptCompiles()
        {
            var compiler = new TypeScript.TypeScriptCompiler();
            var result = compiler.Compile(@"class Greeter {
            greeting: string;
            constructor (message: string) {
            this.greeting = message;
            }
            greet() {
            return ""Hello, "" + this.greeting;
            }
            }

            var greeter = new Greeter(""world"");

            var button = document.createElement('button')
            button.innerText =""Say Hello""
            button.onclick = function() {
            alert(greeter.greet())
            }

            document.body.appendChild(button)");

            result.Should().Be(
            @"var Greeter = (function () {
            function Greeter(message) {
            this.greeting = message;
            }
            Greeter.prototype.greet = function () {
            return ""Hello, "" + this.greeting;
            };
            return Greeter;
            })();
            var greeter = new Greeter(""world"");
            var button = document.createElement('button');
            button.innerText = ""Say Hello"";
            button.onclick = function () {
            alert(greeter.greet());
            };
            document.body.appendChild(button);");
        }
 public void DeclaresNumber()
 {
     var compiler = new TypeScript.TypeScriptCompiler();
     var result = compiler.Compile("var a = 1;");
     result.Should().Be("var a = 1;");
 }