11 # Some of these will cause warnings if left on. Here we're checking the
12 # functionality, not the warnings.
13 no warnings "numeric";
15 # test cases based on [perl #36675] -'-10' eq '+10'
16 is(- 10, -10, "Simple numeric negation to negative");
17 is(- -10, 10, "Simple numeric negation to positive");
18 is(-"10", -10, "Negation of a positive string to negative");
19 is(-"10.0", -10, "Negation of a positive decimal sting to negative");
20 is(-"10foo", -10, "Negation of a numeric-lead string returns negation of numeric");
21 is(-"-10", 10, 'Negation of string starting with "-" returns a positive number - integer');
23 is(-$1, 10, 'Negation of magical string starting with "-" - integer');
24 is(-"-10.0", 10.0, 'Negation of string starting with "-" returns a positive number - decimal');
26 is(-$1, 10.0, 'Negation of magical string starting with "-" - decimal');
27 is(-"-10foo", "+10foo", 'Negation of string starting with "-" returns a string starting with "+" - non-numeric');
28 is(-"xyz", "-xyz", 'Negation of a negative string adds "-" to the front');
29 is(-"-xyz", "+xyz", "Negation of a negative string to positive");
30 is(-"+xyz", "-xyz", "Negation of a positive string to negative");
31 is(-bareword, "-bareword", "Negation of bareword treated like a string");
32 is(- -bareword, "+bareword", "Negation of -bareword returns string +bareword");
33 is(-" -10", 10, "Negation of a whitespace-lead numeric string");
34 is(-" -10.0", 10, "Negation of a whitespace-lead decimal string");
36 "Negation of a whitespace-lead sting starting with a numeric");
37 is(-"-e1", "+e1", "Negation of e1");
41 is -$x, '-dogs', 'cached numeric value does not sabotage string negation';
43 is(-"97656250000000000", -97656250000000000, '-bigint vs -"bigint"');
44 "9765625000000000" =~ /(\d+)/;
45 is -$1, -"$1", '-$1 vs -"$1" with big int';
48 chop($au = "%apples\x{100}");
49 is(-$au, -$a, 'utf8 flag makes no difference for string negation');
50 is -"\x{100}", 0, '-(non-ASCII) is equivalent to -(punct)';
52 sub TIESCALAR { bless[] }
53 sub STORE { $_[0][0] = $_[1] }
54 sub FETCH { $_[0][0] }
57 $a = "97656250000000000";
60 is -$t, -97656250000000000, 'magic str+int dualvar';
62 { # Repeat most of the tests under use integer
64 is(- 10, -10, "Simple numeric negation to negative");
65 is(- -10, 10, "Simple numeric negation to positive");
66 is(-"10", -10, "Negation of a positive string to negative");
67 is(-"10.0", -10, "Negation of a positive decimal sting to negative");
69 "Negation of a numeric-lead string returns negation of numeric");
71 'Negation of string starting with "-" returns a positive number -'
74 is(-$1, 10, 'Negation of magical string starting with "-" - integer');
76 'Negation of string starting with "-" returns a positive number - '
79 is(-$1, 10, 'Negation of magical string starting with "-" - decimal');
80 is(-"-10foo", "+10foo",
81 'Negation of string starting with "-" returns a string starting '
82 .'with "+" - non-numeric');
84 'Negation of a negative string adds "-" to the front');
85 is(-"-xyz", "+xyz", "Negation of a negative string to positive");
86 is(-"+xyz", "-xyz", "Negation of a positive string to negative");
87 is(-bareword, "-bareword",
88 "Negation of bareword treated like a string");
89 is(- -bareword, "+bareword",
90 "Negation of -bareword returns string +bareword");
91 is(-" -10", 10, "Negation of a whitespace-lead numeric string");
92 is(-" -10.0", 10, "Negation of a whitespace-lead decimal string");
94 "Negation of a whitespace-lead sting starting with a numeric");
95 is(-"-e1", "+e1", "Negation of e1 (use integer)");
100 'cached numeric value does not sabotage string negation';
103 chop($au = "%apples\x{100}");
104 is(-$au, -$a, 'utf8 flag makes no difference for string negation');
105 is -"\x{100}", 0, '-(non-ASCII) is equivalent to -(punct)';
108 # [perl #120288] use integer should not stop barewords from being quoted
112 is eval "return -a"||$@, "-a", '-bareword under strict+integer';