Commits

Shlomi Fish committed 70af1db

Add more.

Comments (0)

Files changed (2)

XML-GrammarBase/lib/XML/GrammarBase/Role/RelaxNG.pm

     return $self->rng_validate_dom($dom);
 }
 
+sub rng_validate_string
+{
+    my ($self, $xml_string) = @_;
+
+    my $xml_parser = XML::LibXML->new();
+    $xml_parser->validation(0);
+
+    my $dom = $xml_parser->parse_string($xml_string);
+
+    return $self->rng_validate_dom($dom);
+}
+
 =head1 SYNOPSIS
 
     package XML::Grammar::MyGrammar::RelaxNG::Validate;
 
 Validates the file in $file_path using the RELAX-NG schema.
 
+=head2 $self->rng_validate_string($xml_string)
+
+Validates the XML in the $xml_string using the RELAX-NG schema.
+
 =head2 BUILD
 
 L<Any::Moose> constructor. For internal use.

XML-GrammarBase/t/rng.t

 use strict;
 use warnings;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 
 package MyGrammar::RNG;
 
     # TEST
     is ($@, '', 'No exception was thrown.');
 }
+
+sub _slurp
+{
+    my $filename = shift;
+
+    open my $in, '<', $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    binmode $in, ':encoding(utf8)';
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
+{
+    my $rng = MyGrammar::RNG->new();
+
+    eval {
+        $rng->rng_validate_string(
+            _slurp(
+                File::Spec->catfile(
+                    File::Spec->curdir(), "t", "data", "fiction-xml-test.xml"
+                )
+            ),
+        );
+    };
+
+    # TEST
+    is ($@, '', 'No exception was thrown.');
+}