]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - t/11-point.t
Update VPIT::TestHelpers to 15e8aee3
[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 => 8 + 2 * 8 + 2 * (1 + 2 * 3);
7
8 use Math::Complex;
9
10 use LaTeX::TikZ;
11
12 use lib 't/lib';
13 use LaTeX::TikZ::TestHelper;
14
15 using Tikz->formatter(
16  format => '%d',
17 );
18
19 my $z = Math::Complex->make(1, 2);
20
21 my $p = eval {
22  Tikz->point($z);
23 };
24 is $@, '', 'creating a point from a Math::Complex object doesn\'t croak';
25
26 check $p, 'a point from a Math::Complex object', <<'RES';
27 \draw (1cm,2cm) ;
28 RES
29
30 $p = eval {
31  Tikz->point(1-2*i);
32 };
33 is $@, '', 'creating a point from a Math::Complex constant object doesn\'t croak';
34
35 check $p, 'a point from a constant Math::Complex object', <<'RES';
36 \draw (1cm,-2cm) ;
37 RES
38
39 $p = eval {
40  Tikz->point;
41 };
42 is $@, '', 'creating a point from nothing doesn\'t croak';
43
44 check $p, 'a point from nothing', <<'RES';
45 \draw (0cm,0cm) ;
46 RES
47
48 $p = eval {
49  Tikz->point(-7);
50 };
51 is $@, '', 'creating a point from a numish constant doesn\'t croak';
52
53 check $p, 'a point from a numish constant', <<'RES';
54 \draw (-7cm,0cm) ;
55 RES
56
57 $p = eval {
58  Tikz->point(5,-1);
59 };
60 is $@, '', 'creating a point from two numish constants doesn\'t croak';
61
62 check $p, 'a point from two numish constants', <<'RES';
63 \draw (5cm,-1cm) ;
64 RES
65
66 $p = eval {
67  Tikz->point([-3, 2]);
68 };
69 is $@, '', 'creating a point from an array ref doesn\'t croak';
70
71 check $p, 'a point from an array ref', <<'RES';
72 \draw (-3cm,2cm) ;
73 RES
74
75 $p = eval {
76  Tikz->point(
77   [1,-1],
78   label => 'foo',
79  );
80 };
81 is $@, '', 'creating a labeled point from an array ref doesn\'t croak';
82
83 check $p, 'a labeled point', <<'RES';
84 \draw (1cm,-1cm) [fill] circle (0.4pt) node[scale=0.20,above] {foo} ;
85 RES
86
87 $p = eval {
88  Tikz->point(
89   [2,-2],
90   label => 'bar',
91   pos   => 'below right',
92  );
93 };
94 is $@, '',
95          'creating a labeled positioned point from an array ref doesn\'t croak';
96
97 check $p, 'a labeled positioned point', <<'RES';
98 \draw (2cm,-2cm) [fill] circle (0.4pt) node[scale=0.20,below right] {bar} ;
99 RES
100
101 my $union = eval {
102  Tikz->union(
103   Tikz->point([ 0, -1 ]),
104   Tikz->raw("foo"),
105   Tikz->point(9)
106  );
107 };
108 is          $@,            '',    'creating a simple union path doesn\'t croak';
109 is_point_ok $union->begin, 0, -1, 'beginning of a simple union path';
110 is_point_ok $union->end,   9, 0,  'end of a simple union path';
111
112 my $path = eval {
113  Tikz->union(
114   Tikz->join('--' => 1, 2, 3),
115   $union,
116   Tikz->chain(5 => '--' => [ 6, 1 ]),
117  );
118 };
119 is          $@,           '',   'creating a complex union path doesn\'t croak';
120 is_point_ok $path->begin, 1, 0, 'beginning of a complex union path';
121 is_point_ok $path->end,   6, 1, 'end of a complex union path';