UNPKG

2.02 kBtext/x-cView Raw
1#include "../ast.hpp"
2#include "../context.hpp"
3#include "../parser.hpp"
4#include <string>
5
6using namespace Sass;
7
8Context ctx = Context(Context::Data());
9
10Compound_Selector* compound_selector(std::string src)
11{ return Parser::from_c_str(src.c_str(), ctx, "", Position()).parse_compound_selector(); }
12
13Complex_Selector* complex_selector(std::string src)
14{ return Parser::from_c_str(src.c_str(), ctx, "", Position()).parse_complex_selector(false); }
15
16void check_compound(std::string s1, std::string s2)
17{
18 std::cout << "Is "
19 << s1
20 << " a superselector of "
21 << s2
22 << "?\t"
23 << compound_selector(s1 + ";")->is_superselector_of(compound_selector(s2 + ";"))
24 << std::endl;
25}
26
27void check_complex(std::string s1, std::string s2)
28{
29 std::cout << "Is "
30 << s1
31 << " a superselector of "
32 << s2
33 << "?\t"
34 << complex_selector(s1 + ";")->is_superselector_of(complex_selector(s2 + ";"))
35 << std::endl;
36}
37
38int main()
39{
40 check_compound(".foo", ".foo.bar");
41 check_compound(".foo.bar", ".foo");
42 check_compound(".foo.bar", "div.foo");
43 check_compound(".foo", "div.foo");
44 check_compound("div.foo", ".foo");
45 check_compound("div.foo", "div.bar.foo");
46 check_compound("p.foo", "div.bar.foo");
47 check_compound(".hux", ".mumble");
48
49 std::cout << std::endl;
50
51 check_complex(".foo ~ .bar", ".foo + .bar");
52 check_complex(".foo .bar", ".foo + .bar");
53 check_complex(".foo .bar", ".foo > .bar");
54 check_complex(".foo .bar > .hux", ".foo.a .bar.b > .hux");
55 check_complex(".foo ~ .bar .hux", ".foo.a + .bar.b > .hux");
56 check_complex(".foo", ".bar .foo");
57 check_complex(".foo", ".foo.a");
58 check_complex(".foo.bar", ".foo");
59 check_complex(".foo .bar .hux", ".bar .hux");
60 check_complex(".foo ~ .bar .hux.x", ".foo.a + .bar.b > .hux.y");
61 check_complex(".foo ~ .bar .hux", ".foo.a + .bar.b > .mumble");
62 check_complex(".foo + .bar", ".foo ~ .bar");
63 check_complex("a c e", "a b c d e");
64 check_complex("c a e", "a b c d e");
65
66 return 0;
67}
68
69