tagged release 0.7.1
[parrot.git] / languages / tcl / t / cmd_incr.t
blob9cdda34366b768ceb51c76b270f6241611d3ebbe
1 #!perl
3 # Copyright (C) 2004-2006, The Perl Foundation.
4 # $Id$
6 # the following lines re-execute this as a tcl script
7 # the \ at the end of these lines makes them a comment in tcl \
8 use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
9 use Tcl::Test; #\
10 __DATA__
12 source lib/test_more.tcl
14 plan 15
16 eval_is {
17  set a 2
18  incr a
19  set a
20 } 3 simple
22 eval_is {
23  set a 1
24  incr a 5
25  set a
26 } 6 offset
28 eval_is {
29  set a 2
30  incr a -1
31  set a
32 } 1 {negative offset}
34 eval_is {
35  set a 1
36  incr a
37 } 2 {return value}
39 eval_is {
40  set a -2
41  incr a
42  set a
43 } -1 {negative base}
46 eval_is {
47  set a 2
48  incr a +3
49  set a
50 } 5 {explicit positive offset}
52 eval_is {
53  set a 1
54  incr a 3 2
55  set a
56 } {wrong # args: should be "incr varName ?increment?"} {too many args}
58 eval_is {
59  set a 1
60  incr
61  puts $a
62 } {wrong # args: should be "incr varName ?increment?"} {too few args}
64 eval_is {
65   set a 1
66   incr a a
67 } {expected integer but got "a"} {expected integer, got alpha}
69 # This test fails in tclsh8.5a5:
70 # https://sourceforge.net/tracker/?func=detail&atid=110894&aid=1602991&group_id=10894
71 eval_is {
72   set a 1
73   incr a 1.5
74 } {expected integer but got "1.5"} {expected integer, got float}
76 # as of 8.5, this autovivifies the variable
77 eval_is {
78   catch {unset a}
79   incr a
80 } 1 {no such variable}
83 # Uses the same parsing mechanism as
84 # [expr <octal>] - all the edge cases are tested there.
85 eval_is {
86   set i 25
87   incr i 000012345
88   set i
89 } 5374 {octal offset}
91 eval_is {
92   set x foo
93   incr x
94 } {expected integer but got "foo"} {not an int}
96 eval_is {
97   set x {   14   }
98   incr x
99   set x
100 } 15 {space padded int}
102 eval_is {
103   set x 0xff
104   incr x
105   set x
106 } 256 {hex variable}
108 # Local Variables:
109 #   mode: cperl
110 #   cperl-indent-level: 4
111 #   fill-column: 100
112 # End:
113 # vim: expandtab shiftwidth=4: