示例#1
0
        public void DoTestShowProjectHelp(string nantNamespace, string prefix)
        {
            string buildFileContents = @"<?xml version='1.0' ?>
                <{1}{2}project {0} name='Hello World' default='build' basedir='.'>

                    <{1}{2}property name='basename' value='HelloWorld'/>
                    <{1}{2}target name='init'/> <!-- fake subtarget for unit test -->

                    <{1}{2}target name='clean' description='cleans build directory'>
                        <{1}{2}delete file='${{basename}}.exe' failonerror='false'/>
                    </{1}{2}target>

                    <{1}{2}target name='build' description='compiles the source code'>
                        <{1}{2}csc target='exe' output='${{basename}}.exe'>
                            <{1}{2}sources>
                                <{1}{2}include name='${{basename}}.cs'/>
                            </{1}{2}sources>
                        </{1}{2}csc>
                    </{1}{2}target>

                    <{1}{2}target name='test' depends='build' description='run the program'>
                        <{1}{2}exec program='${{basename}}.exe'/>
                    </{1}{2}target>
                </{1}{2}project>";

            string colon         = prefix.Length == 0? string.Empty: ":";
            string namespaceDecl = nantNamespace.Length == 0? string.Empty:
                                   string.Format("xmlns{2}{1}=\"{0}\"", nantNamespace, prefix, colon);
            // write build file to temp file
            string buildFileName = CreateTempFile("buildfile.xml", string.Format(buildFileContents, namespaceDecl, prefix, colon));

            Assert.IsTrue(File.Exists(buildFileName), buildFileName + " does not exist.");

            X.XmlDocument document = new Project(buildFileName, Level.Warning, 0).Document;
            Assert.AreEqual(nantNamespace, document.DocumentElement.NamespaceURI);
            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.ShowProjectHelp(document);
                result = c.Close();
            }

            /* expecting output in the form of"
             *
             *  Default Target:
             *
             *   build         compiles the source code
             *
             *  Main Targets:
             *
             *   clean         cleans build directory
             *   build         compiles the source code
             *   test          run the program
             *
             *  Sub Targets:
             *
             *   init
             */

            // using a regular expression to look for valid output
            // expression created by RegEx http://www.organicbit.com/regex/
            string expression = @"Default Target:[\s]*(?<default>build)\s*compiles the source code[\s]*Main Targets:[\s]*(?<main1>build)\s*compiles the source code[\s]*(?<main2>clean)\s*cleans build directory[\s]*(?<main3>test)\s*run the program[\s]*Sub Targets:[\s]*(?<subtarget1>init)";

            Match match = Regex.Match(result, expression);

            if (match.Success)
            {
                Assert.AreEqual("build", match.Groups["default"].Value);
                Assert.AreEqual("build", match.Groups["main1"].Value);
                Assert.AreEqual("clean", match.Groups["main2"].Value);
                Assert.AreEqual("test", match.Groups["main3"].Value);
                Assert.AreEqual("init", match.Groups["subtarget1"].Value);
            }
            else
            {
                Assert.Fail("Project help text does not appear to be valid, see results for details:" + Environment.NewLine + result);
            }

            // delete the build file
            File.Delete(buildFileName);
            Assert.IsFalse(File.Exists(buildFileName), buildFileName + " exists.");
        }
示例#2
0
 public static void Main(string[] args)
 {
     ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CLI));
     ConsoleDriver.Run(new CommonTestsGenerator(GeneratorKind.CSharp));
 }
示例#3
0
 public static void Main(string[] args)
 {
     ConsoleDriver.Run(new CSharpTempTests(GeneratorKind.CSharp));
 }
示例#4
0
 public static void Main(string[] args)
 {
     ConsoleDriver.Run(new NamespacesDerivedTests(GeneratorKind.CSharp));
 }
示例#5
0
 static void Main(string[] args)
 {
     ConsoleDriver.Run(new JemallocLibrary());
 }
示例#6
0
        void RenderLine(ConsoleDriver driver, IHasStats toRender, int col, int line, int width)
        {
            string suffix = "   ";

            //Get relation to player
            if (toRender is IActor a)
            {
                var world        = a.CurrentLocation.World;
                var relationship = world.Relationships.SumBetween(a, world.Player);

                if (relationship < -40)
                {
                    suffix = "---";
                }
                else
                if (relationship < -20)
                {
                    suffix = "-- ";
                }
                else
                if (relationship < 0)
                {
                    suffix = "-  ";
                }
                else
                if (relationship > 40)
                {
                    suffix = "+++";
                }
                else
                if (relationship > 20)
                {
                    suffix = "++ ";
                }
                else
                if (relationship > 0)
                {
                    suffix = "+  ";
                }
            }

            //allow for the suffix
            var ustring = toRender.ToString();

            ustring = ustring.Substring(0, Math.Min(ustring.Length, width - 3)) + suffix;
            ustring = ustring.PadRight(width);

            int byteLen = ustring.Length;
            int used    = 0;

            for (int i = 0; i < byteLen;)
            {
                (var rune, var size) = Utf8.DecodeRune(ustring, i, i - byteLen);
                var count = Rune.ColumnWidth(rune);
                if (used + count >= width)
                {
                    break;
                }

                if (rune == '-')
                {
                    driver.SetAttribute(_red);
                }
                else
                if (rune == '+')
                {
                    driver.SetAttribute(_green);
                }
                else
                {
                    driver.SetAttribute(_normal);
                }

                driver.AddRune(rune);
                used += count;
                i    += size;
            }
            for (; used < width; used++)
            {
                driver.AddRune(' ');
            }
        }
示例#7
0
 public void Render(ListView container, ConsoleDriver driver, bool marked, int item, int col, int line, int width)
 {
     container.Move(col, line);
     RenderLine(driver, _roomContentsObjects[item], col, line, width);
 }
示例#8
0
 public void Render(ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width)
 {
     container.Move(col, line);
     RenderUstr(driver, GridViewRowList[item].DisplayString, col, line, width);
 }