1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 use parsing::parse;
6 use style::properties::longhands::{perspective_origin, transform_origin};
7 use style_traits::ToCss;
8 
9 #[test]
test_clip()10 fn test_clip() {
11     use style::properties::longhands::clip;
12 
13     assert_roundtrip_with_context!(clip::parse, "auto");
14     assert_roundtrip_with_context!(clip::parse, "rect(1px, 2px, 3px, 4px)");
15     assert_roundtrip_with_context!(clip::parse, "rect(1px, auto, auto, 4px)");
16     assert_roundtrip_with_context!(clip::parse, "rect(auto, auto, auto, auto)");
17 
18     // Non-standard syntax
19     assert_roundtrip_with_context!(clip::parse,
20                                    "rect(1px 2px 3px 4px)",
21                                    "rect(1px, 2px, 3px, 4px)");
22     assert_roundtrip_with_context!(clip::parse,
23                                    "rect(auto 2px 3px auto)",
24                                    "rect(auto, 2px, 3px, auto)");
25     assert_roundtrip_with_context!(clip::parse,
26                                    "rect(1px auto auto 4px)",
27                                    "rect(1px, auto, auto, 4px)");
28     assert_roundtrip_with_context!(clip::parse,
29                                    "rect(auto auto auto auto)",
30                                    "rect(auto, auto, auto, auto)");
31 }
32 
33 #[test]
test_effects_parser_exhaustion()34 fn test_effects_parser_exhaustion() {
35     assert_parser_exhausted!(perspective_origin::parse, "1px 1px", true);
36     assert_parser_exhausted!(transform_origin::parse, "1px 1px", true);
37 
38     assert_parser_exhausted!(perspective_origin::parse, "1px some-rubbish", false);
39     assert_parser_exhausted!(transform_origin::parse, "1px some-rubbish", false);
40 }
41 
42 #[test]
test_parse_factor()43 fn test_parse_factor() {
44     use parsing::parse;
45     use style::properties::longhands::filter;
46 
47     assert!(parse(filter::parse, "brightness(0)").is_ok());
48     assert!(parse(filter::parse, "brightness(55)").is_ok());
49     assert!(parse(filter::parse, "brightness(100)").is_ok());
50 
51     assert!(parse(filter::parse, "contrast(0)").is_ok());
52     assert!(parse(filter::parse, "contrast(55)").is_ok());
53     assert!(parse(filter::parse, "contrast(100)").is_ok());
54 
55     assert!(parse(filter::parse, "grayscale(0)").is_ok());
56     assert!(parse(filter::parse, "grayscale(55)").is_ok());
57     assert!(parse(filter::parse, "grayscale(100)").is_ok());
58 
59     assert!(parse(filter::parse, "invert(0)").is_ok());
60     assert!(parse(filter::parse, "invert(55)").is_ok());
61     assert!(parse(filter::parse, "invert(100)").is_ok());
62 
63     assert!(parse(filter::parse, "opacity(0)").is_ok());
64     assert!(parse(filter::parse, "opacity(55)").is_ok());
65     assert!(parse(filter::parse, "opacity(100)").is_ok());
66 
67     assert!(parse(filter::parse, "sepia(0)").is_ok());
68     assert!(parse(filter::parse, "sepia(55)").is_ok());
69     assert!(parse(filter::parse, "sepia(100)").is_ok());
70 
71     assert!(parse(filter::parse, "saturate(0)").is_ok());
72     assert!(parse(filter::parse, "saturate(55)").is_ok());
73     assert!(parse(filter::parse, "saturate(100)").is_ok());
74 
75     // Negative numbers are invalid for certain filters
76     assert!(parse(filter::parse, "brightness(-1)").is_err());
77     assert!(parse(filter::parse, "contrast(-1)").is_err());
78     assert!(parse(filter::parse, "grayscale(-1)").is_err());
79     assert!(parse(filter::parse, "invert(-1)").is_err());
80     assert!(parse(filter::parse, "opacity(-1)").is_err());
81     assert!(parse(filter::parse, "sepia(-1)").is_err());
82     assert!(parse(filter::parse, "saturate(-1)").is_err());
83 }
84 
85 #[test]
blur_radius_should_not_accept_negavite_values()86 fn blur_radius_should_not_accept_negavite_values() {
87     use style::properties::longhands::box_shadow;
88     assert!(parse(box_shadow::parse, "1px 1px -1px").is_err());// for -ve values
89     assert!(parse(box_shadow::parse, "1px 1px 0").is_ok());// for zero
90     assert!(parse(box_shadow::parse, "1px 1px 1px").is_ok());// for +ve value
91 }
92