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
|
# encoding: utf-8
require_relative 'support/common'
describe 'Serialization' do
make_my_diffs_pretty!
parallelize_me!
# Parse a bunch of real-world CSS and make sure it's the same when we
# serialize it.
Dir[File.join(File.dirname(__FILE__), 'support/serialization/*.css')].each do |filepath|
it "should parse and serialize #{filepath}" do
input = File.read(filepath)
tree = Crass.parse(input,
:preserve_comments => true,
:preserve_hacks => true)
assert_equal(input, CP.stringify(tree))
end
end
# -- Regression tests --------------------------------------------------------
it "should not omit a trailing semicolon when serializing a `@charset` rule" do
css = '@charset "utf-8";'
tree = Crass.parse(css)
assert_equal(css, CP.stringify(tree))
end
it "should reflect modifications made to the block of an `:at_rule`" do
tree = Crass.parse(%[
@media (screen) {
.froggy { color: green; }
.piggy { color: pink; }
}
].strip)
tree[0][:block] = Crass::Parser.parse_rules(".piggy { color: pink; }")
assert_equal(
"@media (screen) {.piggy { color: pink; }}",
Crass::Parser.stringify(tree)
)
end
it "should serialize a @page rule" do
css = %[
@page { margin: 2cm }
@page :right {
@top-center { content: "Preliminary edition" }
@bottom-center { content: counter(page) }
}
@page {
size: 8.5in 11in;
margin: 10%;
@top-left {
content: "Hamlet";
}
@top-right {
content: "Page " counter(page);
}
}
].strip
tree = Crass.parse(css)
assert_equal(css, Crass::Parser.stringify(tree))
end
end
|