Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[gsoc_spectest] reorganization and a few more tests for ===, eqv, and…

… ranges. (7 tests added)

git-svn-id: http://svn.pugscode.org/pugs@21114 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit 9a5861722c004ab526882767719348fdbf47e25c 1 parent e90d4b6
Auzon authored
92 S03-operators/range.t
... ... @@ -0,0 +1,92 @@
  1 +use v6;
  2 +
  3 +use Test;
  4 +
  5 +plan 51;
  6 +
  7 +# 3..2 must *not* produce "3 2". Use reverse to get a reversed range. -lwall
  8 +
  9 +is ~(3..6), "3 4 5 6", "(..) works on numbers (1)";
  10 +is ~(3..3), "3", "(..) works on numbers (2)";
  11 +is ~(3..2), "", "(..) works on numbers (3)";
  12 +is ~(8..11), "8 9 10 11", "(..) works on carried numbers (3)";
  13 +
  14 +is ~("a".."c"), "a b c", "(..) works on chars (1)";
  15 +is ~("a".."a"), "a", "(..) works on chars (2)";
  16 +is ~("b".."a"), "", "(..) works on chars (3)";
  17 +is ~("Y".."AB"), "Y Z AA AB", "(..) works on carried chars (3)";
  18 +
  19 +is ~('Y'..'z', 'Y Z', '(..) works on uppercase letter .. lowercase letter');
  20 +is ~('Y'..'_', 'Y Z', '(..) works on letter .. non-letter');
  21 +
  22 +isnt ~(0..^10), ~(0.. ^10), '(0..^10) is not the same as (0.. ^10)');
  23 +
  24 +is ~(3..9-3), "3 4 5 6", "(..) has correct precedence (1)";
  25 +is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (2)";
  26 +
  27 +# Test the three exclusive range operators:
  28 +# L<S03/Range semantics/range operator has variants>
  29 +is [1^..9], [2..9], "bottom-exclusive range (^..) works";
  30 +is [1 ..^9], [1..8], "top-exclusive range (..^) works";
  31 +is [1^..^9], [2..8], "double-exclusive range (^..^) works";
  32 +is [1^..^2], [], "double-exclusive range (^..^) can produce null range";
  33 +
  34 +# tests of (x ^..^ x) here and below ensure that our implementation
  35 +# of double-exclusive range does not blindly remove an element
  36 +# from the head and tail of a list
  37 +is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
  38 +
  39 +is ["a"^.."z"], ["b".."z"], "bottom-exclusive string range (^..) works";
  40 +is ["a"..^"z"], ["a".."y"], "top-exclusive string range (..^) works";
  41 +is ["a"^..^"z"], ["b".."y"], "double-exclusive string range (^..^) works";
  42 +is ['a'^..^'b'], [], "double-exclusive string range (^..^) can produce null range";
  43 +is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
  44 +
  45 +is 1.5 ~~ 1^..^2, Bool::True, "lazy evaluation of the range operator", :todo<bug>;
  46 +
  47 +# Test the unary ^ operator
  48 +is ~(^5), "0 1 2 3 4", "unary ^num produces the range 0..^num";
  49 +is [^1], [0], "unary ^ on the boundary ^1 works";
  50 +is [^0], [], "unary ^0 produces null range";
  51 +
  52 +# Test with floats
  53 +# 2006-12-05:
  54 +# 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
  55 +# 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
  56 +# 16:17 <TimToady> yes
  57 +is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
  58 +is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
  59 +is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
  60 +is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
  61 +
  62 +is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
  63 +is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
  64 +is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
  65 +is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
  66 +
  67 +is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
  68 +is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
  69 +is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
  70 +is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
  71 +
  72 +is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
  73 +is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
  74 +is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
  75 +is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
  76 +is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
  77 +
  78 +# Test that the operands are forced to scalar context
  79 +{
  80 + my @one = (1,);
  81 + my @three = (1, 1, 1);
  82 +
  83 + is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
  84 + is ~(@one ^.. 3) , "2 3" , "lower exclusive limit is in scalar context";
  85 + is ~(1 .. @three) , "1 2 3", "upper inclusive limit is in scalar context";
  86 + is ~(1 ..^ @three) , "1 2" , "upper exclusive limit is in scalar context";
  87 + is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
  88 + is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
  89 + is ~(@three .. @one), "" , "null range produced with lists forced to scalar context";
  90 +}
  91 +
  92 +# For tests involving :by, see t/operators/adverbial_modifiers.t
