Example #1
0
        public void TestNullColoredWord()
        {
            var o  = new TestOutput(new List <TestTextFragment>());
            var wh = new WordHighlighter(o);

            Assert.Throws <ArgumentNullException>(() => wh.Add(null));
        }
Example #2
0
        public static void Main(string[] args)
        {
            string text = File.ReadAllText(args[0]);

            string[] words = StringHelpers.Split(text,
                                                 StringHelpers.StringSplitOptions.RemoveEmptyEntries);
            ConsoleColor[]  colors = { ConsoleColor.Red,        ConsoleColor.Cyan,
                                       ConsoleColor.Yellow,      ConsoleColor.Green,
                                       ConsoleColor.Magenta,     ConsoleColor.DarkBlue,
                                       ConsoleColor.DarkMagenta, ConsoleColor.DarkCyan };
            var             output = new ConsoleOutput();
            WordHighlighter wh     = new WordHighlighter(output);

            for (int i = 0; i < words.Length; i++)
            {
                ColoredWord cw = new ColoredWord(words[i],
                                                 colors[i % colors.Length]);
                wh.Add(cw);
            }
            Console.WriteLine("Enter text: ");
            string line = Console.ReadLine();

            wh.Print(line, WordHighlighter.PrintOptions.WholeWordsOnly);
            Console.WriteLine();
            Console.WriteLine("The end");
        }
Example #3
0
        public void TestInvalidOptions()
        {
            var o  = new TestOutput(new List <TestTextFragment>());
            var wh = new WordHighlighter(o);

            Assert.Throws <ArgumentException>(
                () => wh.Print("aaa", (WordHighlighter.PrintOptions) 200));
        }
Example #4
0
        private void Test(List <ColoredWord> coloredWords, string text,
                          List <TestTextFragment> expectedTextFragments,
                          WordHighlighter.PrintOptions options =
                          WordHighlighter.PrintOptions.None)
        {
            var o  = new TestOutput(expectedTextFragments);
            var wh = new WordHighlighter(o);

            foreach (ColoredWord cw in coloredWords)
            {
                wh.Add(cw);
            }
            wh.Print(text, options);

            // check that WordHighlighter.Print() printed all expected fragments
            Assert.AreEqual(expectedTextFragments.Count, o.CurrentIndex);
        }