From d6d4d3d0275aa5d6b716d39ba0afd9e37207c986 Mon Sep 17 00:00:00 2001 From: JSCHILL1 Date: Sun, 26 Apr 2009 20:38:22 -0500 Subject: [PATCH] Unit tests for removing trailing zeroes and removing whitespace/commas before negative coords in path data --- scour.py | 4 ++-- testscour.py | 14 ++++++++++++++ unittests/path-truncate-zeroes.svg | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 unittests/path-truncate-zeroes.svg diff --git a/scour.py b/scour.py index c33017d..f484bf6 100755 --- a/scour.py +++ b/scour.py @@ -64,7 +64,6 @@ import math import base64 import os.path import urllib -import svg_regex from svg_regex import svg_parser APP = 'scour' @@ -630,7 +629,8 @@ def serializePath(pathObj): # if coord can be an integer without loss of precision, go for it if int(coord) == coord: pathStr += str(int(coord)) else: pathStr += str(coord) - if c < len(data)-1: + # only need the comma if the next number if non-negative + if c < len(data)-1 and data[c+1] >= 0: pathStr += ',' c += 1 except TypeError: diff --git a/testscour.py b/testscour.py index 0d3e1ed..fb5b335 100755 --- a/testscour.py +++ b/testscour.py @@ -20,6 +20,7 @@ import unittest import scour import xml.dom.minidom +from svg_regex import svg_parser SVGNS = 'http://www.w3.org/2000/svg' @@ -421,6 +422,19 @@ class DoNotCollapseMultiplyReferencedGradients(unittest.TestCase): self.assertNotEquals(len(doc.getElementsByTagNameNS(SVGNS, 'linearGradient')), 0, 'Multiply-referenced linear gradient collapsed' ) +class RemoveTrailingZeroesFromPath(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/path-truncate-zeroes.svg') + path = doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d') + self.assertEquals(path[:4] == 'M300' and path[4] != '.', True, + 'Trailing zeros not removed from path data' ) + +class RemoveDelimiterBeforeNegativeCoordsInPath(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/path-truncate-zeroes.svg') + path = doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d') + self.assertEquals(path[4], '-', + 'Delimiters not removed before negative coordinate in path data' ) #class RemoveUnreferencedFonts(unittest.TestCase): # def runTest(self): diff --git a/unittests/path-truncate-zeroes.svg b/unittests/path-truncate-zeroes.svg new file mode 100644 index 0000000..4de6d52 --- /dev/null +++ b/unittests/path-truncate-zeroes.svg @@ -0,0 +1,3 @@ + + +