Created
February 21, 2017 19:01
-
-
Save federicomenaquintero/1ea77215bdb6b606612abfc908267703 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nom::{double}; | |
named! (pub comma, | |
tag! (b",")); | |
// Parse a viewBox attribute | |
// https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute | |
// | |
// viewBox: double [,] double [,] double [,] double [,] | |
// | |
// x, y, w, h | |
// | |
// Where w and h must be nonnegative. | |
named! (pub view_box<(f64, f64, f64, f64)>, | |
verify! (ws! (do_parse! (x: double >> | |
opt! (comma) >> | |
y: double >> | |
opt! (comma) >> | |
w: double >> | |
opt! (comma) >> | |
h: double >> | |
(x, y, w, h))), | |
|(x, y, w, h)| w >= 0.0 && h >= 0.0)); | |
#[test] | |
fn parses_view_box () { | |
assert_eq! (view_box (b"1 2 3 4"), IResult::Done (&b""[..], (1f64, 2f64, 3f64, 4f64))); | |
} | |
gives me | |
---- parsers::tests::parses_view_box stdout ---- | |
thread 'parsers::tests::parses_view_box' panicked at 'assertion failed: `(left == right)` (left: `Error(Position(Alt, [49, 32, 50, 32, 51, 32, 52]))`, right: `Done([], (1, 2, 3, 4))`)', parsers.rs:95 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment