cvsuser 01/10/03 08:58:54
Modified: . string.c
t/op string.t
Log:
chop fixes for n < 0 and tests
Courtesy of: Alex Gough <[EMAIL PROTECTED]>
Revision Changes Path
1.11 +4 -1 parrot/string.c
Index: string.c
===================================================================
RCS file: /home/perlcvs/parrot/string.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- string.c 2001/10/02 14:01:30 1.10
+++ string.c 2001/10/03 15:58:54 1.11
@@ -1,7 +1,7 @@
/* string.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: string.c,v 1.10 2001/10/02 14:01:30 simon Exp $
+ * $Id: string.c,v 1.11 2001/10/03 15:58:54 simon Exp $
* Overview:
* This is the api definitions for the string subsystem
* Data Structure and Algorithms:
@@ -142,6 +142,9 @@
string_chopn(STRING* s, INTVAL n) {
if (n > s->strlen) {
n = s->strlen;
+ }
+ if (n < 0) {
+ n = 0;
}
return (ENC_VTABLE(s)->chopn)(s, n);
}
1.6 +22 -1 parrot/t/op/string.t
Index: string.t
===================================================================
RCS file: /home/perlcvs/parrot/t/op/string.t,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- string.t 2001/09/25 09:12:57 1.5
+++ string.t 2001/10/03 15:58:54 1.6
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 11;
output_is( <<'CODE', <<OUTPUT, "set_s_sc" );
set S4, "JAPH\n"
@@ -33,6 +33,27 @@
CODE
JAPH
japh
+OUTPUT
+
+output_is(<<'CODE', <<OUTPUT, "chopn, OOB values");
+ set S1, "A string of length 21"
+ chopn S1, 0
+ print S1
+ print "\n"
+ chopn S1, 4
+ print S1
+ print "\n"
+ chopn S1, -4
+ print S1
+ print "\n"
+ chopn S1, 1000
+ print S1
+ print "** nothing **\n"
+CODE
+A string of length 21
+A string of lengt
+A string of lengt
+** nothing **
OUTPUT
output_is( <<'CODE', 'JAPH', "substr_s_s_i_i" );