File: rt133141.t

package info (click to toggle)
libtype-tiny-perl 2.004000-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,856 kB
  • sloc: perl: 14,858; makefile: 2; sh: 1
file content (56 lines) | stat: -rw-r--r-- 1,636 bytes parent folder | download | duplicates (2)
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
=pod

=encoding utf-8

=head1 PURPOSE

Make sure that L<Tuple[Enum["test string"]]> can initialize in XS

=head1 SEE ALSO

L<https://rt.cpan.org/Ticket/Display.html?id=133141>.

=head1 AUTHOR

Andrew Ruder E<lt>andy@aeruder.net<gt>

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2020-2023 by Andrew Ruder

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

use strict;
use warnings FATAL=> 'all';
use Test::More;
use Type::Tiny;
use Types::Standard qw[ Tuple Enum ];
use Type::Parser qw( eval_type );
use Type::Registry;

plan tests => 10;

my $type1 = Tuple[Enum[qw(a b)]];
ok $type1->check(["a"]), '"a" matches Enum[qw(a b)]';
ok !$type1->check(["c"]), '"c" does not match Enum[qw(a b)]';

my $type2 = Tuple[Enum["foo bar"]];
ok $type2->check(["foo bar"]), '"foo bar" matches Enum["foo bar"]';
ok !$type2->check(["baz"]), '"baz" does not match Enum["foo bar"]';

my $type3 = Tuple[Enum["test\""]];
ok $type3->check(["test\""]), '"test\"" matches Enum["test\""]';
ok !$type3->check(["baz"]), '"baz" does not match Enum["test\""]';

my $type4 = Tuple[Enum["hello, world"]];
ok $type4->check(["hello, world"]), '"hello, world" matches Enum["hello, world"]';
ok !$type4->check(["baz"]), '"baz" does not match Enum["hello, world"]';

my $reg = Type::Registry->for_me;
$reg->add_types("Types::Standard");
my $type5 = eval_type("Tuple[Enum[\"hello, world\"]]", $reg);
ok $type5->check(["hello, world"]), "eval_type() evaluates quoted strings";
ok !$type5->check(["baz"]), "eval_type() evaluates quoted strings and doesn't pass 'baz'";