xref: /openbsd-src/gnu/usr.bin/perl/t/op/svflags.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    set_up_inc('../lib');
7    skip_all("need B, need full perl") if is_miniperl();
8}
9
10# Tests the new documented mechanism for determining the original type
11# of an SV.
12
13plan tests => 16;
14use strict;
15use B qw(svref_2object SVf_IOK SVf_NOK SVf_POK);
16
17my $x = 10;
18my $xobj = svref_2object(\$x);
19is($xobj->FLAGS & (SVf_IOK | SVf_POK), SVf_IOK, "correct base flags on IV");
20
21my $y = $x . "";
22
23is($xobj->FLAGS & (SVf_IOK | SVf_POK), SVf_IOK, "POK not set on IV used as string");
24
25$x = 1.0;
26
27is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "correct base flags on NV");
28
29$y = $x . "";
30
31is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on NV used as string");
32
33my $z = $x;
34$x = $z;
35
36is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on copy of NV used as string");
37
38$x = "Inf" + 0;
39
40is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "correct base flags on Inf NV");
41
42$y = $x . "";
43
44is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on Inf NV used as string");
45
46$z = $x;
47$x = $z;
48
49is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on copy of Inf NV used as string");
50
51$x = "-Inf" + 0;
52
53is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "correct base flags on -Inf NV");
54
55$y = $x . "";
56
57is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on -Inf NV used as string");
58
59$z = $x;
60$x = $z;
61
62is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on copy of -Inf NV used as string");
63
64{
65    local $^W = 0;
66    $x  = "NaN" + 0;
67}
68
69is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "correct base flags on NaN NV");
70
71$y = $x . "";
72
73is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on NaN NV used as string");
74
75$z = $x;
76$x = $z;
77
78is($xobj->FLAGS & (SVf_NOK | SVf_POK), SVf_NOK, "POK not set on copy of NaN NV used as string");
79
80$x = "10";
81is($xobj->FLAGS & (SVf_IOK | SVf_POK), SVf_POK, "correct base flags on PV");
82
83$y = $x + 10;
84
85is($xobj->FLAGS & (SVf_IOK | SVf_POK), (SVf_IOK | SVf_POK), "POK still set on PV used as number");
86