public void MultiClassIsMatch_Test()
        {
            int priority;

            var defn = new StyleDefn();

            defn.Match = "doc:Div.red";


            var div = new Div();

            div.StyleClass  = "red blue";
            div.ElementName = "doc:Div";
            var result = defn.IsMatchedTo(div, out priority);

            Assert.IsTrue(result, "The definition did not match the component");

            div.StyleClass = "blue red";
            result         = defn.IsMatchedTo(div, out priority);
            Assert.IsTrue(result, "The definition did not match the component");

            div.StyleClass = "blue red green";
            result         = defn.IsMatchedTo(div, out priority);
            Assert.IsTrue(result, "The definition did not match the component");
        }
        public void NestedClassMatch_Test()
        {
            int priority;

            var defn = new StyleDefn();

            defn.Match = ".red .blue";

            var div1 = new Div();

            div1.StyleClass = "red";

            var div2 = new Div();

            div2.StyleClass = "blue";
            div1.Contents.Add(div2);

            var result = defn.IsMatchedTo(div2, out priority);

            Assert.IsTrue(result, "The inner div was not matched as expected");


            //Switch the parent to .green and it should not match

            div1.StyleClass = "green";
            result          = defn.IsMatchedTo(div2, out priority);
            Assert.IsFalse(result, "The inner div was matched - not as expected");
        }
        public void NestedMultipleClassMatch_Test()
        {
            int priority = 0;

            var defn = new StyleDefn();

            defn.Match = "doc:Div.green > doc:Para.green.red, doc:Div.red > doc:Para.blue.green";

            var div1 = new Div();

            div1.ElementName = "doc:Div";
            div1.StyleClass  = "red";

            var div2 = new Div();

            div2.ElementName = "doc:Div";
            div2.StyleClass  = "green";
            div1.Contents.Add(div2);

            var para = new Paragraph();

            para.ElementName = "doc:Para";
            para.StyleClass  = "green red";
            div2.Contents.Add(para);

            //red > bulue and green
            var result = defn.IsMatchedTo(para, out priority);

            Assert.IsTrue(result, "The inner para was not matched as expected");


            //Switch the parent to .red and parents parent to .green and it should match on the second selector
            //As not a direct parent (classes reveresd order)

            div2.StyleClass = "red";
            para.StyleClass = "green blue";

            result = defn.IsMatchedTo(para, out priority);
            Assert.IsTrue(result, "The inner para was not matched as expected");

            //red back as direct parent, but only one class on the para

            div2.StyleClass = "red";
            para.StyleClass = "green";

            result = defn.IsMatchedTo(para, out priority);
            Assert.IsFalse(result, "The inner para was matched - not as expected");
        }
        public void NestedDualClassMatch_Test()
        {
            int priority;

            var defn = new StyleDefn();

            defn.Match = "doc:Div.green > .blue.green";

            var div1 = new Div();

            div1.ElementName = "doc:Div";
            div1.StyleClass  = "red";

            var div2 = new Div();

            div2.ElementName = "doc:Div";
            div2.StyleClass  = "green";
            div1.Contents.Add(div2);

            var para = new Paragraph();

            para.ElementName = "doc:Para";
            para.StyleClass  = "blue green";
            div2.Contents.Add(para);

            var result = defn.IsMatchedTo(para, out priority);

            Assert.IsTrue(result, "The inner para was not matched as expected");


            //Switch the parent to .red and parents parent to .green and it should not match
            //As not a direct parent

            div1.StyleClass = "green";
            div2.StyleClass = "red";

            result = defn.IsMatchedTo(div2, out priority);
            Assert.IsFalse(result, "The inner para was matched - not as expected");

            //Green back as direct parent, but only one class on the para

            div2.StyleClass = "green";
            para.StyleClass = "blue";

            result = defn.IsMatchedTo(div2, out priority);
            Assert.IsFalse(result, "The inner para was matched - not as expected");
        }
        public void DeepNestedClassMatch_Test()
        {
            int priority;

            var defn = new StyleDefn();

            defn.Match = "doc:Div#MyDiv doc:Para.blue";

            var div1 = new Div();

            div1.ElementName = "doc:Div";
            div1.ID          = "MyDiv";
            div1.StyleClass  = "red";

            var div2 = new Div();

            div2.ElementName = "doc:Div";
            div2.StyleClass  = "blue";
            div1.Contents.Add(div2);

            var para = new Paragraph();

            para.ElementName = "doc:Para";
            para.StyleClass  = "blue";
            div2.Contents.Add(para);

            var result = defn.IsMatchedTo(para, out priority);

            Assert.IsTrue(result, "The inner para was not matched as expected");

            //Switch the parent to .green and it should not match

            div1.StyleClass = "green";
            result          = defn.IsMatchedTo(div2, out priority);
            Assert.IsFalse(result, "The inner para was matched - not as expected");
        }
        public void SimpleIsMatch_Test()
        {
            int priority;
            var defn = new StyleDefn();

            defn.Match = PDFStyleMatcher.Parse(".red");


            var div = new Div();

            div.StyleClass = "red";

            var result = defn.IsMatchedTo(div, out priority);

            Assert.IsTrue(result, "The definition did not match the component");
        }
        public void DualIsMatch_Test()
        {
            int priority;
            var defn = new StyleDefn();

            defn.Match = PDFStyleMatcher.Parse("doc:Div.red");


            var div = new Div();

            div.ID          = "MyDiv";
            div.StyleClass  = "red";
            div.ElementName = "doc:Div";

            var result = defn.IsMatchedTo(div, out priority);

            Assert.IsTrue(result, "The definition did not match the component");
        }
