Inheritance: ISourceFile
コード例 #1
0
        private Tuple <JsClass, MockErrorReporter> Compile(string source, bool expectErrors = false)
        {
            var sourceFile  = new MockSourceFile("file.cs", source);
            var er          = new MockErrorReporter(!expectErrors);
            var n           = new Namer();
            var references  = new[] { Mscorlib, QUnit };
            var compilation = PreparedCompilation.CreateCompilation("Test", new[] { sourceFile }, references, null);
            var s           = new AttributeStore(compilation.Compilation, er);

            s.RunAttributeCode();
            var md  = new MetadataImporter(er, compilation.Compilation, s, new CompilerOptions());
            var rtl = new RuntimeLibrary(md, er, compilation.Compilation, n, s);

            md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
            var compiler = new Compiler(md, n, rtl, er);

            var result = compiler.Compile(compilation).ToList();

            Assert.That(result, Has.Count.EqualTo(1), "Should compile exactly one type");
            Assert.That(er.AllMessages, Is.Empty, "Compile should not generate errors");

            result = new TestRewriter(er, rtl, s).Rewrite(result).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should have one type after rewrite");
            Assert.That(result[0], Is.InstanceOf <JsClass>(), "Compiled type should be a class after rewrite");

            if (expectErrors)
            {
                Assert.That(er.AllMessages, Is.Not.Empty);
            }
            else
            {
                Assert.That(er.AllMessages, Is.Empty);
            }

            return(Tuple.Create((JsClass)result[0], er));
        }
コード例 #2
0
        private Tuple<JsClass, MockErrorReporter> Compile(string source, bool expectErrors = false)
        {
            var sourceFile = new MockSourceFile("file.cs", source);
            var er = new MockErrorReporter(!expectErrors);
            var n = new Namer();
            var references = new[] { Mscorlib, QUnit };
            var compilation = PreparedCompilation.CreateCompilation("Test", new[] { sourceFile }, references, null);
            var s = new AttributeStore(compilation.Compilation, er);
            s.RunAttributeCode();
            var md = new MetadataImporter(er, compilation.Compilation, s, new CompilerOptions());
            var rtl = new RuntimeLibrary(md, er, compilation.Compilation, n, s);
            md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
            var compiler = new Compiler(md, n, rtl, er);

            var result = compiler.Compile(compilation).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should compile exactly one type");
            Assert.That(er.AllMessages, Is.Empty, "Compile should not generate errors");

            result = new TestRewriter(er, rtl, s).Rewrite(result).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should have one type after rewrite");
            Assert.That(result[0], Is.InstanceOf<JsClass>(), "Compiled type should be a class after rewrite");

            if (expectErrors) {
                Assert.That(er.AllMessages, Is.Not.Empty);
            }
            else {
                Assert.That(er.AllMessages, Is.Empty);
            }

            return Tuple.Create((JsClass)result[0], er);
        }