From fa7851ea067f8bfc71194622158afaecba650446 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 10 Jan 2017 17:15:05 +0100 Subject: [PATCH] add transform expressions tests (https://github.com/mapnik/mapnik/pull/141\ 6) (ref #3569) --- test/unit/core/transform_expressions_test.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/unit/core/transform_expressions_test.cpp diff --git a/test/unit/core/transform_expressions_test.cpp b/test/unit/core/transform_expressions_test.cpp new file mode 100644 index 000000000..748fea2af --- /dev/null +++ b/test/unit/core/transform_expressions_test.cpp @@ -0,0 +1,57 @@ +#include "catch.hpp" + +#include +#include + +namespace { + + +bool test_transform_expressions(std::string const& in, std::string const& out) +{ + auto tr_list = mapnik::parse_transform(in); + return mapnik::to_expression_string(*tr_list) == out; +} + +} + +TEST_CASE("transform-expressions") +{ + // matrix + CHECK(test_transform_expressions("matrix( 1,2,3,4,5, 6)", "matrix(1, 2, 3, 4, 5, 6)")); + CHECK(test_transform_expressions("matrix(1 2 3 4 5 6)", "matrix(1, 2, 3, 4, 5, 6)")); + CHECK(test_transform_expressions("matrix(1,2,3,4,5,4*2-1)", "matrix(1, 2, 3, 4, 5, (4*2-1))")); + + // translate + CHECK(test_transform_expressions("translate(100)", "translate(100)")); + CHECK(test_transform_expressions("translate([tx])", "translate([tx])")); + CHECK(test_transform_expressions("translate(100 200)", "translate(100, 200)")); + CHECK(test_transform_expressions("translate([tx],[ty])", "translate([tx], [ty])")); + CHECK(test_transform_expressions("translate([tx],200)", "translate([tx], 200)")); + CHECK(test_transform_expressions("translate(100,[ty])", "translate(100, [ty])")); + + // scale + CHECK(test_transform_expressions("scale(1.5)", "scale(1.5)")); + CHECK(test_transform_expressions("scale([sx])", "scale([sx])")); + CHECK(test_transform_expressions("scale([sx],1.5)", "scale([sx], 1.5)")); + CHECK(test_transform_expressions("scale(1.5,[sy])", "scale(1.5, [sy])")); + CHECK(test_transform_expressions("scale([sx],[sy]/2)", "scale([sx], [sy]/2)")); + + // rotate + CHECK(test_transform_expressions("rotate([a] -2)", "rotate(([a]-2))")); + CHECK(test_transform_expressions("rotate([a] -2 -3)", "rotate((([a]-2)-3))")); + CHECK(test_transform_expressions("rotate([a],-2,-3)", "rotate([a], -2, -3)")); + CHECK(test_transform_expressions("rotate([a] -2 -3 -4)", "rotate(((([a]-2)-3)-4))")); + CHECK(test_transform_expressions("rotate([a] -2, 3, 4)", "rotate(([a]-2), 3, 4)")); + + // skewX + CHECK(test_transform_expressions("skewX(2)", "skewX(2)")); + CHECK(test_transform_expressions("skewX(2*[x]+[y])", "skewX((2*[x]+[y]))")); + + // skewY + CHECK(test_transform_expressions("skewY(2)", "skewY(2)")); + CHECK(test_transform_expressions("skewY(2*[x]+[y])", "skewY((2*[x]+[y]))")); + + // compound + CHECK(test_transform_expressions("translate([tx]) rotate([a])", "translate([tx]) rotate([a])")); + CHECK(test_transform_expressions("rotate(30+[a]) scale(2*[sx],[sy])", "rotate((30+[a])) scale(2*[sx], [sy])")); +}