add reduce fallback for perl < 5.8.9 (mst)
[catagits/DOM-Tiny.git] / t / dom.t
diff --git a/t/dom.t b/t/dom.t
index ed69234..e345d27 100644 (file)
--- a/t/dom.t
+++ b/t/dom.t
@@ -3,6 +3,7 @@ use warnings;
 use utf8;
 use Test::More;
 use DOM::Tiny;
+use JSON::PP ();
 
 # Empty
 is(DOM::Tiny->new,                     '',    'right result');
@@ -774,9 +775,12 @@ is $dom->at('[test=""]')->tag,  'div', 'right tag';
 is $dom->at('[test2=""]')->tag, 'div', 'right tag';
 is $dom->at('[test3=""]'), undef, 'no result';
 
-# Multi-line in attribute
-$dom = DOM::Tiny->new(qq{<div test="line1\nline2" />});
-is $dom->at('div')->attr->{test}, "line1\nline2", 'multi-line attribute';
+# Multi-line attribute
+$dom = DOM::Tiny->new(qq{<div class="line1\nline2" />});
+is $dom->at('div')->attr->{class}, "line1\nline2", 'multi-line attribute value';
+is $dom->at('.line1')->tag, 'div', 'right tag';
+is $dom->at('.line2')->tag, 'div', 'right tag';
+is $dom->at('.line3'), undef, 'no result';
 
 # Whitespaces before closing bracket
 $dom = DOM::Tiny->new('<div >content</div>');
@@ -2488,9 +2492,12 @@ is $dom->tree->[3][1], ' bad idea -- HTML5 ', 'right comment';
 is $dom->tree->[5][1], ' HTML4 ',             'right comment';
 is $dom->tree->[7][1], ' bad idea -- HTML4 ', 'right comment';
 
-# Huge number of attributes
-$dom = DOM::Tiny->new('<div ' . ('a=b ' x 32768) . '>Test</div>');
-is $dom->at('div[a=b]')->text, 'Test', 'right text';
+SKIP: {
+  skip 'Regex subexpression recursion causes SIGSEGV on 5.8', 1 unless $] >= 5.010000;
+  # Huge number of attributes
+  $dom = DOM::Tiny->new('<div ' . ('a=b ' x 32768) . '>Test</div>');
+  is $dom->at('div[a=b]')->text, 'Test', 'right text';
+}
 
 # Huge number of nested tags
 my $huge = ('<a>' x 100) . 'works' . ('</a>' x 100);
@@ -2498,4 +2505,7 @@ $dom = DOM::Tiny->new($huge);
 is $dom->all_text, 'works', 'right text';
 is "$dom", $huge, 'right result';
 
+# TO_JSON
+is +JSON::PP->new->convert_blessed->encode([DOM::Tiny->new('<a></a>')]), '["<a></a>"]', 'right result';
+
 done_testing();