]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blob - t/11-integrate.t
Initial import
[perl/modules/Lexical-Types.git] / t / 11-integrate.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5 + 4;
7
8 {
9  package MyTypes;
10
11  BEGIN { require Lexical::Types; }
12
13  sub import {
14   eval 'package Str; package Int';
15   Lexical::Types->import(
16    as => sub { __PACKAGE__, 'new_' . lc($_[0]) }
17   );
18  }
19
20  sub unimport {
21   Lexical::Types->unimport;
22  }
23
24  sub new_str {
25   $_[1] = 'str:' . (caller(0))[2];
26   Test::More::is($_[2], 'Str', 'original type is correct');
27   ();
28  }
29
30  sub new_int {
31   $_[1] = (caller(0))[2];
32   Test::More::is($_[2], 'Int', 'original type is correct');
33   ();
34  }
35 }
36
37 {
38  BEGIN { MyTypes->import }
39  my Str $x;
40  is $x, 'str:' . (__LINE__-1), 'MyTypes->new_str 1';
41  {
42   BEGIN { MyTypes->unimport }
43   my Str $y;
44   is $y, undef, 'pragma not in use';
45   {
46    BEGIN { MyTypes->import }
47    my Int $z;
48    is $z, __LINE__-1, 'MyTypes->new_int 1';
49   }
50  }
51  my Str $y;
52  is $y, 'str:' . (__LINE__-1), 'MyTypes->new_str 2';
53  my Int $z;
54  is $z, __LINE__-1, 'MyTypes->new_int 2';
55 }