public void TestFormatter()
        {
            var processor = new Processor();
            processor.AddDomain("TestDomain");
            processor.AddDomain("TestDomain", "SubDomain");
            processor.GetDomain("TestDomain").Add("TestKey", "This is a test.");
            processor.GetDomain("TestDomain", "SubDomain").Add("TestKey", "This is a subdomain test.");

            var formatStr1 = "##TestDomain.TestKey##";
            var formatOut1 = processor.FormatString(formatStr1);
            var formatStr2 = "##TestDomain:SubDomain.TestKey##";
            var formatOut2 = processor.FormatString(formatStr2);
            var formatStr3 = "##TestDomain.TestKey####TestDomain:SubDomain.TestKey##";
            var formatOut3 = processor.FormatString(formatStr3);

            Assert.AreEqual("This is a test.", formatOut1);
            Assert.AreEqual("This is a subdomain test.", formatOut2);
            Assert.AreEqual("This is a test.This is a subdomain test.", formatOut3);
        }
        public void TestFormatterWithNewlineOptionsAndSameReplacers()
        {
            var processor = new Processor();
            processor.AddDomain("TestDomain");
            processor.GetDomain("TestDomain").Add("TestKey", "This is a test.");

            var formatStr = @"<@<% TestOption test=""Parameter"" %>@>
            ##TestDomain.TestKey##<% TestOption test=""Parameter"" %>##TestDomain.TestKey##";
            var formatOut = processor.FormatString(formatStr);

            Assert.AreEqual("This is a test.This is a test.", formatOut);
        }
        public void TestFormatterWithConvertersAndOptions()
        {
            var processor = new Processor();
            processor.AddDomain("TestDomain");
            processor.GetDomain("TestDomain").Add("TestKey", "This is a test.");

            var formatStr = @"<@
            <% Import dll=""NasuTek.Preprocessor.ProcessingLibrary.Tests.dll"" %>
            <% Import namespace=""NasuTek.Preprocessor.ProcessingLibrary.Tests"" %>
            @>
            ##TestDomain.TestKey(TestConverter[Demo=""Demo Testing "",Demo2=""Is Awesome.""])##";

            processor.ExecuteProcessors(formatStr);

            var formatOut = processor.FormatString(formatStr);

            Assert.AreEqual("Demo Testing Is Awesome.", formatOut);
        }
        static void Main(string[] args)
        {
            Console.Error.WriteLine("NasuTek Preprocessor Version 1.0");
            Console.Error.WriteLine("\tCopyright (C) 2013 NasuTek Enterprises");
            Console.Error.WriteLine();

            var inFiles = new List<string>();
            var outFiles = new List<string>();
            var processorDefinitionFile = new List<string>();
            var parameters = new List<string>();

            string showHelp = null;

            if (args.Length < 1)
                showHelp = "";

            var optionSet = new OptionSet {
                { "i|InFile=", "The filename to preprocess. Use STDIN to use standard input.", inFiles.Add },
                { "o|OutFile=", "The filename to write the processed file to. Use STDOUT to use standard output.", outFiles.Add },
                { "P|ProcessorDefinitionFile=", "The filename to preprocess. Use STDIN to use standard input.", processorDefinitionFile.Add },
                { "p|Parameter=", "Set a parameter for a processor.", parameters.Add },
                { "?|h|Help", "Shows Help", v=> showHelp = v },
            };

            try
            {
                optionSet.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Error.Write("NasuTek.Preprocessor: ");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("Try `NasuTek.Preprocessor /Help' for more information.");
                return;
            }

            if (showHelp != null)
            {
                Show_Help(optionSet);
                return;
            }

            #if !DEBUG
            try
            {
            #endif
            foreach (var inFileName in inFiles)
            {
                var processor = new Processor();
                foreach (var v in parameters)
                {
                    var splValComma = v.Split(',');
                    var splValEqual = splValComma[1].Split('=');

                    processor.SetParameter(splValComma[0], splValEqual[0], splValEqual[1]);
                }

                var input = "";

                if (inFileName != "STDIN")
                    input = File.ReadAllText(inFileName);
                else
                {
                    try
                    {
            #pragma warning disable 168
                        var tmp = Console.KeyAvailable;
            #pragma warning restore 168
                        var readLine = "";
                        while (readLine != "__EOF__")
                        {
                            readLine = Console.ReadLine();
                            if (readLine != "__EOF__")
                                input += readLine + Environment.NewLine;
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        input = Console.In.ReadToEnd();
                    }
                }

                foreach (var processorDef in processorDefinitionFile)
                {
                    processor.ExecuteProcessors(File.ReadAllText(processorDef));
                }

                processor.ExecuteProcessors(input);
                input = processor.FormatString(input);

                if (outFiles[inFiles.IndexOf(inFileName)] != "STDOUT")
                    File.WriteAllText(outFiles[inFiles.IndexOf(inFileName)], input);
                else
                    Console.Write(input);
            }
            #if !DEBUG
            }
            catch (Exception e)
            {
                if (Debugger.IsAttached)
                    throw;

                Console.Error.WriteLine(e.ToString());
            }
            #endif

            Console.Error.WriteLine("File processed successfully.");
        }