public void TestUnbalancedBrackets()
 {
     var qry = @"(()";
     var mockDoc = new DocumentMock(qry);
     var srchr = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
     
     var res = srchr.SearchBracket(mockDoc, 3);
     Assert.AreEqual(1, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
     Assert.AreEqual(2, res.ClosingBracketOffset, "Test forward Matching End Bracket");
     res = srchr.SearchBracket(mockDoc, 1);
     Assert.AreEqual(0, res.ClosingBracketLength, "non-existant end Bracket");
     
 }
        public void TestUnbalancedBrackets()
        {
            var qry     = @"(()";
            var mockDoc = new DocumentMock(qry);
            var srchr   = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();

            var res = srchr.SearchBracket(mockDoc, 3);

            Assert.AreEqual(1, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
            Assert.AreEqual(2, res.ClosingBracketOffset, "Test forward Matching End Bracket");
            res = srchr.SearchBracket(mockDoc, 1);
            Assert.AreEqual(0, res.ClosingBracketLength, "non-existant end Bracket");
        }
        public void TestSkippingDoubleSlashComments()
        {
            var qry = @"Evaluate Filter(
// this is a test )
table1
,table1[col1] = 10 )
";
            var mockDoc = new DocumentMock(qry);
            var srchr = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
            var res = srchr.SearchBracket(mockDoc, 17);
            Assert.IsNull(res, "Test should not match anything");
            // test matching end br4acket
            res = srchr.SearchBracket(mockDoc, 16);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
            Assert.AreEqual(66, res.ClosingBracketOffset, "Test forward Matching End Bracket");
            // test
            res = srchr.SearchBracket(mockDoc, 67);
            Assert.AreEqual(15, res.OpeningBracketOffset,"Test back Matching Start bracket");
            Assert.AreEqual(66, res.ClosingBracketOffset, "Test back Matching End bracket");
        }
        public void TestSkippingDoubleSlashComments()
        {
            var qry = @"Evaluate Filter(" + Environment.NewLine
                      + "// this is a test )" + Environment.NewLine
                      + "table1" + Environment.NewLine
                      + ",table1[col1] = 10 )" + Environment.NewLine;

            var mockDoc = new DocumentMock(qry);
            var srchr   = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
            var res     = srchr.SearchBracket(mockDoc, 17);

            Assert.IsNull(res, "Test should not match anything");
            // test matching end br4acket
            res = srchr.SearchBracket(mockDoc, 16);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
            Assert.AreEqual(66, res.ClosingBracketOffset, "Test forward Matching End Bracket");
            // test
            res = srchr.SearchBracket(mockDoc, 67);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test back Matching Start bracket");
            Assert.AreEqual(66, res.ClosingBracketOffset, "Test back Matching End bracket");
        }
        public void TestSkippingDoubleDashComments()
        {
            var qry = @"Evaluate Filter(" + Environment.NewLine
                      + "-- this is a test )\"" + Environment.NewLine
                      + "table1" + Environment.NewLine
                      + ",table1[col1] = 10 )" + Environment.NewLine;

            var mockDoc = new DocumentMock(qry);
            var srchr   = new DAXEditorControl.BracketRenderer.DaxStudioBracketSearcher();
            var res     = srchr.SearchBracket(mockDoc, 17);

            Assert.IsNull(res);
            res = srchr.SearchBracket(mockDoc, 16);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
            Assert.AreEqual(67, res.ClosingBracketOffset, "Test forward Matching End Bracket");
            res = srchr.SearchBracket(mockDoc, 37);
            Assert.IsNull(res, "Should not find bracket in comment");
            res = srchr.SearchBracket(mockDoc, 68);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test back Matching Start bracket");
            Assert.AreEqual(67, res.ClosingBracketOffset, "Test back Matching End bracket");
        }
        public void TestMultiLineQuery()
        {
            var qry = Environment.NewLine
                      + "EVALUATE" + Environment.NewLine
                      + "    CALCULATETABLE(" + Environment.NewLine
                      + "    'Product Subcategory'," + Environment.NewLine
                      + "    'Product Category'[Product Category Name] = @Category " + Environment.NewLine
                      + "    ))" + Environment.NewLine;

            var mockDoc = new DocumentMock(qry);
            var srchr   = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
            var res     = srchr.SearchBracket(mockDoc, 1);

            Assert.IsNull(res, "no match found at start of string");
            res = srchr.SearchBracket(mockDoc, 31);
            Assert.AreEqual(125, res.ClosingBracketOffset, "Found End Bracket");
            res = srchr.SearchBracket(mockDoc, 126);
            Assert.AreEqual(30, res.OpeningBracketOffset, "Found End Bracket");
            res = srchr.SearchBracket(mockDoc, 127);
            Assert.AreEqual(126, res.OpeningBracketOffset, "Found End Bracket");
            Assert.AreEqual(0, res.ClosingBracketOffset, "No Start Bracket");
        }
        public void TestSkippingStrings()
        {
            var qry = "Evaluate Filter(" + Environment.NewLine
                      + "table1" + Environment.NewLine
                      + ",table1[col1] = \":)\" || ')' )";
            var mockDoc = new DocumentMock(qry);
            var srchr   = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
            var res     = srchr.SearchBracket(mockDoc, 17);

            Assert.IsNull(res);
            res = srchr.SearchBracket(mockDoc, 16);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
            Assert.AreEqual(54, res.ClosingBracketOffset, "Test forward Matching End Bracket");

            res = srchr.SearchBracket(mockDoc, 45);
            Assert.IsNull(res, "Should not find bracket in string");

            res = srchr.SearchBracket(mockDoc, 52);
            Assert.IsNull(res, "Should not find bracket in char");

            res = srchr.SearchBracket(mockDoc, 55);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test back Matching Start bracket");
            Assert.AreEqual(54, res.ClosingBracketOffset, "Test back Matching End bracket");
        }
        public void TestSkippingStrings()
        {
            var qry = @"Evaluate Filter(
table1
,table1[col1] = "":)"" || ')' )";
            var mockDoc = new DocumentMock(qry);
            var srchr = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
            var res = srchr.SearchBracket(mockDoc, 17);
            Assert.IsNull(res);
            res = srchr.SearchBracket(mockDoc, 16);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test forward Matching Start Bracket");
            Assert.AreEqual(54, res.ClosingBracketOffset, "Test forward Matching End Bracket");
            
            res = srchr.SearchBracket(mockDoc, 45);
            Assert.IsNull(res, "Should not find bracket in string");
            
            res = srchr.SearchBracket(mockDoc, 52);
            Assert.IsNull(res, "Should not find bracket in char");
            
            res = srchr.SearchBracket(mockDoc, 55);
            Assert.AreEqual(15, res.OpeningBracketOffset, "Test back Matching Start bracket");
            Assert.AreEqual(54, res.ClosingBracketOffset, "Test back Matching End bracket");
             
        }
        public void TestMultiLineQuery()
        {
            var qry = @"
EVALUATE
    CALCULATETABLE(
    'Product Subcategory',
    'Product Category'[Product Category Name] = @Category 
    ))
";
            var mockDoc = new DocumentMock(qry);
            var srchr = new DAXEditor.BracketRenderer.DaxStudioBracketSearcher();
            var res = srchr.SearchBracket(mockDoc, 1);
            Assert.IsNull(res, "no match found at start of string");
            res = srchr.SearchBracket(mockDoc, 31);
            Assert.AreEqual(125, res.ClosingBracketOffset, "Found End Bracket");
            res = srchr.SearchBracket(mockDoc, 126);
            Assert.AreEqual(30, res.OpeningBracketOffset, "Found End Bracket");
            res = srchr.SearchBracket(mockDoc, 127);
            Assert.AreEqual(126, res.OpeningBracketOffset, "Found End Bracket");
            Assert.AreEqual(0, res.ClosingBracketOffset, "No Start Bracket");
        }