summaryrefslogtreecommitdiff
path: root/t/scalar-properties.t
blob: 33841669dce8825f2e0e665e34b6ce7088b08ee4 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
#!perl -w

my $loaded;

use strict;

use constant num_one => 1;
use constant num_two => 2;
use constant txt_one => 'one';
use constant txt_two => 'two';

use Data::Compare;

$| = 1;
eval 'use Scalar::Properties';
print (($@) ? "1..0 # Skipping no Scalar::Properties found\n" : "1..17\n");
exit(0) if($@);

my $test = 0;
print "ok ".(++$test)." load module\n";

eval q{

use Scalar::Properties;

# test SP vs SP

my($sp1, $sp2) = (1, 1);
print 'not ' unless(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs with same value, no properties compare the same\n";
 
($sp1, $sp2) = (1, 2);
print 'not ' if(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs with different values, no properties compare different\n";
 
($sp1, $sp2) = (1->a('frob')->b(num_one), 1->a('frob')->b(num_one));
print 'not ' unless(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs with same value, same properties compare the same\n";
 
($sp1, $sp2) = (1->a('foo')->b(num_one), 1->a('frob')->b(num_one));
print 'not ' if(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs same value, different properties compare different\n";

($sp1, $sp2) = (1->a('frob')->b(num_one), 2->a('frob')->b(num_one));
print 'not ' if(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs different value, same properties compare different\n";
 
($sp1, $sp2) = (1->a('foo')->b(num_one), 2->a('frob')->b(num_one));
print 'not ' if(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs different value, different properties compare different\n";
 
($sp1, $sp2) = (1, 1->a('frob')->b(num_one));
print 'not ' if(Compare($sp1, $sp2));
print 'ok '.(++$test)." SPs with same value, one with extra properties compare different\n";
 
($sp1, $sp2) = (1->a('frob')->b(num_one), 1);
print 'not ' if(Compare($sp1, $sp2));
print 'ok '.(++$test)." (rev) SPs with same value, one with extra properties compare different\n";
 
# test scalar vs SP

$sp1 = 1;
my $scalar1 = num_one;
print 'not ' unless(Compare($scalar1, $sp1));
print 'ok '.(++$test)." scalar and S::P with same numeric value compare the same\n";

$sp1 = 2;
print 'not ' if(Compare($scalar1, $sp1));
print 'ok '.(++$test)." scalar and S::P with different numeric value compare different\n";

$sp1 = 'one';
$scalar1 = txt_one;
print 'not ' unless(Compare($scalar1, $sp1));
print 'ok '.(++$test)." scalar and S::P with same string value compare the same\n";

$sp1 = 'two';
print 'not ' if(Compare($scalar1, $sp1));
print 'ok '.(++$test)." scalar and S::P with different string value compare different\n";

# test SP vs scalar

$sp1 = 1;
$scalar1 = num_one;
print 'not ' unless(Compare($sp1, $scalar1));
print 'ok '.(++$test)." (rev) scalar and S::P with same numeric value compare the same\n";

$sp1 = 2;
print 'not ' if(Compare($sp1, $scalar1));
print 'ok '.(++$test)." (rev) scalar and S::P with different numeric value compare different\n";

$sp1 = 'one';
$scalar1 = txt_one;
print 'not ' unless(Compare($sp1, $scalar1));
print 'ok '.(++$test)." (rev) scalar and S::P with same string value compare the same\n";

$sp1 = 'two';
print 'not ' if(Compare($sp1, $scalar1));
print 'ok '.(++$test)." (rev) scalar and S::P with different string value compare different\n";

}