|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +module Csscss |
| 4 | + describe Declaration do |
| 5 | + it "< and > checks parent" do |
| 6 | + dec1 = Declaration.new("background", "#fff") |
| 7 | + dec2 = Declaration.new("background", "#fff") |
| 8 | + dec3 = Declaration.new("background-color", "#fff", dec1) |
| 9 | + dec4 = Declaration.new("background-color", "#fff", nil) |
| 10 | + |
| 11 | + dec1.must_be :>, dec3 |
| 12 | + dec3.must_be :<, dec1 |
| 13 | + |
| 14 | + dec1.wont_be :>, dec2 |
| 15 | + dec1.wont_be :>, dec4 |
| 16 | + dec4.wont_be :>, dec1 |
| 17 | + end |
| 18 | + |
| 19 | + it "is a derivative if it has parent" do |
| 20 | + dec1 = Declaration.new("background", "#fff") |
| 21 | + dec1.wont_be :derivative? |
| 22 | + Declaration.new("background-color", "#fff", dec1).must_be :derivative? |
| 23 | + end |
| 24 | + |
| 25 | + it "ignores parents when checking equality" do |
| 26 | + dec1 = Declaration.new("background", "#fff") |
| 27 | + dec2 = Declaration.new("background-color", "#fff", dec1) |
| 28 | + dec3 = Declaration.new("background-color", "#fff", nil) |
| 29 | + |
| 30 | + dec1.wont_equal dec2 |
| 31 | + dec2.wont_equal dec1 |
| 32 | + |
| 33 | + dec2.must_equal dec3 |
| 34 | + dec3.must_equal dec2 |
| 35 | + |
| 36 | + dec2.hash.must_equal dec3.hash |
| 37 | + dec3.hash.must_equal dec2.hash |
| 38 | + dec3.hash.wont_equal dec1.hash |
| 39 | + |
| 40 | + dec2.must_be :eql?, dec3 |
| 41 | + dec3.must_be :eql?, dec2 |
| 42 | + dec2.wont_be :eql?, dec1 |
| 43 | + end |
| 44 | + |
| 45 | + it "derivatives are handled correctly in a hash" do |
| 46 | + dec1 = Declaration.new("background", "#fff") |
| 47 | + dec2 = Declaration.new("background-color", "#fff", dec1) |
| 48 | + dec3 = Declaration.new("background-color", "#fff", nil) |
| 49 | + |
| 50 | + h = {} |
| 51 | + h[dec2] = false |
| 52 | + h[dec3] = true |
| 53 | + |
| 54 | + h.keys.size.must_equal 1 |
| 55 | + h[dec2].must_equal true |
| 56 | + h[dec3].must_equal true |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments