| 1 | // Copyright 2019 the SimpleCSS Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | |
| 4 | //! Stylesheet |
| 5 | |
| 6 | use simplecss::*; |
| 7 | |
| 8 | #[test] |
| 9 | fn style_01() { |
| 10 | let style = StyleSheet::parse(""); |
| 11 | assert_eq!(style.to_string(), ""); |
| 12 | } |
| 13 | |
| 14 | #[test] |
| 15 | fn style_02() { |
| 16 | let style = StyleSheet::parse("a {}"); |
| 17 | assert_eq!(style.to_string(), ""); |
| 18 | } |
| 19 | |
| 20 | #[test] |
| 21 | fn style_03() { |
| 22 | let style = StyleSheet::parse("a { color:red }"); |
| 23 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 24 | } |
| 25 | |
| 26 | #[test] |
| 27 | fn style_04() { |
| 28 | let style = StyleSheet::parse("/**/"); |
| 29 | assert_eq!(style.to_string(), ""); |
| 30 | } |
| 31 | |
| 32 | #[test] |
| 33 | fn style_05() { |
| 34 | let style = StyleSheet::parse("a { color:red } /**/"); |
| 35 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 36 | } |
| 37 | |
| 38 | #[test] |
| 39 | fn style_06() { |
| 40 | let style = StyleSheet::parse("a, b { color:red }"); |
| 41 | assert_eq!(style.to_string(), "a { color:red; }\nb { color:red; }"); |
| 42 | } |
| 43 | |
| 44 | #[test] |
| 45 | fn style_07() { |
| 46 | let style = StyleSheet::parse("a, { color:red }"); |
| 47 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 48 | } |
| 49 | |
| 50 | #[test] |
| 51 | fn style_08() { |
| 52 | let style = StyleSheet::parse("a,, { color:red }"); |
| 53 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 54 | } |
| 55 | |
| 56 | #[test] |
| 57 | fn style_09() { |
| 58 | let style = StyleSheet::parse("a,,b { color:red }"); |
| 59 | assert_eq!(style.to_string(), "a { color:red; }\nb { color:red; }"); |
| 60 | } |
| 61 | |
| 62 | #[test] |
| 63 | fn style_10() { |
| 64 | let style = StyleSheet::parse(",a { color:red }"); |
| 65 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 66 | } |
| 67 | |
| 68 | #[test] |
| 69 | fn style_11() { |
| 70 | let style = StyleSheet::parse("@import \"subs.css\";\na { color:red }"); |
| 71 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 72 | } |
| 73 | |
| 74 | #[test] |
| 75 | fn style_12() { |
| 76 | let style = StyleSheet::parse( |
| 77 | "\ |
| 78 | @media screen { |
| 79 | p:before { content: 'Hello'; } |
| 80 | } |
| 81 | a { color:red }", |
| 82 | ); |
| 83 | assert_eq!(style.to_string(), "a { color:red; }"); |
| 84 | } |
| 85 | |
| 86 | #[test] |
| 87 | fn style_13() { |
| 88 | let style = StyleSheet::parse("a > { color:red }"); |
| 89 | assert_eq!(style.to_string(), ""); |
| 90 | } |
| 91 | |
| 92 | #[test] |
| 93 | fn style_14() { |
| 94 | let style = StyleSheet::parse("p { color:green; color }"); |
| 95 | assert_eq!(style.to_string(), "p { color:green; }"); |
| 96 | } |
| 97 | |
| 98 | #[test] |
| 99 | fn style_15() { |
| 100 | let style = StyleSheet::parse("p { color; color:green }"); |
| 101 | assert_eq!(style.to_string(), ""); // TODO: should be 'p { color:green; }' |
| 102 | } |
| 103 | |
| 104 | #[test] |
| 105 | fn style_16() { |
| 106 | let style = StyleSheet::parse("p { color:green; color: }"); |
| 107 | assert_eq!(style.to_string(), "p { color:green; }"); |
| 108 | } |
| 109 | |
| 110 | #[test] |
| 111 | fn style_17() { |
| 112 | let style = StyleSheet::parse("p { color:green; color:; color:red; }"); |
| 113 | assert_eq!(style.to_string(), "p { color:green; }"); |
| 114 | } |
| 115 | |
| 116 | #[test] |
| 117 | fn style_18() { |
| 118 | let style = StyleSheet::parse("p { color:green; color{;color:maroon} }"); |
| 119 | assert_eq!(style.to_string(), "p { color:green; }"); |
| 120 | } |
| 121 | |
| 122 | #[test] |
| 123 | fn style_19() { |
| 124 | let style = StyleSheet::parse("p { color{;color:maroon} color:green; }"); |
| 125 | assert_eq!(style.to_string(), ""); // TODO: should be 'p { color:green; }' |
| 126 | } |
| 127 | |
| 128 | #[test] |
| 129 | fn style_20() { |
| 130 | let style = StyleSheet::parse( |
| 131 | "\ |
| 132 | h1 { color: green } |
| 133 | h2 & h3 { color: red } |
| 134 | h4 { color: black } |
| 135 | ", |
| 136 | ); |
| 137 | assert_eq!( |
| 138 | style.to_string(), |
| 139 | "h1 { color:green; }\nh4 { color:black; }" |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | #[test] |
| 144 | fn style_21() { |
| 145 | let style = StyleSheet::parse(":le>*"); |
| 146 | assert_eq!(style.to_string(), ""); |
| 147 | } |