]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - t/01-api.t
106ebbe649b573ea0ffe84c8e09bf5310e83b2c3
[perl/modules/LaTeX-TikZ.git] / t / 01-api.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5 + 16 + 12;
7
8 use LaTeX::TikZ;
9
10 ok(defined &Tikz,         'main::Tikz constant is defined');
11 is(prototype('Tikz'), '', 'main::Tikz is actually a constant');
12
13 {
14  package LaTeX::TikZ::TestAPI1;
15
16  eval {
17   LaTeX::TikZ->import(as => ':)');
18  };
19  ::like($@, qr/^Invalid name/, 'invalid name');
20 }
21
22 {
23  package LaTeX::TikZ::TestAPI2;
24
25  use LaTeX::TikZ as => 'T';
26
27  ::ok(defined &T,         'LaTeX::TikZ::TestAPI2::T constant is defined');
28  ::is(prototype('T'), '', 'LaTeX::TikZ::TestAPI2::T is actually a constant');
29 }
30
31 my @methods = qw/
32  raw
33  path seq
34  point line polyline closed_polyline rectangle circle arc
35  raw_mod
36  clip layer
37  width color fill
38 /;
39
40 for (@methods) {
41  ok(Tikz->can($_), "Tikz evaluates to something that ->can($_)");
42 }
43
44 require LaTeX::TikZ::Interface;
45
46 for my $name (undef, ':)') {
47  eval {
48   LaTeX::TikZ::Interface->import(
49    $name => sub { },
50   );
51  };
52  like $@, qr/^Invalid interface name/, 'invalid interface name';
53 }
54
55 eval {
56  LaTeX::TikZ::Interface->import(
57   'raw' => sub { },
58  );
59 };
60 like $@, qr/^'raw' is already defined/, 'already defined';
61
62 for my $code (undef, [ ]) {
63  eval {
64   LaTeX::TikZ::Interface->import(
65    'foo' => $code,
66   );
67  };
68  like $@, qr/^Invalid code reference/, 'invalid code';
69 }
70
71 eval {
72  LaTeX::TikZ::Interface->import(
73   'foo' => sub { @_ },
74  );
75 };
76 is $@,           '', 'registering foo doesn\'t croak';
77 ok(Tikz->can('foo'), 'Tikz evaluates to something that ->can(foo)');
78 is_deeply [ Tikz->foo('hello') ], [ Tikz, 'hello' ], 'Tikz->foo works';
79
80 eval {
81  LaTeX::TikZ::Interface->import(
82   'bar' => sub { @_ },
83   'baz' => undef,
84  );
85 };
86 like $@, qr/^Invalid code reference/, 'baz is invalid code';
87 ok(!Tikz->can('baz'), 'baz was not defined');
88 ok(Tikz->can('bar'),  'but bar was defined');
89 is_deeply [ Tikz->bar('bonjour') ], [ Tikz, 'bonjour' ], 'Tikz->bar works';