Exemple #1
0
        public void ParseItemCollection_RemoveTest()
        {
            CssParser  p = new CssParser();
            StyleSheet s = p.Parse("@charset \"foo\"; .a { } .b { } /* */", true);

            ParseItemList pc = new ParseItemList
            {
                s.Children[0]
            };

            Assert.IsTrue(pc.Remove(pc[0]));
            Assert.AreEqual(0, pc.Count);

            pc.Add(s.Children[0]);
            pc.Add(s.Children[s.Children.Count - 1]);
            Assert.AreEqual(2, pc.Count);
            Assert.AreEqual(typeof(CComment), pc[1].GetType());

            Assert.IsTrue(pc.Remove(s.Children[s.Children.Count - 1]));
            Assert.AreEqual(1, pc.Count);
            Assert.AreEqual(s.Children[0], pc[0]);
            Assert.AreEqual(typeof(CharsetDirective), pc[0].GetType());

            Assert.IsTrue(pc.Remove(s.Children[0]));
            Assert.AreEqual(0, pc.Count);

            Assert.IsFalse(pc.Remove(s.Children[0]));
            Assert.AreEqual(0, pc.Count);
        }
Exemple #2
0
        public void ParseItemCollection_AddTest()
        {
            CssParser  p = new CssParser();
            StyleSheet s = p.Parse("@charset \"foo\"; .a { } .b { } /* */", true);

            ParseItemList pc = new ParseItemList
            {
                s.Children[0]
            };

            Assert.AreSame(pc[0], s.Children[0]);
            Assert.AreEqual(typeof(CharsetDirective), pc[0].GetType());

            pc.Add(s.Children[s.Children.Count - 1]);
            Assert.AreEqual(typeof(CComment), pc[1].GetType());
            Assert.AreEqual(2, pc.Count);

            pc.Add(s.Children[1]);
            Assert.AreEqual(typeof(CharsetDirective), pc[0].GetType());
            Assert.AreEqual(typeof(RuleSet), pc[1].GetType());
            Assert.AreEqual(typeof(CComment), pc[2].GetType());
            Assert.AreEqual(3, pc.Count);

            Assert.AreEqual(0, pc.FindInsertIndex(0, beforeExisting: true));
            Assert.AreEqual(1, pc.FindInsertIndex(0, beforeExisting: false));

            Assert.AreEqual(0, pc.TextStart);
            Assert.AreEqual(s.Length, pc.TextLength);
        }