146 S03-operators/value_equivalence.t
... ... @@ -0,0 +1,146 @@
  1 +use v6;
  2 +
  3 +use Test;
  4 +
  5 +=begin pod
  6 +
  7 +L<S03/"Chaining binary precedence" /Value identity>
  8 +
  9 +C<===> and C<eqv> are 2 distinct operators, where C<===> tests value
  10 +equivalence for immutable types and reference equivalence for
  11 +mutable types, and C<eqv> tests value equivalence for snapshots of mutable
  12 +types. So C<(1,2) === (1,2)> returns true but C<[1,2] === [1,2]> returns
  13 +false, and C<[1,2] eqv [1,2]> returns true.
  14 +
  15 +=end pod
  16 +
  17 +plan 51;
  18 +
  19 +# === on values
  20 +{
  21 + ok (1 === 1), "=== on values (1)";
  22 + ok (0 === 0), "=== on values (2)";
  23 + ok !(0 === 1), "=== on values (3)";
  24 + ok ("abc" === "abc"), "=== on values(abc)";
  25 + ok !("abc" === "ABC"), "=== on values(abc === ABC)";
  26 + ok !(1 === 1.0), "=== on values (1 === 1.0)";
  27 + ok !(1 === "1"), '=== on values (1 === "1")';
  28 +}
  29 +
  30 +# Value types
  31 +{
  32 + my $a = 1;
  33 + my $b = 1;
  34 +
  35 + ok $a === $a, "=== on value types (1-1)";
  36 + ok $b === $b, "=== on value types (1-2)";
  37 + ok $a === $b, "=== on value types (1-3)";
  38 +}
  39 +
  40 +{
  41 + my $a = 1;
  42 + my $b = 2;
  43 +
  44 + ok ($a === $a), "=== on value types (2-1)";
  45 + ok ($b === $b), "=== on value types (2-2)";
  46 + ok !($a === $b), "=== on value types (2-3)";
  47 +}
  48 +
  49 +# Reference types
  50 +{
  51 + my @a = (1,2,3);
  52 + my @b = (1,2,3);
  53 +
  54 + ok (\@a === \@a), "=== on array references (1)";
  55 + ok (\@b === \@b), "=== on array references (2)";
  56 + ok !(\@a === \@b), "=== on array references (3)";
  57 +}
  58 +
  59 +{
  60 + my $a = \3;
  61 + my $b = \3;
  62 +
  63 + ok ($a === $a), "=== on scalar references (1-1)";
  64 + ok ($b === $b), "=== on scalar references (1-2)";
  65 + ok !($a === $b), "=== on scalar references (1-3)", :todo<bug>;
  66 +}
  67 +
  68 +{
  69 + my $a = { 3 };
  70 + my $b = { 3 };
  71 +
  72 + ok ($a === $a), "=== on sub references (1-1)";
  73 + ok ($b === $b), "=== on sub references (1-2)";
  74 + ok !($a === $b), "=== on sub references (1-3)";
  75 +}
  76 +
  77 +{
  78 + ok (&say === &say), "=== on sub references (2-1)";
  79 + ok (&map === &map), "=== on sub references (2-2)";
  80 + ok !(&say === &map), "=== on sub references (2-3)";
  81 +}
  82 +
  83 +{
  84 + my $num = 3;
  85 + my $a = \$num;
  86 + my $b = \$num;
  87 +
  88 + ok ($a === $a), "=== on scalar references (2-1)";
  89 + ok ($b === $b), "=== on scalar references (2-2)";
  90 + ok ($a === $b), "=== on scalar references (2-3)";
  91 +}
  92 +
  93 +{
  94 + ok !([1,2,3] === [4,5,6]), "=== on anonymous array references (1)";
  95 + ok !([1,2,3] === [1,2,3]), "=== on anonymous array references (2)";
  96 + ok !([] === []), "=== on anonymous array references (3)";
  97 +}
  98 +
  99 +{
  100 + ok !({a => 1} === {a => 2}), "=== on anonymous hash references (1)";
  101 + ok !({a => 1} === {a => 1}), "=== on anonymous hash references (2)";
  102 +}
  103 +
  104 +{
  105 + ok !(\3 === \4), "=== on anonymous scalar references (1)";
  106 + ok !(\3 === \3), "=== on anonymous scalar references (2)", :todo<bug>;
  107 + ok !(\undef === \undef), "=== on anonymous scalar references (3)", :todo<bug>;
  108 +}
  109 +
  110 +# Chained === (not specced, but obvious)
  111 +{
  112 + ok (3 === 3 === 3), "chained === (1)";
  113 + ok !(3 === 3 === 4), "chained === (2)";
  114 +}
  115 +
  116 +# Subparam binding doesn't affect === test
  117 +{
  118 + my $foo;
  119 + my $test = -> $arg { $foo === $arg };
  120 +
  121 + $foo = 3;
  122 + ok $test($foo), "subparam binding doesn't affect === (1)";
  123 + ok $test(3), "subparam binding doesn't affect === (2)";
  124 +
  125 + ok !$test(4), "subparam binding doesn't affect === (3)";
  126 + my $bar = 4;
  127 + ok !$test($bar), "subparam binding doesn't affect === (4)";
  128 +}
  129 +
  130 +{
  131 + my $a = 1;
  132 + my $b = 2;
  133 + is($a === $a, Bool::True, '=== returns Bool::True when true');
  134 + is($a === $b, Bool::False, '=== returns Bool::False when false');
  135 +}
  136 +
  137 +# L<S03/"Chaining binary precedence" /Negated relational operators>
  138 +{
  139 + ok !(1 !=== 1), "!=== on values (1)";
  140 + ok !(0 !=== 0), "!=== on values (2)";
  141 + ok (1 !=== 0), "!=== on values (3)";
  142 + ok !("abc" !=== "abc"), "!=== on values(abc)";
  143 + ok ("abc" !=== "ABC"), "!=== on values(abc !=== ABC)";
  144 + ok (1 !=== 1.0), "!=== on values (1 !=== 1.0)";
  145 + ok (1 !=== "1"), '!=== on values (1 !=== "1")';
  146 +}
7 S29-any/eqv.t
... ... @@ -1,8 +1,9 @@
1 1 use v6;
2 2 use Test;
3 3
4   -plan 38;
  4 +plan 40;
5 5
  6 +# L<S03/Comparison semantics/Binary eqv tests equality much like === does>
6 7 # L<S29/Any/"=item eqv">
7 8
8 9 # eqv on values
@@ -117,3 +118,7 @@ plan 38;
117 118 ok !$test($bar), "subparam binding doesn't affect eqv (4)";
118 119 }
119 120
  121 +{
  122 + is(1 eqv 1, Bool::True, 'eqv returns Bool::True when true');
  123 + is(0 eqv 1, Bool::False, 'eqv returns Bool::False when false');
  124 +}

0 comments on commit 9a58617

Please sign in to comment.
Something went wrong with that request. Please try again.