Unit tests for removing trailing zeroes and removing whitespace/commas before negative coords in path data
This commit is contained in:
parent
5d7e3a075c
commit
d6d4d3d027
3 changed files with 19 additions and 2 deletions
4
scour.py
4
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:
|
||||
|
|
|
|||
14
testscour.py
14
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):
|
||||
|
|
|
|||
3
unittests/path-truncate-zeroes.svg
Normal file
3
unittests/path-truncate-zeroes.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
|
||||
<path d="M300.0000, -100.1 z" fill="red" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 108 B |
Loading…
Add table
Add a link
Reference in a new issue