Example #8
0
        public void IsMatchedToTest()
        {
            StyleDefn target = new StyleDefn();

            //Catch All with document
            int priority;

            Scryber.Components.Document doc = new Components.Document();
            bool expected = true;
            bool actual;

            actual = target.IsMatchedTo(doc, out priority);
            Assert.AreEqual(expected, actual, "Didn't match document on catch all");

            //set up component

            Scryber.Components.Label lbl = new Scryber.Components.Label();
            lbl.StyleClass = "myclass";
            lbl.ID         = "myId";


            //Catch all should always match

            expected = true;
            actual   = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(1, expected));

            //match applied type
            target.AppliedType = typeof(Scryber.Components.Label);
            expected           = true;
            actual             = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(2, expected));

            //match applied type and class
            target.AppliedClass = "myclass";
            expected            = true;
            actual = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(3, expected));

            //match applied type, class and id
            target.AppliedID = "myId";
            expected         = true;
            actual           = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(4, expected));

            //match class and id
            target.AppliedType = null;
            expected           = true;
            actual             = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(5, expected));

            //match id
            target.AppliedClass = string.Empty;
            expected            = true;
            actual = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(6, expected));

            //match base type and id
            target.AppliedType = typeof(Scryber.Components.SpanBase);
            expected           = true;
            actual             = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(7, expected));

            //multiple defined style classes
            lbl.StyleClass      = "other myclass";
            target.AppliedClass = "myclass";
            expected            = true;
            actual = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(8, expected));

            //non-matched class, matched type and id
            lbl.StyleClass      = "myclass";
            target.AppliedClass = "other";
            expected            = false;
            actual = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(9, expected));

            //non-matched type, matched class and id
            target.AppliedType  = typeof(Scryber.Components.TableCell);
            target.AppliedClass = "myclass";
            expected            = false;
            actual = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(10, expected));

            //non-matched id, matched class
            target.AppliedType = null;
            lbl.ID             = "otherID";
            expected           = false;
            actual             = target.IsMatchedTo(lbl, out priority);
            Assert.AreEqual(expected, actual, GetIsMatchedToMessage(11, expected));
        }