diff --git a/testscour.py b/testscour.py
index cc6676e..04da38c 100755
--- a/testscour.py
+++ b/testscour.py
@@ -1744,34 +1744,83 @@ class DoNotRemoveGradientsWhenReferencedInStyleCss(unittest.TestCase):
'Gradients removed when referenced in CSS')
-class DoNotPrettyPrintWhenWhitespacePreserved(unittest.TestCase):
+class Whitespace(unittest.TestCase):
- def runTest(self):
- with open('unittests/whitespace-important.svg') as f:
- s = scourString(f.read()).splitlines()
- c = '''
-
-'''.splitlines()
- for i in range(4):
- self.assertEqual(s[i], c[i],
- 'Whitespace not preserved for line ' + str(i))
+ def setUp(self):
+ self.doc = scourXmlFile('unittests/whitespace.svg')
+ def test_basic(self):
+ text = self.doc.getElementById('txt_a1')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Multiple spaces not stripped from text element')
+ text = self.doc.getElementById('txt_a2')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Tab not replaced with space in text element')
+ text = self.doc.getElementById('txt_a3')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Multiple spaces not stripped from text element with xml:space="default"')
+ text = self.doc.getElementById('txt_a4')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Tab not replaced with space in text element with xml:space="default"')
+ text = self.doc.getElementById('txt_a5')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Multiple spaces not preserved in text element with xml:space="preserve"')
+ text = self.doc.getElementById('txt_a6')
+ self.assertIn('text1\ttext2', text.toxml(),
+ 'Tab not preserved in text element with xml:space="preserve"')
-class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase):
+ def test_newlines(self):
+ text = self.doc.getElementById('txt_b1')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Newline not replaced with space in text element')
+ text = self.doc.getElementById('txt_b2')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Newline not replaced with space in text element with xml:space="default"')
+ text = self.doc.getElementById('txt_b3')
+ self.assertIn('text1\n text2', text.toxml(),
+ 'Newline not preserved in text element with xml:space="preserve"')
- def runTest(self):
- with open('unittests/whitespace-nested.svg') as f:
- s = scourString(f.read()).splitlines()
- c = '''
-
-'''.splitlines()
- for i in range(4):
- self.assertEqual(s[i], c[i],
- 'Whitespace not preserved when nested for line ' + str(i))
+ def test_inheritance(self):
+ text = self.doc.getElementById('txt_c1')
+ self.assertIn('text1 text2', text.toxml(),
+ ' does not inherit xml:space="preserve" of parent text element')
+ text = self.doc.getElementById('txt_c2')
+ self.assertIn('text1 text2', text.toxml(),
+ 'xml:space="default" of does not overwrite xml:space="preserve" of parent text element')
+ text = self.doc.getElementById('txt_c3')
+ self.assertIn('text1 text2', text.toxml(),
+ 'xml:space="preserve" of does not overwrite xml:space="default" of parent text element')
+ text = self.doc.getElementById('txt_c4')
+ self.assertIn('text1 text2', text.toxml(),
+ ' does not inherit xml:space="preserve" of parent group')
+ text = self.doc.getElementById('txt_c5')
+ self.assertIn('text1 text2', text.toxml(),
+ 'xml:space="default" of text element does not overwrite xml:space="preserve" of parent group')
+ text = self.doc.getElementById('txt_c6')
+ self.assertIn('text1 text2', text.toxml(),
+ 'xml:space="preserve" of text element does not overwrite xml:space="default" of parent group')
+
+ def test_important_whitespace(self):
+ text = self.doc.getElementById('txt_d1')
+ self.assertIn('text1 text2', text.toxml(),
+ 'Newline with whitespace collapsed in text element')
+ text = self.doc.getElementById('txt_d2')
+ self.assertIn('text1 tspan1 text2', text.toxml(),
+ 'Whitespace stripped from the middle of a text element')
+ text = self.doc.getElementById('txt_d3')
+ self.assertIn('text1 tspan1 tspan2 text2', text.toxml(),
+ 'Whitespace stripped from the middle of a text element')
+
+ def test_incorrect_whitespace(self):
+ text = self.doc.getElementById('txt_e1')
+ self.assertIn('text1text2', text.toxml(),
+ 'Whitespace introduced in text element with newline')
+ text = self.doc.getElementById('txt_e2')
+ self.assertIn('text1tspantext2', text.toxml(),
+ 'Whitespace introduced in text element with ')
+ text = self.doc.getElementById('txt_e3')
+ self.assertIn('text1tspantext2', text.toxml(),
+ 'Whitespace introduced in text element with and newlines')
class GetAttrPrefixRight(unittest.TestCase):
@@ -1807,10 +1856,10 @@ class HandleEmptyStyleElement(unittest.TestCase):
class EnsureLineEndings(unittest.TestCase):
def runTest(self):
- with open('unittests/whitespace-important.svg') as f:
+ with open('unittests/newlines.svg') as f:
s = scourString(f.read())
- self.assertEqual(len(s.splitlines()), 4,
- 'Did not output line ending character correctly')
+ self.assertEqual(len(s.splitlines()), 24,
+ 'Did handle reading or outputting line ending characters correctly')
class XmlEntities(unittest.TestCase):
diff --git a/unittests/newlines.svg b/unittests/newlines.svg
new file mode 100644
index 0000000..a909603
--- /dev/null
+++ b/unittests/newlines.svg
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/unittests/whitespace-important.svg b/unittests/whitespace-important.svg
deleted file mode 100644
index 6918044..0000000
--- a/unittests/whitespace-important.svg
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
diff --git a/unittests/whitespace-nested.svg b/unittests/whitespace-nested.svg
deleted file mode 100644
index 3b99356..0000000
--- a/unittests/whitespace-nested.svg
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
diff --git a/unittests/whitespace.svg b/unittests/whitespace.svg
new file mode 100644
index 0000000..2bb48a6
--- /dev/null
+++ b/unittests/whitespace.svg
@@ -0,0 +1,40 @@
+
+