summaryrefslogtreecommitdiff
path: root/lib/Switch
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-05-17 03:08:01 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-05-17 03:08:01 +0000
commit6596d39b554785758f393f2dda70b41e7e3c4251 (patch)
tree92e90c570dced788935a8de378cbab9cb9c246cf /lib/Switch
parentd575d9c7132bef67d0532d002ca10ee80b07917a (diff)
downloadperl-6596d39b554785758f393f2dda70b41e7e3c4251.tar.gz
Upgrade to Switch 2.07.
p4raw-id: //depot/perl@16643
Diffstat (limited to 'lib/Switch')
-rwxr-xr-xlib/Switch/Changes9
-rw-r--r--lib/Switch/README14
-rwxr-xr-xlib/Switch/t/given.t216
-rwxr-xr-xlib/Switch/t/nested.t8
-rwxr-xr-xlib/Switch/t/switch.t8
5 files changed, 131 insertions, 124 deletions
diff --git a/lib/Switch/Changes b/lib/Switch/Changes
index add21302bf..c872bdd80f 100755
--- a/lib/Switch/Changes
+++ b/lib/Switch/Changes
@@ -59,3 +59,12 @@ Revision history for Perl extension Switch.
- Fixed the parsing of embedded POD (thanks Brent)
- Fixed bug encountered when -s or -m file test used (thanks Jochen)
+
+
+2.07 Wed May 15 15:19:28 2002
+
+ - Corified tests
+
+ - Updated "Perl6" syntax to reflect current design
+ (as far as possible -- can't eliminate need to parenthesize
+ variables, since they're ambiguous in Perl 5)
diff --git a/lib/Switch/README b/lib/Switch/README
index f2cf139d1b..5a517403a5 100644
--- a/lib/Switch/README
+++ b/lib/Switch/README
@@ -1,5 +1,5 @@
==============================================================================
- Release of version 2.06 of Switch
+ Release of version 2.07 of Switch
==============================================================================
@@ -26,16 +26,14 @@ COPYRIGHT
==============================================================================
-CHANGES IN VERSION 2.06
+CHANGES IN VERSION 2.07
- - Fixed parsing of ternary operators in Switch'ed source code
- (at the expense of no longer correctly parsing ?...? regexes)
- (thanks Mark)
+ - Corified tests
- - Fixed the parsing of embedded POD (thanks Brent)
-
- - Fixed bug encountered when -s or -m file test used (thanks Jochen)
+ - Updated "Perl6" syntax to reflect current design
+ (as far as possible -- can't eliminate need to parenthesize
+ variables, since they're ambiguous in Perl 5)
==============================================================================
diff --git a/lib/Switch/t/given.t b/lib/Switch/t/given.t
index d47541a9cb..c396c35856 100755
--- a/lib/Switch/t/given.t
+++ b/lib/Switch/t/given.t
@@ -1,8 +1,8 @@
-#! /usr/local/bin/perl -w
-
BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
+ if ($ENV{PERL_CORE}) {
+ chdir('t') if -d 't';
+ @INC = qw(../lib);
+ }
}
use Carp;
@@ -19,22 +19,22 @@ $when->{when} = { when => "when" };
# PREMATURE when
-eval { when 1: { ok(0) }; ok(0) } || ok(1);
+eval { when 1 { ok(0) }; ok(0) } || ok(1);
# H.O. FUNCS
-given (__ > 2) {
+given __ > 2 {
- when 1: { ok(0) } else { ok(1) }
- when 2: { ok(0) } else { ok(1) }
- when 3: { ok(1) } else { ok(0) }
+ when 1 { ok(0) } else { ok(1) }
+ when 2 { ok(0) } else { ok(1) }
+ when 3 { ok(1) } else { ok(0) }
}
given (3) {
- eval { when __ <= 1 || __ > 2: { ok(0) } } || ok(1);
- when __ <= 2: { ok(0) };
- when __ <= 3: { ok(1) };
+ eval { when __ <= 1 || __ > 2 { ok(0) } } || ok(1);
+ when __ <= 2 { ok(0) };
+ when __ <= 3 { ok(1) };
}
# POSSIBLE ARGS: NUMERIC, STRING, ARRAY, HASH, REGEX, CODE
@@ -45,40 +45,40 @@ for (1..3)
{
given ($_) {
# SELF
- when $_: { ok(1) } else { ok(0) }
+ when ($_) { ok(1) } else { ok(0) }
# NUMERIC
- when 1: { ok ($_==1) } else { ok($_!=1) }
- when (1): { ok ($_==1) } else { ok($_!=1) }
- when 3: { ok ($_==3) } else { ok($_!=3) }
- when (4): { ok (0) } else { ok(1) }
- when (2): { ok ($_==2) } else { ok($_!=2) }
+ when 1 { ok ($_==1) } else { ok($_!=1) }
+ when (1) { ok ($_==1) } else { ok($_!=1) }
+ when 3 { ok ($_==3) } else { ok($_!=3) }
+ when (4) { ok (0) } else { ok(1) }
+ when (2) { ok ($_==2) } else { ok($_!=2) }
# STRING
- when ('a'): { ok (0) } else { ok(1) }
- when 'a' : { ok (0) } else { ok(1) }
- when ('3'): { ok ($_ == 3) } else { ok($_ != 3) }
- when ('3.0'): { ok (0) } else { ok(1) }
+ when ('a') { ok (0) } else { ok(1) }
+ when 'a' { ok (0) } else { ok(1) }
+ when ('3') { ok ($_ == 3) } else { ok($_ != 3) }
+ when ('3.0') { ok (0) } else { ok(1) }
# ARRAY
- when ([10,5,1]): { ok ($_==1) } else { ok($_!=1) }
- when [10,5,1]: { ok ($_==1) } else { ok($_!=1) }
- when (['a','b']): { ok (0) } else { ok(1) }
- when (['a','b',3]): { ok ($_==3) } else { ok ($_!=3) }
- when (['a','b',2.0]) : { ok ($_==2) } else { ok ($_!=2) }
- when ([]) : { ok (0) } else { ok(1) }
+ when ([10,5,1]) { ok ($_==1) } else { ok($_!=1) }
+ when [10,5,1] { ok ($_==1) } else { ok($_!=1) }
+ when (['a','b']) { ok (0) } else { ok(1) }
+ when (['a','b',3]) { ok ($_==3) } else { ok ($_!=3) }
+ when (['a','b',2.0]) { ok ($_==2) } else { ok ($_!=2) }
+ when ([]) { ok (0) } else { ok(1) }
# HASH
- when ({}) : { ok (0) } else { ok (1) }
- when {} : { ok (0) } else { ok (1) }
- when {1,1} : { ok ($_==1) } else { ok($_!=1) }
- when ({1=>1, 2=>0}) : { ok ($_==1) } else { ok($_!=1) }
+ when ({}) { ok (0) } else { ok (1) }
+ when {} { ok (0) } else { ok (1) }
+ when {1,1} { ok ($_==1) } else { ok($_!=1) }
+ when ({1=>1, 2=>0}) { ok ($_==1) } else { ok($_!=1) }
# SUB/BLOCK
- when (sub {$_[0]==2}) : { ok ($_==2) } else { ok($_!=2) }
- when {$_[0]==2} : { ok ($_==2) } else { ok($_!=2) }
- when {0} : { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
- when {1} : { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
+ when (sub {$_[0]==2}) { ok ($_==2) } else { ok($_!=2) }
+ when {$_[0]==2} { ok ($_==2) } else { ok($_!=2) }
+ when {0} { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
+ when {1} { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
}
}
@@ -89,36 +89,36 @@ for ('a'..'c','1')
{
given ($_) {
# SELF
- when ($_) : { ok(1) } else { ok(0) }
+ when ($_) { ok(1) } else { ok(0) }
# NUMERIC
- when (1) : { ok ($_ !~ /[a-c]/) } else { ok ($_ =~ /[a-c]/) }
- when (1.0) : { ok ($_ !~ /[a-c]/) } else { ok ($_ =~ /[a-c]/) }
+ when (1) { ok ($_ !~ /[a-c]/) } else { ok ($_ =~ /[a-c]/) }
+ when (1.0) { ok ($_ !~ /[a-c]/) } else { ok ($_ =~ /[a-c]/) }
# STRING
- when ('a') : { ok ($_ eq 'a') } else { ok($_ ne 'a') }
- when ('b') : { ok ($_ eq 'b') } else { ok($_ ne 'b') }
- when ('c') : { ok ($_ eq 'c') } else { ok($_ ne 'c') }
- when ('1') : { ok ($_ eq '1') } else { ok($_ ne '1') }
- when ('d') : { ok (0) } else { ok (1) }
+ when ('a') { ok ($_ eq 'a') } else { ok($_ ne 'a') }
+ when ('b') { ok ($_ eq 'b') } else { ok($_ ne 'b') }
+ when ('c') { ok ($_ eq 'c') } else { ok($_ ne 'c') }
+ when ('1') { ok ($_ eq '1') } else { ok($_ ne '1') }
+ when ('d') { ok (0) } else { ok (1) }
# ARRAY
- when (['a','1']) : { ok ($_ eq 'a' || $_ eq '1') }
+ when (['a','1']) { ok ($_ eq 'a' || $_ eq '1') }
else { ok ($_ ne 'a' && $_ ne '1') }
- when (['z','2']) : { ok (0) } else { ok(1) }
- when ([]) : { ok (0) } else { ok(1) }
+ when (['z','2']) { ok (0) } else { ok(1) }
+ when ([]) { ok (0) } else { ok(1) }
# HASH
- when ({}) : { ok (0) } else { ok (1) }
- when ({a=>'a', 1=>1, 2=>0}) : { ok ($_ eq 'a' || $_ eq '1') }
+ when ({}) { ok (0) } else { ok (1) }
+ when ({a=>'a', 1=>1, 2=>0}) { ok ($_ eq 'a' || $_ eq '1') }
else { ok ($_ ne 'a' && $_ ne '1') }
# SUB/BLOCK
- when (sub{$_[0] eq 'a' }) : { ok ($_ eq 'a') }
+ when (sub{$_[0] eq 'a' }) { ok ($_ eq 'a') }
else { ok($_ ne 'a') }
- when {$_[0] eq 'a'} : { ok ($_ eq 'a') } else { ok($_ ne 'a') }
- when {0} : { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
- when {1} : { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
+ when {$_[0] eq 'a'} { ok ($_ eq 'a') } else { ok($_ ne 'a') }
+ when {0} { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
+ when {1} { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
}
}
@@ -131,35 +131,35 @@ for ([],[1,'a'],[2,'b'])
given ($_) {
$iteration++;
# SELF
- when ($_) : { ok(1) }
+ when ($_) { ok(1) }
# NUMERIC
- when (1) : { ok ($iteration==2) } else { ok ($iteration!=2) }
- when (1.0) : { ok ($iteration==2) } else { ok ($iteration!=2) }
+ when (1) { ok ($iteration==2) } else { ok ($iteration!=2) }
+ when (1.0) { ok ($iteration==2) } else { ok ($iteration!=2) }
# STRING
- when ('a') : { ok ($iteration==2) } else { ok ($iteration!=2) }
- when ('b') : { ok ($iteration==3) } else { ok ($iteration!=3) }
- when ('1') : { ok ($iteration==2) } else { ok ($iteration!=2) }
+ when ('a') { ok ($iteration==2) } else { ok ($iteration!=2) }
+ when ('b') { ok ($iteration==3) } else { ok ($iteration!=3) }
+ when ('1') { ok ($iteration==2) } else { ok ($iteration!=2) }
# ARRAY
- when (['a',2]) : { ok ($iteration>=2) } else { ok ($iteration<2) }
- when ([1,'a']) : { ok ($iteration==2) } else { ok($iteration!=2) }
- when ([]) : { ok (0) } else { ok(1) }
- when ([7..100]) : { ok (0) } else { ok(1) }
+ when (['a',2]) { ok ($iteration>=2) } else { ok ($iteration<2) }
+ when ([1,'a']) { ok ($iteration==2) } else { ok($iteration!=2) }
+ when ([]) { ok (0) } else { ok(1) }
+ when ([7..100]) { ok (0) } else { ok(1) }
# HASH
- when ({}) : { ok (0) } else { ok (1) }
- when ({a=>'a', 1=>1, 2=>0}) : { ok ($iteration==2) }
+ when ({}) { ok (0) } else { ok (1) }
+ when ({a=>'a', 1=>1, 2=>0}) { ok ($iteration==2) }
else { ok ($iteration!=2) }
# SUB/BLOCK
- when {scalar grep /a/, @_} : { ok ($iteration==2) }
+ when {scalar grep /a/, @_} { ok ($iteration==2) }
else { ok ($iteration!=2) }
- when (sub {scalar grep /a/, @_ }) : { ok ($iteration==2) }
+ when (sub {scalar grep /a/, @_ }) { ok ($iteration==2) }
else { ok ($iteration!=2) }
- when {0} : { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
- when {1} : { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
+ when {0} { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
+ when {1} { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
}
}
@@ -173,37 +173,37 @@ for ({},{a=>1,b=>0})
$iteration++;
# SELF
- when ($_) : { ok(1) } else { ok(0) }
+ when ($_) { ok(1) } else { ok(0) }
# NUMERIC
- when (1) : { ok (0) } else { ok (1) }
- when (1.0) : { ok (0) } else { ok (1) }
+ when (1) { ok (0) } else { ok (1) }
+ when (1.0) { ok (0) } else { ok (1) }
# STRING
- when ('a') : { ok ($iteration==2) } else { ok ($iteration!=2) }
- when ('b') : { ok (0) } else { ok (1) }
- when ('c') : { ok (0) } else { ok (1) }
+ when ('a') { ok ($iteration==2) } else { ok ($iteration!=2) }
+ when ('b') { ok (0) } else { ok (1) }
+ when ('c') { ok (0) } else { ok (1) }
# ARRAY
- when (['a',2]) : { ok ($iteration==2) }
+ when (['a',2]) { ok ($iteration==2) }
else { ok ($iteration!=2) }
- when (['b','a']) : { ok ($iteration==2) }
+ when (['b','a']) { ok ($iteration==2) }
else { ok ($iteration!=2) }
- when (['b','c']) : { ok (0) } else { ok (1) }
- when ([]) : { ok (0) } else { ok(1) }
- when ([7..100]) : { ok (0) } else { ok(1) }
+ when (['b','c']) { ok (0) } else { ok (1) }
+ when ([]) { ok (0) } else { ok(1) }
+ when ([7..100]) { ok (0) } else { ok(1) }
# HASH
- when ({}) : { ok (0) } else { ok (1) }
- when ({a=>'a', 1=>1, 2=>0}) : { ok (0) } else { ok (1) }
+ when ({}) { ok (0) } else { ok (1) }
+ when ({a=>'a', 1=>1, 2=>0}) { ok (0) } else { ok (1) }
# SUB/BLOCK
- when {$_[0]{a}} : { ok ($iteration==2) }
+ when {$_[0]{a}} { ok ($iteration==2) }
else { ok ($iteration!=2) }
- when (sub {$_[0]{a}}) : { ok ($iteration==2) }
+ when (sub {$_[0]{a}}) { ok ($iteration==2) }
else { ok ($iteration!=2) }
- when {0} : { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
- when {1} : { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
+ when {0} { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
+ when {1} { ok (1) } else { ok (0) } # ; -> SUB, NOT HASH
}
}
@@ -224,40 +224,40 @@ for ( sub {1},
given ($_) {
$iteration++;
# SELF
- when ($_) : { ok(1) } else { ok(0) }
+ when ($_) { ok(1) } else { ok(0) }
# NUMERIC
- when (1) : { ok ($iteration<=2) } else { ok ($iteration>2) }
- when (1.0) : { ok ($iteration<=2) } else { ok ($iteration>2) }
- when (1.1) : { ok ($iteration==1) } else { ok ($iteration!=1) }
+ when (1) { ok ($iteration<=2) } else { ok ($iteration>2) }
+ when (1.0) { ok ($iteration<=2) } else { ok ($iteration>2) }
+ when (1.1) { ok ($iteration==1) } else { ok ($iteration!=1) }
# STRING
- when ('a') : { ok ($iteration==1) } else { ok ($iteration!=1) }
- when ('b') : { ok ($iteration==1) } else { ok ($iteration!=1) }
- when ('c') : { ok ($iteration==1) } else { ok ($iteration!=1) }
- when ('1') : { ok ($iteration<=2) } else { ok ($iteration>2) }
+ when ('a') { ok ($iteration==1) } else { ok ($iteration!=1) }
+ when ('b') { ok ($iteration==1) } else { ok ($iteration!=1) }
+ when ('c') { ok ($iteration==1) } else { ok ($iteration!=1) }
+ when ('1') { ok ($iteration<=2) } else { ok ($iteration>2) }
# ARRAY
- when ([1, 'a']) : { ok ($iteration<=2) }
+ when ([1, 'a']) { ok ($iteration<=2) }
else { ok ($iteration>2) }
- when (['b','a']) : { ok ($iteration==1) }
+ when (['b','a']) { ok ($iteration==1) }
else { ok ($iteration!=1) }
- when (['b','c']) : { ok ($iteration==1) }
+ when (['b','c']) { ok ($iteration==1) }
else { ok ($iteration!=1) }
- when ([]) : { ok ($iteration==1) } else { ok($iteration!=1) }
- when ([7..100]) : { ok ($iteration==1) }
+ when ([]) { ok ($iteration==1) } else { ok($iteration!=1) }
+ when ([7..100]) { ok ($iteration==1) }
else { ok($iteration!=1) }
# HASH
- when ({}) : { ok ($iteration==1) } else { ok ($iteration!=1) }
- when ({a=>'a', 1=>1, 2=>0}) : { ok ($iteration<=2) }
+ when ({}) { ok ($iteration==1) } else { ok ($iteration!=1) }
+ when ({a=>'a', 1=>1, 2=>0}) { ok ($iteration<=2) }
else { ok ($iteration>2) }
# SUB/BLOCK
- when {$_[0]->{a}} : { ok (0) } else { ok (1) }
- when (sub {$_[0]{a}}) : { ok (0) } else { ok (1) }
- when {0} : { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
- when {1} : { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
+ when {$_[0]->{a}} { ok (0) } else { ok (1) }
+ when (sub {$_[0]{a}}) { ok (0) } else { ok (1) }
+ when {0} { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
+ when {1} { ok (0) } else { ok (1) } # ; -> SUB, NOT HASH
}
}
@@ -267,11 +267,11 @@ for ( sub {1},
for my $count (1..3)
{
given ([9,"a",11]) {
- when (qr/\d/) : {
+ when (qr/\d/) {
given ($count) {
- when (1) : { ok($count==1) }
+ when (1) { ok($count==1) }
else { ok($count!=1) }
- when ([5,6]) : { ok(0) } else { ok(1) }
+ when ([5,6]) { ok(0) } else { ok(1) }
}
}
ok(1) when 11;
diff --git a/lib/Switch/t/nested.t b/lib/Switch/t/nested.t
index 87451eda00..e7e520ae2e 100755
--- a/lib/Switch/t/nested.t
+++ b/lib/Switch/t/nested.t
@@ -1,8 +1,8 @@
-#! /usr/local/bin/perl -w
-
BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
+ if ($ENV{PERL_CORE}) {
+ chdir('t') if -d 't';
+ @INC = qw(../lib);
+ }
}
use Switch;
diff --git a/lib/Switch/t/switch.t b/lib/Switch/t/switch.t
index 5f5451d34e..ad0f958802 100755
--- a/lib/Switch/t/switch.t
+++ b/lib/Switch/t/switch.t
@@ -1,8 +1,8 @@
-#! /usr/local/bin/perl -w
-
BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
+ if ($ENV{PERL_CORE}) {
+ chdir('t') if -d 't';
+ @INC = qw(../lib);
+ }
}
use Carp;