This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert utf8decode.t to test.pl
[perl5.git] / t / op / negate.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 plan tests => 16;
10
11 # Some of these will cause warnings if left on.  Here we're checking the
12 # functionality, not the warnings.
13 no warnings "numeric";
14
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');
22 is(-"-10.0", 10.0, 'Negation of string starting with "-" returns a positive number - decimal');
23 is(-"-10foo", "+10foo", 'Negation of string starting with "-" returns a string starting with "+" - non-numeric');
24 is(-"xyz", "-xyz", 'Negation of a negative string adds "-" to the front');
25 is(-"-xyz", "+xyz", "Negation of a negative string to positive");
26 is(-"+xyz", "-xyz", "Negation of a positive string to negative");
27 is(-bareword, "-bareword", "Negation of bareword treated like a string");
28 is(- -bareword, "+bareword", "Negation of -bareword returns string +bareword");
29 is(-" -10", 10, "Negation of a whitespace-lead numeric string");
30 is(-" -10.0", 10, "Negation of a whitespace-lead decimal string");
31 is(-" -10foo", 10, "Negation of a whitespace-lead sting starting with a numeric")