]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - t/11-point.t
Allow a bare Tikz->point for 0
[perl/modules/LaTeX-TikZ.git] / t / 11-point.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6 + 2 * 6;
7
8 use Math::Complex;
9
10 use LaTeX::TikZ;
11
12 my $tikz = Tikz->formatter(
13  format => '%d',
14 );
15
16 sub check {
17  my ($set, $desc, $exp) = @_;
18
19  local $Test::Builder::Level = $Test::Builder::Level + 1;
20
21  my ($head, $decl, $body) = eval {
22   $tikz->render(ref $set eq 'ARRAY' ? @$set : $set);
23  };
24  is $@, '', "$desc: no error";
25
26  unless (ref $exp eq 'ARRAY') {
27   $exp = [ split /\n/, $exp ];
28  }
29  unshift @$exp, '\begin{tikzpicture}';
30  push    @$exp, '\end{tikzpicture}';
31
32  is_deeply $body, $exp, $desc;
33 }
34
35 my $z = Math::Complex->make(1, 2);
36
37 my $p = eval {
38  Tikz->point($z);
39 };
40 is $@, '', 'creating a point from a Math::Complex object doesn\'t croak';
41
42 check $p, 'a point from a Math::Complex object', <<'RES';
43 \draw (1cm,2cm) ;
44 RES
45
46 $p = eval {
47  Tikz->point(1-2*i);
48 };
49 is $@, '', 'creating a point from a Math::Complex constant object doesn\'t croak';
50
51 check $p, 'a point from a constant Math::Complex object', <<'RES';
52 \draw (1cm,-2cm) ;
53 RES
54
55 $p = eval {
56  Tikz->point;
57 };
58 is $@, '', 'creating a point from nothing doesn\'t croak';
59
60 check $p, 'a point from nothing', <<'RES';
61 \draw (0cm,0cm) ;
62 RES
63
64 $p = eval {
65  Tikz->point(-7);
66 };
67 is $@, '', 'creating a point from a numish constant doesn\'t croak';
68
69 check $p, 'a point from a numish constant', <<'RES';
70 \draw (-7cm,0cm) ;
71 RES
72
73 $p = eval {
74  Tikz->point(5,-1);
75 };
76 is $@, '', 'creating a point from two numish constants doesn\'t croak';
77
78 check $p, 'a point from two numish constants', <<'RES';
79 \draw (5cm,-1cm) ;
80 RES
81
82 $p = eval {
83  Tikz->point([-3, 2]);
84 };
85 is $@, '', 'creating a point from an array ref doesn\'t croak';
86
87 check $p, 'a point from an array ref', <<'RES';
88 \draw (-3cm,2cm) ;
89 RES