internal static void RunHighlightingTest(SyntaxHighlightingDefinition highlighting, string inputText)
        {
            var editor           = TextEditorFactory.CreateNewEditor();
            var sb               = new StringBuilder();
            int lineNumber       = 0;
            var expectedSegments = new List <Tuple <DocumentLocation, string> > ();

            using (var sr = new StringReader(inputText)) {
                while (true)
                {
                    var lineText = sr.ReadLine();
                    if (lineText == null)
                    {
                        break;
                    }
                    var idx = lineText.IndexOf('^');
                    if (idx >= 0)
                    {
                        expectedSegments.Add(Tuple.Create(new DocumentLocation(lineNumber, idx + 1), lineText.Substring(idx + 1).Trim()));
                    }
                    else
                    {
                        lineNumber++;
                        sb.AppendLine(lineText);
                    }
                }
            }
            editor.Text = sb.ToString();
            highlighting.PrepareMatches();
            editor.SyntaxHighlighting = new SyntaxHighlighting(highlighting, editor);

            //var line = editor.GetLine (6); {
            foreach (var line in editor.GetLines())
            {
                var coloredSegments = editor.SyntaxHighlighting.GetHighlightedLineAsync(line, CancellationToken.None).WaitAndGetResult(CancellationToken.None).Segments;
                for (int i = 0; i < expectedSegments.Count; i++)
                {
                    var seg = expectedSegments [i];
                    if (seg.Item1.Line == line.LineNumber)
                    {
                        var matchedSegment = coloredSegments.FirstOrDefault(s => s.Contains(seg.Item1.Column - 1));
                        Assert.NotNull(matchedSegment, "No segment found at : " + seg.Item1);
                        foreach (var segi in seg.Item2.Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            Console.WriteLine("line " + line.LineNumber + " : " + editor.GetTextAt(line));
                            Console.WriteLine(segi);
                            Console.WriteLine(string.Join(", ", matchedSegment.ScopeStack.ToArray()));
                            string mk          = null;
                            int    d           = 0;
                            var    expr        = StackMatchExpression.Parse(segi);
                            var    matchResult = expr.MatchesStack(matchedSegment.ScopeStack, ref mk);
                            Assert.IsTrue(matchResult.Item1, "Wrong color at " + seg.Item1 + " expected " + segi + " was " + string.Join(", ", matchedSegment.ScopeStack.ToArray()));
                        }
                        expectedSegments.RemoveAt(i);
                        i--;
                    }
                }
            }
            Assert.AreEqual(0, expectedSegments.Count, "Not all segments matched.");
        }
        public void TestDashChar()
        {
            var    expr = StackMatchExpression.Parse("entity.other.attribute-name");
            string tmp  = "";

            Assert.IsTrue(expr.MatchesStack(new ScopeStack("entity.other.attribute-name"), ref tmp).Item1);
        }
        public void TestSubstringMatch()
        {
            var    expr = StackMatchExpression.Parse("foo");
            string tmp  = "";

            Assert.IsTrue(expr.MatchesStack(new ScopeStack("foo.bar"), ref tmp).Item1);
        }
        public void TestBug45378()
        {
            var    expr = StackMatchExpression.Parse("string, constant.other.symbol, entity.other.inherited-class, markup.heading, markup.inserted.git_gutter");
            string tmp  = "";

            Assert.IsTrue(expr.MatchesStack(new ScopeStack("text.xml").Push("meta.tag.xml").Push("string.quoted.double.xml"), ref tmp).Item1);
        }
        public void TestMinusOr()
        {
            var    expr = StackMatchExpression.Parse("foo - (foo.bar | foo.foobar)");
            string tmp  = "";

            Assert.IsTrue(expr.MatchesStack(new ScopeStack("foo"), ref tmp).Item1);
            Assert.IsFalse(expr.MatchesStack(new ScopeStack("foo.bar"), ref tmp).Item1);
            Assert.IsFalse(expr.MatchesStack(new ScopeStack("foo.foobar"), ref tmp).Item1);
        }