Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (33 sloc) 1.508 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
use v6;
use Test;

plan 24;

# N.B.: relational ops are in relational.t

#L<S03/Comparison semantics>

# spaceship comparisons (Num)
is(1 <=> 1, Order::Same, '1 <=> 1 is same');
is(1 <=> 2, Order::Less, '1 <=> 2 is increase');
is(2 <=> 1, Order::More, '2 <=> 1 is decrease');

is 0 <=> -1, Order::More, '0 <=> -1 is increase';
is -1 <=> 0, Order::Less, '-1 <=> 0 is decrease';
is 0 <=> -1/2, Order::More, '0 <=> -1/2 is increase';
is 0 <=> 1/2, Order::Less, '0 <=> 1/2 is increase';
is -1/2 <=> 0, Order::Less, '-1/2 <=> 0 is decrease';
is 1/2 <=> 0, Order::More, '1/2 <=> 0 is decrease';
is 1/2 <=> 1/2, Order::Same, '1/2 <=> 1/2 is same';
is -1/2 <=> -1/2, Order::Same, '-1/2 <=> -1/2 is same';
is 1/2 <=> -1/2, Order::More, '1/2 <=> -1/2 is decrease';
is -1/2 <=> 1/2, Order::Less, '-1/2 <=> 1/2 is increase';

# leg comparison (Str)
is('a' leg 'a', Order::Same, 'a leg a is same');
is('a' leg 'b', Order::Less, 'a leg b is increase');
is('b' leg 'a', Order::More, 'b leg a is decrease');
is('a' leg 1, Order::More, 'leg is in string context');

# cmp comparison
is('a' cmp 'a', Order::Same, 'a cmp a is same');
is('a' cmp 'b', Order::Less, 'a cmp b is increase');
is('b' cmp 'a', Order::More, 'b cmp a is decrease');
is(1 cmp 1, Order::Same, '1 cmp 1 is same');
is(1 cmp 2, Order::Less, '1 cmp 2 is increase');
is(2 cmp 1, Order::More, '2 cmp 1 is decrease');
is('a' cmp 1, Order::More, '"a" cmp 1 is decrease'); # unspecced but P5 behavior

# vim: ft=perl6
Something went wrong with that request. Please try again.