File: over_equal.t

package info (click to toggle)
libnetaddr-ip-perl 4.079%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 1,580 kB
  • ctags: 251
  • sloc: perl: 1,417; cpp: 67; sh: 51; makefile: 9
file content (122 lines) | stat: -rw-r--r-- 2,215 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

#use diagnostics;
use NetAddr::IP::Lite;

$| = 1;

print "1..14\n";

my $test = 1;
sub ok() {
  print 'ok ',$test++,"\n";
}

my $four	= new NetAddr::IP::Lite('0.0.0.4');		# same as 0.0.0.4/32
my $four120	= new NetAddr::IP::Lite('::4/120');	# same as 0.0.0.4/24

my $t432	= '0.0.0.4/32';
my $t4120	= '0:0:0:0:0:0:0:4/120';

my $five	= new NetAddr::IP::Lite('0.0.0.5');
my $t532	= '0.0.0.5/32';


# 1
## test '""' overload
my $txt = sprintf ("%s",$four120);

print "got: $txt, exp: $t4120\nnot "
	unless $txt eq $t4120;
&ok;

# 2
## test '""' again
$txt = sprintf ("%s",$four);

print "got: $txt, exp: $t432\nnot "
	unless $txt eq $t432;
&ok;

# 3
## test 'eq' to scalar
print 'failed ',$four," eq $t432\nnot "
	unless $four eq $t432;
&ok;

# 4
## test scalar 'eq' to
print "failed $t432 eq ",$four,"\nnot "
	unless $t432 eq $four;
&ok;

# 5
## test 'eq' to self
print 'failed ',$four,' eq ', $four,"\nnot "
	unless $four eq $four;
&ok;

# 6
## test 'eq' cidr !=
print 'failed ',$four,' should not eq ',$four120,"\nnot "
	if $four eq $four120;
&ok;

# 7
## test '==' not for scalars
print "failed scalar $t432 should not == ",$four,"\nnot "
	if $t432 == $four;
&ok;

# 8
## test '== not for scalar, reversed args
print 'failed scalar ',$four," should not == $t432\nnot "
	if $four == $t432;
&ok;

# ==========================================
#
# test "ne" and "!="
#
# 9
## test 'ne' to scalar
print 'failed ',$four120," ne $t432\nnot "
	unless $four120 ne $t432;
&ok;

# 10
## test scalar 'ne' to
print "failed $t432 ne ",$four120,"\nnot "
	unless $t432 ne $four120;
&ok;

# 11
## test 'ne' to cidr
print 'failed ',$four,' ne ', $four120,"\nnot "
	unless $four ne $four120;
&ok;

# 12
## test '!=' not for scalar, reversed args
$rv = $five != $four ? 1 : 0;
#print "rv=$rv\n";
print "failed scalar $five != $four\nnot "
	unless $rv;
&ok;

# unblessed scalars not welcome
undef local $^W;
# 13
## test '!=' not for scalars
my $rv = $t432 != $five ? 1 : 0;
#print "rv=$rv\n";
print "failed scalar $t432  != ",$five,"\nnot "
	unless $rv;
&ok;

# 14
# since both of these are string scalars, the != should fail
$rv = $t532 != $t432 ? 1 : 0;
#print "rv = $rv\n";
print "failed scalar $t532 != $t432\nnot "
	if $rv;
&ok;