File: 08-filehandle.t

package info (click to toggle)
libgraphics-colornames-perl 3.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 276 kB
  • sloc: perl: 1,458; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 1,640 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl

use strict;
use Test::More tests => 28;

use FileHandle;
use IO::File;

use_ok( 'Graphics::ColorNames', 1.10, qw( hex2tuple tuple2hex ) );

{
    my $fh = new IO::File;
    open( $fh, './t-etc/rgb.txt' );

    tie my %colors, 'Graphics::ColorNames', $fh;
    ok( tied %colors );

    ok( keys %colors == 6 );    #

    my $count = 0;
    foreach my $name ( keys %colors ) {
        my @RGB = hex2tuple( $colors{$name} );
        $count++, if ( tuple2hex(@RGB) eq $colors{$name} );
    }
    ok( $count == keys %colors );

    foreach my $name (qw( one two three four five six)) {
        ok( exists $colors{$name} );
    }

    close $fh;
}

{
    my $fh = new FileHandle;
    open( $fh, './t-etc/rgb.txt' );

    tie my %colors, 'Graphics::ColorNames', $fh;
    ok( tied %colors );

    ok( keys %colors == 6 );    #

    my $count = 0;
    foreach my $name ( keys %colors ) {
        my @RGB = hex2tuple( $colors{$name} );
        $count++, if ( tuple2hex(@RGB) eq $colors{$name} );
    }
    ok( $count == keys %colors );

    foreach my $name (qw( one two three four five six)) {
        ok( exists $colors{$name} );
    }

    close $fh;
}

{
    open( my $fh, './t-etc/rgb.txt' );

    tie my %colors, 'Graphics::ColorNames', $fh;
    ok( tied %colors );

    ok( keys %colors == 6 );    #

    my $count = 0;
    foreach my $name ( keys %colors ) {
        my @RGB = hex2tuple( $colors{$name} );
        $count++, if ( tuple2hex(@RGB) eq $colors{$name} );
    }
    ok( $count == keys %colors );

    foreach my $name (qw( one two three four five six)) {
        ok( exists $colors{$name} );
    }

    close $fh;
}