This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "Update Unicode-Collate to CPAN version 0.70 and enable XS version"
[perl5.git] / dist / Thread-Queue / t / 03_peek.t
1 use strict;
2 use warnings;
3
4 BEGIN {
5     use Config;
6     if (! $Config{'useithreads'}) {
7         print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
8         exit(0);
9     }
10 }
11
12 use threads;
13 use Thread::Queue;
14
15 if ($] == 5.008) {
16     require 't/test.pl';   # Test::More work-alike for Perl 5.8.0
17 } else {
18     require Test::More;
19 }
20 Test::More->import();
21 plan('tests' => 19);
22
23 my $q = Thread::Queue->new(1..10);
24 ok($q, 'New queue');
25
26 $q->enqueue([ qw/foo bar/ ]);
27
28 sub q_check
29 {
30     is($q->peek(3), 4, 'Peek at queue');
31     is($q->peek(-3), 9, 'Negative peek');
32
33     my $nada = $q->peek(20);
34     ok(! defined($nada), 'Big peek');
35     $nada = $q->peek(-20);
36     ok(! defined($nada), 'Big negative peek');
37
38     my $ary = $q->peek(-1);
39     is_deeply($ary, [ qw/foo bar/ ], 'Peek array');
40
41     is($q->pending(), 11, 'Queue count in thread');
42 }
43
44 threads->create(sub {
45     q_check();
46     threads->create('q_check')->join();
47 })->join();
48 q_check();
49
50 exit(0);
51
52 # EOF