diff options
author | Steve Peters <steve@fisharerojo.org> | 2005-12-17 15:35:45 +0000 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2005-12-17 15:35:45 +0000 |
commit | 8705167b57c0f17d383e9e8ced641c8a486046b2 (patch) | |
tree | 6abd18749a02af0716669e9581e8b4054b4f3ea6 /t | |
parent | 4ea1d5509b412a58fa64cd5ebc1ea31750b05303 (diff) | |
download | perl-8705167b57c0f17d383e9e8ced641c8a486046b2.tar.gz |
Addition documentation explaining aritmetic negation on strings. Also,
additional test cases based partially on code by Piotr Fusik in
RT #36675: -'-10' eq '+10'.
p4raw-id: //depot/perl@26387
Diffstat (limited to 't')
-rw-r--r-- | t/op/negate.t | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/t/op/negate.t b/t/op/negate.t new file mode 100644 index 0000000000..fb8d4b49e8 --- /dev/null +++ b/t/op/negate.t @@ -0,0 +1,31 @@ +#!./perl -w + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require './test.pl'; +} + +plan tests => 16; + +# Some of these will cause warnings if left on. Here we're checking the +# functionality, not the warnings. +no warnings "numeric"; + +# test cases based on [perl #36675] -'-10' eq '+10' +is(- 10, -10, "Simple numeric negation to negative"); +is(- -10, 10, "Simple numeric negation to positive"); +is(-"10", -10, "Negation of a positive string to negative"); +is(-"10.0", -10, "Negation of a positive decimal sting to negative"); +is(-"10foo", -10, "Negation of a numeric-lead string returns negation of numeric"); +is(-"-10", "+10", 'Negation of string starting with "-" returns a string starting with "+" - numeric'); +is(-"-10.0", "+10.0", 'Negation of string starting with "-" returns a string starting with "+" - decimal'); +is(-"-10foo", "+10foo", 'Negation of string starting with "-" returns a string starting with "+" - non-numeric'); +is(-"xyz", "-xyz", 'Negation of a negative string adds "-" to the front'); +is(-"-xyz", "+xyz", "Negation of a negative string to positive"); +is(-"+xyz", "-xyz", "Negation of a positive string to negative"); +is(-bareword, "-bareword", "Negation of bareword treated like a string"); +is(- -bareword, "+bareword", "Negation of -bareword returns string +bareword"); +is(-" -10", 10, "Negation of a whitespace-lead numeric string"); +is(-" -10.0", 10, "Negation of a whitespace-lead decimal string"); +is(-" -10foo", 10, "Negation of a whitespace-lead sting starting with a numeric") |