Add test for (string< "aaa" "aaaaa")
authorSamuel Chase <samebchase@gmail.com>
Mon, 13 May 2013 06:34:38 +0000 (12:04 +0530)
committerSamuel Chase <samebchase@gmail.com>
Mon, 13 May 2013 06:34:38 +0000 (12:04 +0530)
Updated implementation of string< so that the above test passes.

src/string.lisp
tests/strings.lisp

index aebad3a..9c547ef 100644 (file)
 
 (defun string< (s1 s2)
   (let ((len-1 (length s1))
-               (len-2 (length s2)))
-       (cond ((= len-2 0) nil)
-                 ((= len-1 0) 0)
-                 (t (dotimes (i len-1 nil)
-                          (when (char< (char s1 i) (char s2 i))
-                                (return-from string< i)))))))
-               
+        (len-2 (length s2)))
+    (cond ((= len-2 0) nil)
+          ((= len-1 0) 0)
+          (t (dotimes (i len-1 nil)
+               (when (char< (char s1 i) (char s2 i))
+                 (return-from string< i))
+               (when (and (= i (1- len-1)) (> len-2 len-1))
+                 (return-from string< (1+ i))))))))
+
 (define-setf-expander char (string index)
   (let ((g!string (gensym))
         (g!index (gensym))
index cb6cd83..f68ee1c 100644 (file)
@@ -22,6 +22,7 @@
 (test (null (string< "" "")))
 (test (null (string< "a" "")))
 (test (= (string< "" "a") 0))
+(test (= (string< "aaa" "aaaaa") 3))
 
 ;;; BUG: The compiler will macroexpand the forms below (char str N)
 ;;; will expand to internal SBCL code instead of our (setf char). It