예제 #1
0
        public void ParseModule_parses_two_files_with_errors_in_both()
        {
            const string source1 = @"namespace Test";
            const string source2 = @"namespace Test;
public int32 Func {}";

            var sourceProvider = new TestingSourceFileProvider();

            sourceProvider.Add(".", "main.cle", source1);
            sourceProvider.Add(".", "other.cle", source2);

            var compilation = new Compilation();

            CompilerDriver.ParseModule(".", compilation, sourceProvider, out var syntaxTrees);

            sourceProvider.AssertFileWasRead("main.cle");
            sourceProvider.AssertFileWasRead("other.cle");
            Assert.That(compilation.Diagnostics, Has.Exactly(2).Items);
            Assert.That(syntaxTrees, Is.Empty);

            Assert.That(compilation.Diagnostics[0].Module, Is.EqualTo("."));
            Assert.That(compilation.Diagnostics[0].Filename, Is.EqualTo("main.cle"));
            Assert.That(compilation.Diagnostics[0].Code, Is.EqualTo(DiagnosticCode.ExpectedSemicolon));

            Assert.That(compilation.Diagnostics[1].Module, Is.EqualTo("."));
            Assert.That(compilation.Diagnostics[1].Filename, Is.EqualTo("other.cle"));
            Assert.That(compilation.Diagnostics[1].Code, Is.EqualTo(DiagnosticCode.ExpectedParameterList));
        }
예제 #2
0
        public void ParseModule_raises_error_on_unavailable_module()
        {
            var sourceProvider = new TestingSourceFileProvider();

            sourceProvider.Add(".", "main.cle", "");

            var compilation = new Compilation();

            CompilerDriver.ParseModule("OtherModule", compilation, sourceProvider, out var syntaxTrees);

            Assert.That(compilation.Diagnostics, Has.Exactly(1).Items);
            Assert.That(compilation.Diagnostics[0].Code, Is.EqualTo(DiagnosticCode.ModuleNotFound));
            Assert.That(compilation.Diagnostics[0].Module, Is.EqualTo("OtherModule"));
            Assert.That(syntaxTrees, Is.Empty);
        }
예제 #3
0
        public void ParseModule_parses_single_file_successfully()
        {
            const string source         = @"namespace Test;
private int32 PrivateFunc() {}
internal bool ProtectedFunc() {}
public void PublicFunc() {}";
            var          sourceProvider = new TestingSourceFileProvider();

            sourceProvider.Add(".", "main.cle", source);

            var compilation = new Compilation();

            CompilerDriver.ParseModule(".", compilation, sourceProvider, out var syntaxTrees);

            sourceProvider.AssertFileWasRead("main.cle");
            Assert.That(compilation.Diagnostics, Is.Empty);
            Assert.That(syntaxTrees, Has.Exactly(1).Items);
        }