File: label.t

package info (click to toggle)
libchart-gnuplot-perl 0.23-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 944 kB
  • sloc: perl: 4,862; makefile: 113
file content (89 lines) | stat: -rwxr-xr-x 1,748 bytes parent folder | download | duplicates (4)
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
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl -w
use strict;
use Test::More (tests => 3);

BEGIN {use Chart::Gnuplot;}

my $temp = "temp.ps";

# Test default setting of label
{
    my $c = Chart::Gnuplot->new(
        output => $temp,
    );

    $c->label(
        text     => "Test label",
        position => "1, -2",
    );

    $c->_setChart();
    ok(&diff($c->{_script}, "label_1.gp") == 0);
}

# Test formatting label
{
    my $c = Chart::Gnuplot->new(
        output => $temp,
    );

    $c->label(
        text       => "Test label",
        position   => "1, -2",
        offset     => "1.5, 0",
        pointtype  => 5,
        pointsize  => 3,
        pointcolor => 'blue',
    );

    $c->_setChart();
    ok(&diff($c->{_script}, "label_2.gp") == 0);
}

# Test multiple labels
{
    my $c = Chart::Gnuplot->new(
        output => $temp,
    );

    # Label 1
    $c->label(
        text       => "Test label 1",
        position   => "2, -0.3",
        offset     => "1.5, 0",
        pointtype  => 5,
        pointsize  => 3,
        pointcolor => 'blue',
    );

    # Label 2
    $c->label(
        text      => "Test label 2",
        position  => "-2, 0.3",
        pointtype => 'square',
        pointsize => 2,
    );

    $c->_setChart();
    ok(&diff($c->{_script}, "label_3.gp") == 0);
}

###################################################################

# Compare two files
# - return 0 if two files are the same, except the ordering of the lines
# - return 1 otherwise
sub diff
{
    my ($f1, $f2) = @_;
    $f2 = "t/".$f2 if (!-e $f2);

    open(F1, $f1) || return(1);
    open(F2, $f2) || return(1);
    my @c1 = <F1>;
    my @c2 = <F2>;
    close(F1);
    close(F2);
    return(0) if (join("", sort @c1) eq join("", sort @c2));
    return(1);
}