--- /dev/null
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More tests => 2 + 2 * 9;
+
+use LaTeX::TikZ;
+
+my $tikz = Tikz->formatter(
+ format => '%d',
+);
+
+sub check {
+ my ($set, $desc, $exp) = @_;
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ my ($head, $decl, $body) = eval {
+ $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
+ };
+ is $@, '', "$desc: no error";
+
+ unless (ref $exp eq 'ARRAY') {
+ $exp = [ split /\n/, $exp ];
+ }
+ unshift @$exp, '\begin{tikzpicture}';
+ push @$exp, '\end{tikzpicture}';
+
+ is_deeply $body, $exp, $desc;
+}
+
+my $clip1 = Tikz->raw('clip1');
+my $clip2 = Tikz->raw('clip2');
+
+my $foo = eval {
+ Tikz->raw('foo')
+ ->clip($clip1);
+};
+is $@, '', 'creating a clipping a raw path with ->clip doesn\'t croak';
+
+check $foo, 'one clipped raw set', <<'RES';
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\end{scope}
+RES
+
+my $bar = eval {
+ Tikz->raw('bar')
+ ->mod(Tikz->clip(Tikz->raw('clip1')));
+};
+is $@, '', 'creating a clipping a raw path with ->mod doesn\'t croak';
+
+check $bar, 'another clipped raw set', <<'RES';
+\begin{scope}
+\clip clip1 ;
+\draw bar ;
+\end{scope}
+RES
+
+my $seq = Tikz->seq($foo, $bar);
+
+check $seq, 'mods folding with clips 1', <<'RES';
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\end{scope}
+RES
+
+my $baz = Tikz->raw('baz')
+ ->clip($clip2);
+
+check Tikz->seq($seq, $baz), 'mods folding with clips 2', <<'RES';
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\end{scope}
+\begin{scope}
+\clip clip2 ;
+\draw baz ;
+\end{scope}
+RES
+
+check Tikz->seq($baz, $seq), 'mods folding with clips 3', <<'RES';
+\begin{scope}
+\clip clip2 ;
+\draw baz ;
+\end{scope}
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\end{scope}
+RES
+
+my $seq2 = Tikz->seq($seq, $baz)
+ ->clip($clip1);
+
+check $seq2, 'mods folding with clips 4', <<'RES';
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\begin{scope}
+\clip clip2 ;
+\draw baz ;
+\end{scope}
+\end{scope}
+RES
+
+$seq2 = Tikz->seq($seq, $baz)
+ ->clip($clip2);
+
+check $seq2, 'mods folding with clips 5', <<'RES';
+\begin{scope}
+\clip clip2 ;
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\end{scope}
+\draw baz ;
+\end{scope}
+RES
+
+$seq2->clip($clip1);
+
+check $seq2, 'mods folding with clips 6', <<'RES';
+\begin{scope}
+\clip clip2 ;
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\draw baz ;
+\end{scope}
+\end{scope}
+RES
+
+$seq2->mod(Tikz->color('red'));
+
+check $seq2, 'mods folding with clips 7', <<'RES';
+\begin{scope} [color=red]
+\clip clip2 ;
+\begin{scope}
+\clip clip1 ;
+\draw foo ;
+\draw bar ;
+\draw baz ;
+\end{scope}
+\end{scope}
+RES
+