# HG changeset patch
# User Winston W <winstonw@stratolab.com>
# Date 1360022422 28800
# Node ID 10e773e95a871dc6a6226c1b56735672837cc3d3
# Parent  3888a2547945597412550f29bede1abdfe8235d8
Add AttributedTextDecoderTests and test that two newlines becomes one in output.

diff --git a/pyglet/text/formats/attributed.py b/pyglet/text/formats/attributed.py
--- a/pyglet/text/formats/attributed.py
+++ b/pyglet/text/formats/attributed.py
@@ -86,7 +86,7 @@
                 self.append('\n')
                 trailing_newline = True
             elif group == 'nl_para':
-                self.append(m.group('nl_para'))
+                self.append(m.group('nl_para')[1:]) # ignore the first \n
                 trailing_newline = True
             elif group == 'attr':
                 try:
diff --git a/tests/plan.txt b/tests/plan.txt
--- a/tests/plan.txt
+++ b/tests/plan.txt
@@ -228,3 +228,4 @@
     text.HTML                                   GENERIC
     text.HTML_IMAGE                             GENERIC
     text.MULTILINE_WRAP                         GENERIC
+    text.ATTRIBUTED_TEXT_DECODER                GENERIC
diff --git a/tests/text/ATTRIBUTED_TEXT_DECODER.py b/tests/text/ATTRIBUTED_TEXT_DECODER.py
new file mode 100644
--- /dev/null
+++ b/tests/text/ATTRIBUTED_TEXT_DECODER.py
@@ -0,0 +1,17 @@
+import unittest
+
+from pyglet.text.formats.attributed import AttributedTextDecoder
+
+class AttributedTextDecoderTests(unittest.TestCase):
+    __noninteractive = True
+    def testOneNewlineBecomesSpace(self):
+        doc = AttributedTextDecoder().decode('one\ntwo')
+        self.assertEqual(u'one two', doc.text)
+        
+    def testTwoNewlinesBecomesParagraph(self):
+        from pyglet.text.formats.attributed import AttributedTextDecoder
+        doc = AttributedTextDecoder().decode('one\n\ntwo')
+        self.assertEqual(u'one\ntwo', doc.text)
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/text/MULTILINE_WRAP.py b/tests/text/MULTILINE_WRAP.py
--- a/tests/text/MULTILINE_WRAP.py
+++ b/tests/text/MULTILINE_WRAP.py
@@ -112,5 +112,6 @@
         self.window.set_visible()
         app.run()
 
+
 if __name__ == '__main__':
     unittest.main()
