示例#1
0
        /// <summary>
        /// Run the provided donatello program and return the result.
        /// </summary>
        /// <typeparam name="T">The expected return type</typeparam>
        /// <param name="program">The donatello source code</param>
        /// <returns>the return value of the program</returns>
        public static T Run <T>(string program, string assemblyName = null, params string[] references)
        {
            const string namespaceName = "DonatelloRun";
            const string className     = "Runner";
            const string methodName    = "Run";

            CompilationUnitSyntax syntaxTree = AntlrParser.ParseAsClass(program, namespaceName, className, methodName);
            Stream result = Compiler.Compile(assemblyName ?? namespaceName, references, OutputType.DynamicallyLinkedLibrary, syntaxTree);

            return(AssemblyRunner.Run <T>(result, namespaceName, className, methodName));
        }
示例#2
0
        public void Donatello_Transforms_ToCSharp(string test)
        {
            string file = Path.Combine("Unit", "Transforms", test);

            string donatello      = File.ReadAllText(file + ".dnl");
            string expectedCSharp = File.ReadAllText(file + ".cs");

            string actualCSharp = AntlrParser.ParseAsClass(donatello, "UnitTest", test + "Test")
                                  .NormalizeWhitespace()
                                  .ToFullString();

            string normalizedExpectedCSharp = Whitespace.Replace(expectedCSharp, "");
            string normalizedActualCSharp   = Whitespace.Replace(actualCSharp, "");

            Assert.Equal(normalizedExpectedCSharp, normalizedActualCSharp);
        }