Commits

Shlomi Fish committed 4e283fc

* Get rid of trailing space in comments with newlines.

- Apparently XML::Writer appends surrounding spaces to the comments
being output, and if the comment starts or ends with a newline,
then it's a problem.
- Checking in a test in:
- t/screenplay/proto-text-to-xml-using-custom-parser.t

  • Participants
  • Parent commits 2c580ae

Comments (0)

Files changed (5)

perl/modules/XML-Grammar-Fiction/Changes

 Revision history for XML-Grammar-Fiction.
 
+    * Got rid of trailing space in comments with newlines.
+        - Apparently XML::Writer appends surrounding spaces to the comments
+        being output, and if the comment starts or ends with a newline,
+        then it's a problem.
+        - Checking in a test in:
+            - t/screenplay/proto-text-to-xml-using-custom-parser.t
+
+
 v0.14.3     2013-04-30
     * Convert 'Changes' (this file) to CPAN::Changes.
         - Add a test in dist.ini.

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/FictionBase/TagsTree2XML.pm

 {
     my ($self, $elem) = @_;
 
-    $self->_writer->comment($elem->text());
+    my $text = $elem->text();
+
+    # To avoid trailing space due to a problem in XML::Writer
+    $text =~ s{\A[\r\n]+}{}ms;
+
+    if ($text =~ m{\n\z})
+    {
+        $text .= ' ';
+    }
+
+    $self->_writer->comment($text);
 }
 
 sub _calc_write_elem_obj_classes

perl/modules/XML-Grammar-Fiction/t/screenplay/data/proto-text/with-comments-with-newlines.txt

+<s id="top">
+
+<s id="david_and_goliath">
+
+David: I will kill you.
+
+<!-- David and Goliath are Biblical characters -->
+
+Goliath: no way, you little idiot!
+
+<!--
+FILL IN - some scenes.
+-->
+
+David: yes way!
+
+</s>
+
+</s>

perl/modules/XML-Grammar-Fiction/t/screenplay/data/xml/with-comments-with-newlines.xml

+<?xml version='1.0' encoding='utf-8'?>
+<document xmlns="http://web-cpan.berlios.de/modules/XML-Grammar-Screenplay/screenplay-xml-0.2/">
+    <head>
+    </head>
+    <body id="index">
+<scene id="top">
+    <scene id="david_and_goliath">
+        <saying character="David">
+            <para>
+                I will kill you.
+            </para>
+            <!-- David and Goliath are Biblical characters -->
+        </saying>
+        <saying character="Goliath">
+            <para>
+                no way, you little idiot!
+            </para>
+            <!--
+FILL IN - some scenes.
+            -->
+        </saying>
+        <saying character="David">
+            <para>
+                yes way!
+            </para>
+        </saying>
+</scene>
+
+</scene>
+</body>
+</document>

perl/modules/XML-Grammar-Fiction/t/screenplay/proto-text-to-xml-using-custom-parser.t

 
 use lib './t/lib';
 
-use Test::More tests => 54;
+use Test::More tests => 76;
 
 use XmlGrammarTestXML qw(my_is_xml);
 
         with-img-element-inside-paragraphs
         with-internal-description
         with-comments
+        with-comments-with-newlines
         with-multi-para-desc
         with-multi-line-comments
         scenes-with-titles
         with-numeric-entities
     ));
 
-# TEST:$num_texts=18
+# TEST:$num_texts=19
 
 my $grammar = XML::Grammar::Screenplay::FromProto->new({
         parser_class => "XML::Grammar::Screenplay::FromProto::Parser::QnD",
     unlike ($got_xml, qr{^<!DOCTYPE}ms, "No doctype in \"$fn\"");
 
     # TEST*$num_texts
+    unlike ($got_xml, qr{[ \t+]$}ms, "No trailing space in \"$fn\"");
+
+    # TEST*$num_texts
     my_is_xml (
         [ string => $got_xml, ],
         [ string => load_xml("t/screenplay/data/xml/$fn.xml"), ],