CssQueryTest.cs 3.53 KB
Newer Older
1
2
3
4
5
6
7
using Svg.Css;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ExCSS;

namespace Svg.UnitTests
{
8
9
10
11
12
	/// <summary>
	///This is a test class for CssQueryTest and is intended
	///to contain all CssQueryTest Unit Tests
	///</summary>
	[TestClass()]
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    public class CssQueryTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
        
        private void TestSelectorSpecificity(string selector, int specificity)
        {
            var parser = new ExCSS.Parser();
            var sheet = parser.Parse(selector + " {color:black}");
            Assert.AreEqual(specificity, CssQuery.GetSpecificity(sheet.StyleRules[0].Selector));
        }

        /// <summary>
        ///A test for GetSpecificity
        ///</summary>
        ///<remarks>Lifted from http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/, and http://css-tricks.com/specifics-on-css-specificity/ </remarks>
        [TestMethod()]
        public void RunSpecificityTests()
        {
            TestSelectorSpecificity("*", 0x0);
            TestSelectorSpecificity("li", 0x10);
            TestSelectorSpecificity("li:first-line", 0x20);
            TestSelectorSpecificity("ul li", 0x20);
            TestSelectorSpecificity("ul ol+li", 0x30);
            TestSelectorSpecificity("h1 + *[rel=up]", 0x110);
            TestSelectorSpecificity("ul ol li.red", 0x130);
            TestSelectorSpecificity("li.red.level", 0x210);
            TestSelectorSpecificity("p", 0x010);
            TestSelectorSpecificity("div p", 0x020);
            TestSelectorSpecificity(".sith", 0x100);
            TestSelectorSpecificity("div p.sith", 0x120);
            TestSelectorSpecificity("#sith", 0x1000);
            TestSelectorSpecificity("body #darkside .sith p", 0x1120);
            TestSelectorSpecificity("body #content .data img:hover", 0x1220);
            TestSelectorSpecificity("a#a-02", 0x1010);
            TestSelectorSpecificity("a[id=\"a-02\"]", 0x0110);
            TestSelectorSpecificity("ul#nav li.active a", 0x1130);
            TestSelectorSpecificity("body.ie7 .col_3 h2 ~ h2", 0x0230);
            TestSelectorSpecificity("#footer *:not(nav) li", 0x1020);
            TestSelectorSpecificity("ul > li ul li ol li:first-letter", 0x0070);
        }
    }
}