public void TestEggsML() { var expectations = new List <Tuple <string, string, string> > { Tuple.Create("", "(0:)", ""), Tuple.Create("*bold*", "(1:*(1:))", "*bold*"), Tuple.Create("non-bold *bold* non-bold", "(3:,*(1:),)", "non-bold *bold* non-bold"), Tuple.Create("more ***bold*", "(2:,*(1:))", "more *bold*"), Tuple.Create("Nested |*tags*|", "(2:,|(1:*(1:)))", "Nested |*tags*|"), Tuple.Create("Nested |`|||tags|`| yeah!", "(3:,|(1:|(1:)),)", "Nested |`|||tags|`| yeah!"), Tuple.Create("Empty |`| tag!", "(3:,|(0:),)", "Empty |`| tag!"), Tuple.Create(@"Escaped ""http://www.google.com/"" URL", "(1:)", @"""Escaped http://www.google.com/ URL"""), Tuple.Create(@"""String """"string"""" string""", "(1:)", @"String """"string"""" string"), Tuple.Create("[[square]] [<[tag]>]", "(2:,[(1:<(1:[(1:))))", "[[square]] [<[tag]>]"), }; foreach (var tuple in expectations) { Func <EggsNode, string> recurse = null; recurse = node => (node is EggsTag ? ((EggsTag)node).Tag + "(" + ((EggsTag)node).Children.Count.ToString() + ":" + ((EggsTag)node).Children.Select(n => recurse(n)).JoinString(",") + ")" : ""); var eggs = EggsML.Parse(tuple.Item1); Assert.AreEqual(tuple.Item2, recurse(eggs)); Assert.AreEqual(tuple.Item3, eggs.ToString()); } Assert.Throws <ArgumentNullException>(() => EggsML.Parse(null)); Assert.Throws <EggsMLParseException>(() => EggsML.Parse("xyz] xyz")); Assert.Throws <EggsMLParseException>(() => EggsML.Parse("xyz [[[xyz")); Assert.Throws <EggsMLParseException>(() => EggsML.Parse("xyz```xyz")); Assert.Throws <EggsMLParseException>(() => EggsML.Parse("xyz*****xyz")); Assert.Throws <EggsMLParseException>(() => EggsML.Parse("xyz]]] xyz")); Assert.Throws <EggsMLParseException>(() => EggsML.Parse("xyz *xyz")); }
/// <summary>Logs a message to the console.</summary> public override void Log(uint verbosity, LogType type, string message) { if (message == null) { message = "<null>"; } lock (this) { if (VerbosityLimit[type] < verbosity) { return; } string fmtInfo, indent; GetFormattedStrings(out fmtInfo, out indent, verbosity, type); var prevCol = Console.ForegroundColor; var col = GetMessageTypeColor(type); TextWriter consoleStream = (type == LogType.Error && ErrorsToStdErr) ? Console.Error : Console.Out; int wrapWidth = WordWrap ? ConsoleUtil.WrapToWidth() : int.MaxValue; bool first = true; if (InterpretMessagesAsEggsML) { foreach (var line in EggsML.Parse(message).ToConsoleColoredStringWordWrap(wrapWidth - fmtInfo.Length)) { Console.ForegroundColor = col; consoleStream.Write(first ? fmtInfo : indent); first = false; ConsoleUtil.WriteLine(line, type == LogType.Error && ErrorsToStdErr); } } else { Console.ForegroundColor = col; foreach (var line in message.WordWrap(wrapWidth - fmtInfo.Length)) { consoleStream.Write(first ? fmtInfo : indent); first = false; consoleStream.WriteLine(line); } } if (first) { Console.ForegroundColor = col; consoleStream.WriteLine(fmtInfo); // don't completely skip blank messages } Console.ForegroundColor = prevCol; } }