Пример #1
1
        public void Compiler_Execute_AllOfTheValidSampleKleinPrograms()
        {
            var folder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\KleinPrograms\Programs\fullprograms");
            var files  = Directory.GetFiles(folder, "*.kln");

            Assert.That(files.Length, Is.GreaterThan(0));

            foreach (var file in files)
            {
                var input    = File.ReadAllText(file);
                var frontEnd = new FrontEnd();
                var program  = frontEnd.Compile(input);
                Assert.That(program, Is.Not.Null, frontEnd.ErrorRecord.ToString());
                var tacs   = new ThreeAddressCodeFactory().Generate(program);
                var output = new CodeGenerator().Generate(tacs);

                foreach (var testDatum in TestDatum.GetTestData(input))
                {
                    Console.WriteLine($"{Path.GetFileName(file)}      {testDatum}");
                    var tinyOut = new TinyMachine(ExePath, TestFilePath).Execute(output, testDatum.Args);
                    Console.WriteLine(tinyOut);
                    Assert.That(tinyOut, Is.EquivalentTo(testDatum.Asserts), Path.GetFileName(file));
                }
            }
        }
Пример #2
0
        public void Test_MultipleLineWithMultipleAssert()
        {
            string input = @"// Args 2 Assert 7, 9, 13
// Args 3 Assert 7, 9, 13
// Args 5 Assert 7, 9, 13";

            var testData = TestDatum.GetTestData(input);

            Assert.That(testData.Count, Is.EqualTo(3));
        }
Пример #3
0
        public void Test_SingleLineWithMultipleAssert()
        {
            string input = @"// Args 2 Assert 7, 9, 13
";

            var testData = TestDatum.GetTestData(input);

            Assert.That(testData.Count, Is.EqualTo(1));
            Assert.That(testData[0].Args, Is.EqualTo(" 2 "));
            Assert.That(testData[0].Asserts, Is.EquivalentTo(new[] { "7", "9", "13" }));
        }
Пример #4
0
        public void Test_WithRealCode()
        {
            string input = @"// -------------------------------
// test: if expression as a value
// -------------------------------
// Args 2 Assert 7

            main(n: integer) : integer
  6 + if n < 0
      then
         10
      else
         n* n";

            var testData = TestDatum.GetTestData(input);

            Assert.That(testData.Count, Is.EqualTo(1));
            Assert.That(testData[0].Args, Is.EqualTo(" 2 "));
            Assert.That(testData[0].Asserts, Is.EquivalentTo(new [] { "7" }));
        }