Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 141 lines (106 sloc) 4.203 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
2 use Test;
eff0660 @moritz test that defined() is a listop, RT #76448
moritz authored
3 plan 56;
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
4
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
5 # L<S32::Basics/Mu/=item defined>
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
6
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
7 =begin pod
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
8
9 Tests for the defined() builtin
10
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
11 =end pod
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
12
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
13 ok(!defined(Mu), 'Mu is not defined');
14 ok(!defined(Int), 'Int is not defined');
15 ok(!defined(Num), 'Num is not defined');
16 ok(!defined(Str), 'Str is not defined');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
17
18 ok(defined(1), 'numeric literal 1 is defined');
19 ok(defined(""), 'empty string is defined');
20 ok(defined("a"), '"a" is defined');
21 ok(defined(0), 'numeric literal 0 is defined');
cd714c4 Added tests for Nil, (), [], and {} definedness.
plunix authored
22 ok(defined(()), 'empty Parcel is defined');
23 ok(defined([]), 'empty Array is defined');
24 ok(defined({}), 'empty Hash is defined');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
25
26 my $foo;
27 ok(!defined($foo), 'unassigned variable $foo is undefined');
28
29 $foo = 1;
30 ok(defined($foo), 'variable $foo is now defined (as numeric literal 1)');
31
32 $foo = "";
33 ok(defined($foo), 'variable $foo is now defined (as a empty string)');
34
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
35 $foo = Nil;
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
36 ok(!defined($foo), 'variable $foo is now undefined again');
37
38 $foo = "a";
39 ok(defined($foo), 'variable $foo is now defined (as string "a")');
40
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
41 $foo = Mu;
42 ok(!defined($foo), 'variable $foo is now undefined again');
43
44 $foo = "b";
45 ok(defined($foo), 'variable $foo is now defined (as string "b")');
46
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
47 $foo = 0;
48 ok(defined($foo), 'variable $foo is now defined (as numeric literal 0)');
49
252783d @colomon Fudge for niecza.
colomon authored
50 {
51 undefine($foo);
52 ok(!defined($foo), 'undefine $foo works');
53 }
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
54
cd714c4 Added tests for Nil, (), [], and {} definedness.
plunix authored
55 # containers
56
57 my @bax;
58 ok(defined(@bax), 'unassigned variable @bax is defined');
59
60 @bax = 3, 4, 5;
61 ok(defined(@bax), 'unassigned variable @bax is defined');
62
63 @bax = Nil;
64 ok(defined(@bax), 'variable @bax is defined after assigning Nil');
65
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
66 # try the invocant syntax
67
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
68 {
3a22efd [t/spec] update some Nil tests to reflect last spec change
moritz authored
69 my Mu $foo;
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
70 ok(!$foo.defined, 'unassigned variable $foo is undefined');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
71
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
72 $foo = 1;
73 ok($foo.defined, 'variable $foo is now defined (as numeric literal 1)');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
74
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
75 $foo = "";
76 ok($foo.defined, 'variable $foo is now defined (as a empty string)');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
77
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
78 $foo = Nil;
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
79 ok(!$foo.defined, 'variable $foo is now undefined again');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
80
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
81 $foo = "a";
82 ok($foo.defined, 'variable $foo is now defined (as string "a")');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
83
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
84 $foo = Mu;
85 ok(!$foo.defined, 'variable $foo is now undefined again');
86
87 $foo = "b";
88 ok($foo.defined, 'variable $foo is now defined (as string "b")');
89
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
90 $foo = 0;
91 ok($foo.defined, 'variable $foo is now defined (as numeric literal 0)');
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
92
252783d @colomon Fudge for niecza.
colomon authored
93 {
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
94 undefine($foo);
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
95 ok(!$foo.defined, 'undefine $foo works');
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
96 }
252783d @colomon Fudge for niecza.
colomon authored
97 }
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
98
920cbea [defined.t] Added tests for RT #81352.
Kodi Arfer authored
99 # RT #81352
100 # Ensure that we always get Bools
101 {
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
102 isa-ok defined(Mu), Bool, 'defined(Mu) returns a Bool';
103 isa-ok Mu.defined, Bool, 'Mu.defined returns a Bool';
104 isa-ok defined(Int), Bool, 'defined(Int) returns a Bool';
105 isa-ok Int.defined, Bool, 'Int.defined returns a Bool';
106 isa-ok defined(1), Bool, 'defined(1) returns a Bool';
107 isa-ok 1.defined, Bool, '1.defined returns a Bool';
108 isa-ok defined("a"), Bool, 'defined("a") returns a Bool';
109 isa-ok "a".defined, Bool, '"a".defined returns a Bool';
110 isa-ok defined(()), Bool, 'defined(()) returns a Bool';
111 isa-ok ().defined, Bool, '().defined returns a Bool';
112 isa-ok defined({}), Bool, 'defined({}) returns a Bool';
113 isa-ok {}.defined, Bool, '{}.defined returns a Bool';
920cbea [defined.t] Added tests for RT #81352.
Kodi Arfer authored
114
115 my $bar;
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
116 isa-ok defined($bar), Bool, 'defined($bar) with $bar unset returns a Bool';
117 isa-ok $bar.defined, Bool, '$bar.defined with $bar unset returns a Bool';
920cbea [defined.t] Added tests for RT #81352.
Kodi Arfer authored
118 $bar = "";
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
119 isa-ok defined($bar), Bool, 'defined($bar) with $bar eq "" returns a Bool';
120 isa-ok $bar.defined, Bool, '$bar.defined with $bar eq "" returns a Bool';
920cbea [defined.t] Added tests for RT #81352.
Kodi Arfer authored
121 $bar = 7;
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
122 isa-ok defined($bar), Bool, 'defined($bar) with $bar == 7 returns a Bool';
123 isa-ok $bar.defined, Bool, '$bar.defined with $bar == 7 returns a Bool';
920cbea [defined.t] Added tests for RT #81352.
Kodi Arfer authored
124 $bar = Mu;
bb0a8fa @lizmat Use isa-ok instead of isa_ok
lizmat authored
125 isa-ok defined($bar), Bool, 'defined($bar) with $bar set to Mu returns a Bool';
126 isa-ok $bar.defined, Bool, '$bar.defined with $bar set to Mu returns a Bool';
920cbea [defined.t] Added tests for RT #81352.
Kodi Arfer authored
127 }
128
2b44ad1 Refactored 'defined' builtin tests, moved under t/spec/S29-scalar
cosimo authored
129 # While porting a Perl 5 solution to QoTW regular #24, I noticed the following bug:
130 # my %a = (a => 1);
131 # defined %a{"b"}; # true!
132 my %a = (a => 1);
133 ok defined(%a{"a"}), "defined on a hash with parens (1)";
134 ok !defined(%a{"b"}), "defined on a hash with parens (2)";
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
135
eff0660 @moritz test that defined() is a listop, RT #76448
moritz authored
136 # RT #76448
137 ok defined('a' => 5) ~~ Bool, 'defined is a listop, not a prefix op';
138 ok &defined, '&defined is available';
139
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
140 # vim: ft=perl6
Something went wrong with that request. Please try again.