aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit/css.lua
blob: a5a8f533f173d633cbc838dd50b509ec1062742e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
103
104
105
106
107
108
109
context("CSS parsing tests", function()
  local ffi = require("ffi")
  local rspamd_mempool = require "rspamd_mempool"
  local pool = rspamd_mempool.create()
  ffi.cdef[[
const char *rspamd_css_unescape (void *pool,
            const char *begin,
            size_t len,
            size_t *olen);
void* rspamd_css_parse_style (void *pool,
            const char *begin,
            size_t len, void *err);
]]

  local cases = {
    {'#\\31 a2b3c {', '#1a2b3c {'}
  }

  for _,t in ipairs(cases) do
    test("Unescape " .. t[1], function()
      local olen = ffi.new('size_t[1]')
      local escaped = ffi.C.rspamd_css_unescape(pool:topointer(), t[1], #t[1], olen)
      escaped = ffi.string(escaped, tonumber(olen[0]))
      assert_equal(escaped, t[2], escaped .. " not equal " .. t[2])
    end)
  end

  local cases = {[[
p {
  color: red;
  text-align: center;
}
]],
[[
.center {
  text-align: center;
  color: red;
}]],
[[
/* This is a single-line comment */
/* This is
a multi-line
comment */

p {
  color: red;
}
]],
[[
p:first-child {
  color: blue;
}
a[target=_blank] #id{
  background-color: yellow;
}
* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

/* Style the header */
.header {
  background-color: #f1f1f1;
  padding: 20px;
  text-align: center;
}

/* Style the top navigation bar */
.topnav {
  overflow: hidden;
  background-color: #333;
}

/* Style the topnav links */
.topnav a{
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

/* Clear floats after the columns */
.row:after{
  content: "";
  display: table;
  clear: both;
}

/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .column.side, .column.middle {
    width: 100%;
  }
}
]]
  }
  local NULL = ffi.new 'void*'
  for i,t in ipairs(cases) do
    test("Parse css sample " .. i, function()
      local escaped = ffi.C.rspamd_css_parse_style(pool:topointer(), t, #t, NULL)
      --assert_not_nil(escaped)
    end)
  end
end)