Permalink
Browse files

[spec] moved all tests from t/statemens/modifiers into t/spec/S04-sta…

…tement-modifiers/

git-svn-id: http://svn.pugscode.org/pugs@22067 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 3a0641a commit fde97fbc8b22e9d96e62ef33cc98cb340d93a084 dr_df0 committed Aug 29, 2008
@@ -0,0 +1,27 @@
+use v6;
+
+use Test;
+
+plan 4;
+
+# L<S04/"Conditional statements"/Conditional statement modifiers work as in Perl 5>
+
+# test the ``given'' statement modifier
+{
+ my $a = $_ given 2 * 3;
+ is($a, 6, "post given");
+}
+
+{
+ my $a = $_ given 'a';
+ is($a, 'a', "post given");
+}
+
+# L<S04/The C<for> statement/"given" "use a private instance of" $_>
+{
+ my $i;
+ $_ = 10;
+ $i += $_ given $_+3;
+ is $_, 10, 'outer $_ did not get updated in lhs of given';
+ is $i, 13, 'postfix given worked';
+}
@@ -0,0 +1,20 @@
+use v6;
+
+use Test;
+
+plan 2;
+
+# L<S04/"Conditional statements"/Conditional statement modifiers work as in Perl 5>
+
+# test the if statement modifier
+{
+ my $a = 1;
+ $a = 2 if 'a' eq 'a';
+ is($a, 2, "post if");
+}
+
+{
+ my $a = 1;
+ $a = 3 if 'a' eq 'b';
+ is($a, 1, "post if");
+}
@@ -0,0 +1,25 @@
+use v6;
+
+use Test;
+
+plan 4;
+
+# L<S04/"Conditional statements"/that the first expression within parens or brackets is parsed as a statement>
+
+{
+ my $answer = 1;
+ my @x = 41, eval q[(42 if $answer)], 43;
+ my @y = 41, ($answer ?? 42 !! ()), 43;
+ my @z = 41, 42, 43;
+ is @y, @z, "sanity check";
+ is @x, @y, "if expr on true cond", :todo<feature>;
+}
+
+{
+ my $answer = 0;
+ my @x = 41, eval q[(42 if $answer)], 43;
+ my @y = 41, ($answer ?? 42 !! ()), 43;
+ my @z = 41, 43;
+ is @y, @z, "sanity check";
+ is @x, @y, "if expr on false cond", :todo<feature>;
+}
@@ -0,0 +1,16 @@
+use v6;
+
+use Test;
+plan 1;
+
+sub foo() {
+ return if 1;
+ 123;
+}
+
+my $ok = 1;
+for foo() -> @foo {
+ $ok = 0;
+}
+
+ok $ok, "condition in statement level respects context" :todo<bug>;
@@ -0,0 +1,20 @@
+use v6;
+
+use Test;
+
+plan 2;
+
+# test the unless statement modifier
+
+# L<S04/"Conditional statements"/Conditional statement modifiers work as in Perl 5>
+{
+ my $a = 1;
+ $a = 4 unless 'a' eq 'a';
+ is($a, 1, "post unless");
+}
+
+{
+ my $a = 1;
+ $a = 5 unless 'a' eq 'b';
+ is($a, 5, "post unless");
+}
@@ -0,0 +1,28 @@
+use v6;
+
+use Test;
+
+plan 3;
+
+# L<S04/"Conditional statements"/Conditional statement modifiers work as in Perl 5>
+
+# test the ``until'' statement modifier
+{
+ my ($a, $b);
+ $a += $b += 1 until $b >= 10;
+ is($a, 55, "post until");
+}
+
+{
+ my @a = ('a', 'b', 'a');
+ my $a = 'b';
+ $a ~= ', ' ~ shift @a until !+@a;
+ is($a, "b, a, b, a", "post until");
+}
+
+{
+ my @a = 'a'..'e';
+ my $a;
+ $a ++ until shift(@a) eq 'c';
+ is($a, 2, "post until");
+}

0 comments on commit fde97fb

Please sign in to comment.