File: Easiest.t

package info (click to toggle)
libexporter-easy-perl 0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 132 kB
  • ctags: 14
  • sloc: perl: 382; makefile: 2
file content (164 lines) | stat: -rw-r--r-- 2,356 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use strict;

use Test::More tests => 21;

use lib 't';
use Run;

require_ok('Exporter::Easiest');

{
	no strict 'refs';

	*{suck_list} = \&Exporter::Easiest::suck_list;
	*{parse_spec} = \&Exporter::Easiest::parse_spec;
}

is_deeply(suck_list([qw(a b c d e)]), [qw( a b c d e )], "suck all");
is_deeply(suck_list([qw(a b c => e)]), [qw( a b )], "suck some");

is_deeply(
	{
		parse_spec(q(
			a => a b c
		))
	},
	{
		a => [qw( a b c )],
	},
	"parse 1"
);

is_deeply(
	{
		parse_spec(q(
			a => a b c
			b => g h i
		))
	},
	{
		a => [qw( a b c )],
		b => [qw( g h i )],
	},
	"parse 2"
);

is_deeply(
	{
		parse_spec(q(
			a =>
			b => g h i
		))
	},
	{
		a => [],
		b => [qw( g h i )],
	},
	"parse with empty"
);

is_deeply(
	{
		parse_spec(q(
			a =>
				:b => a b :c
				:e => e f g
		))
	},
	{
		a => [],
		TAGS =>
		[
			'b', [qw( a b :c )],
			'e', [qw( e f g )],
		]
	},
	"simple with :s"
);

is_deeply(
	{
		parse_spec(q(
			b => a b
			a =>
				:b =>
				:e => e f :g
				:d => a
			c => a :c
		))
	},
	{
		a => [],
		TAGS =>
		[
			'b', [],
			'e', [qw( e f :g )],
			'd' => ['a'],
		],
		b => [qw( a b )],
		c => [qw( a :c)],
	},
	"everything"
);

is_deeply(
	{ parse_spec(q(VARS => a b)) },
	{ VARS => [qw( a b )] },
	"VARS list"
);

is_deeply(
	{ parse_spec(q(VARS => a)) },
	{ VARS => [qw( a )] },
	"VARS list of 1"
);
is_deeply(
	{ parse_spec(q(VARS => 1)) },
	{ VARS => 1 },
	"VARS 1"
);

is_deeply(
	{ parse_spec(q(VARS => 0)) },
	{ VARS => 0 },
	"VARS 0"
);

is_deeply(
	{ parse_spec(q(ALL => all)) },
	{ ALL => 'all' },
	"good ALL works"
);

eval {parse_spec(q(ALL => all other))};
ok($@, "bad all dies");

package Test::The::Use;

use Exporter::Easiest q(
	EXPORT => e_1 e_2
	TAGS =>
		:tag1 =>  a b c d e f
		:tag2 => b d f
		:tag3 => :tag1 !:tag2
	OK => o_1 o_2
);

use vars qw( @EXPORT @EXPORT_OK %EXPORT_TAGS );

::ok(::eq_set( \@EXPORT, [ qw( e_1 e_2)] ), "use EXPORT and TAGS");
::ok(::eq_set( \@EXPORT_OK ,[qw( a b c d e f o_1 o_2 )] ), "use OK with EXPORT and TAGS"
);

my %e = %EXPORT_TAGS;

::ok(::eq_set( $e{tag1}, [qw( a b c d e f )] ), "use TAGS tag1");
::ok(::eq_set( $e{tag2}, [qw( b d f )] ), "use TAGS tag2");
::ok(::eq_set( $e{tag3}, [qw( a c e )] ), "use TAGS tag3");
::ok(keys(%e) == 3, "use TAGS count");

package Test::Vars;

use Exporter::Easiest qw( OK => $Var );

::runs_ok('$Var', 'tag vars can use var $Var');