summaryrefslogtreecommitdiffstats
path: root/servo/tests/unit/style/parsing/effects.rs
blob: faf1126efa0a59c294fbe781be6846cedabc3dd1 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use parsing::parse;
use style::properties::longhands::{perspective_origin, transform_origin};
use style_traits::ToCss;

#[test]
fn test_clip() {
    use style::properties::longhands::clip;

    assert_roundtrip_with_context!(clip::parse, "auto");
    assert_roundtrip_with_context!(clip::parse, "rect(1px, 2px, 3px, 4px)");
    assert_roundtrip_with_context!(clip::parse, "rect(1px, auto, auto, 4px)");
    assert_roundtrip_with_context!(clip::parse, "rect(auto, auto, auto, auto)");

    // Non-standard syntax
    assert_roundtrip_with_context!(clip::parse,
                                   "rect(1px 2px 3px 4px)",
                                   "rect(1px, 2px, 3px, 4px)");
    assert_roundtrip_with_context!(clip::parse,
                                   "rect(auto 2px 3px auto)",
                                   "rect(auto, 2px, 3px, auto)");
    assert_roundtrip_with_context!(clip::parse,
                                   "rect(1px auto auto 4px)",
                                   "rect(1px, auto, auto, 4px)");
    assert_roundtrip_with_context!(clip::parse,
                                   "rect(auto auto auto auto)",
                                   "rect(auto, auto, auto, auto)");
}

#[test]
fn test_effects_parser_exhaustion() {
    assert_parser_exhausted!(perspective_origin::parse, "1px 1px", true);
    assert_parser_exhausted!(transform_origin::parse, "1px 1px", true);

    assert_parser_exhausted!(perspective_origin::parse, "1px some-rubbish", false);
    assert_parser_exhausted!(transform_origin::parse, "1px some-rubbish", false);
}

#[test]
fn test_parse_factor() {
    use parsing::parse;
    use style::properties::longhands::filter;

    assert!(parse(filter::parse, "brightness(0)").is_ok());
    assert!(parse(filter::parse, "brightness(55)").is_ok());
    assert!(parse(filter::parse, "brightness(100)").is_ok());

    assert!(parse(filter::parse, "contrast(0)").is_ok());
    assert!(parse(filter::parse, "contrast(55)").is_ok());
    assert!(parse(filter::parse, "contrast(100)").is_ok());

    assert!(parse(filter::parse, "grayscale(0)").is_ok());
    assert!(parse(filter::parse, "grayscale(55)").is_ok());
    assert!(parse(filter::parse, "grayscale(100)").is_ok());

    assert!(parse(filter::parse, "invert(0)").is_ok());
    assert!(parse(filter::parse, "invert(55)").is_ok());
    assert!(parse(filter::parse, "invert(100)").is_ok());

    assert!(parse(filter::parse, "opacity(0)").is_ok());
    assert!(parse(filter::parse, "opacity(55)").is_ok());
    assert!(parse(filter::parse, "opacity(100)").is_ok());

    assert!(parse(filter::parse, "sepia(0)").is_ok());
    assert!(parse(filter::parse, "sepia(55)").is_ok());
    assert!(parse(filter::parse, "sepia(100)").is_ok());

    assert!(parse(filter::parse, "saturate(0)").is_ok());
    assert!(parse(filter::parse, "saturate(55)").is_ok());
    assert!(parse(filter::parse, "saturate(100)").is_ok());

    // Negative numbers are invalid for certain filters
    assert!(parse(filter::parse, "brightness(-1)").is_err());
    assert!(parse(filter::parse, "contrast(-1)").is_err());
    assert!(parse(filter::parse, "grayscale(-1)").is_err());
    assert!(parse(filter::parse, "invert(-1)").is_err());
    assert!(parse(filter::parse, "opacity(-1)").is_err());
    assert!(parse(filter::parse, "sepia(-1)").is_err());
    assert!(parse(filter::parse, "saturate(-1)").is_err());
}

#[test]
fn blur_radius_should_not_accept_negavite_values() {
    use style::properties::longhands::box_shadow;
    assert!(parse(box_shadow::parse, "1px 1px -1px").is_err());// for -ve values
    assert!(parse(box_shadow::parse, "1px 1px 0").is_ok());// for zero
    assert!(parse(box_shadow::parse, "1px 1px 1px").is_ok());// for +ve value
}