From 8ae132f29fe3732e97c2eec74bd1eb65ecdf35fc Mon Sep 17 00:00:00 2001 From: Samuel Chase Date: Mon, 13 May 2013 12:04:38 +0530 Subject: [PATCH] Add test for (string< "aaa" "aaaaa") Updated implementation of string< so that the above test passes. --- src/string.lisp | 16 +++++++++------- tests/strings.lisp | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/string.lisp b/src/string.lisp index aebad3a..9c547ef 100644 --- a/src/string.lisp +++ b/src/string.lisp @@ -27,13 +27,15 @@ (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)) diff --git a/tests/strings.lisp b/tests/strings.lisp index cb6cd83..f68ee1c 100644 --- a/tests/strings.lisp +++ b/tests/strings.lisp @@ -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 -- 1.7.10.4