X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fstrings.lisp;h=43f1337376e839b67a8527554cc7270220865293;hb=2305b15fffc6679e9fdf42f6cd5bf49ee0dd3ce8;hp=81b5552423ba09fa59f9e67f1420c8f81edea985;hpb=bf8840c8c7a5c21190b27d51a9268cd520d473ac;p=jscl.git diff --git a/tests/strings.lisp b/tests/strings.lisp index 81b5552..43f1337 100644 --- a/tests/strings.lisp +++ b/tests/strings.lisp @@ -130,89 +130,93 @@ (test (string= (string-capitalize "pipe 13a, foo16c") "Pipe 13a, Foo16c")) (test (string= (string-capitalize "a fool" :start 2 :end nil) "a Fool")) -;; JSCL: no COPY-SEQ yet -;; (test (let ((str (copy-seq "0123ABCD890a"))) -;; (and (string= (nstring-downcase str :start 5 :end 7) "0123AbcD890a") -;; (string= str "0123AbcD890a")))) - -;; (test (let* ((str0 (copy-seq "abcde")) -;; (str (nstring-upcase str0))) -;; (and (eq str0 str) -;; (string= str "ABCDE")))) -;; (test (let* ((str0 (copy-seq "Dr. Livingston, I presume?")) -;; (str (nstring-upcase str0))) -;; (and (eq str0 str) -;; (string= str "DR. LIVINGSTON, I PRESUME?")))) -;; (test (let* ((str0 (copy-seq "Dr. Livingston, I presume?")) -;; (str (nstring-upcase str0 :start 6 :end 10))) -;; (and (eq str0 str) -;; (string= str "Dr. LiVINGston, I presume?")))) - -;; (test (let* ((str0 (copy-seq "abcde")) -;; (str (nstring-upcase str0 :start 2 :end nil))) -;; (string= str "abCDE"))) - - - -;; (test (let* ((str0 (copy-seq "Dr. Livingston, I presume?")) -;; (str (nstring-downcase str0))) -;; (and (eq str0 str) -;; (string= str "dr. livingston, i presume?")))) -;; (test (let* ((str0 (copy-seq "ABCDE")) -;; (str (nstring-downcase str0 :start 2 :end nil))) -;; (string= str "ABcde"))) - -;; (test (let* ((str0 (copy-seq "elm 13c arthur;fig don't")) -;; (str (nstring-capitalize str0))) -;; (and (eq str0 str) -;; (string= str "Elm 13c Arthur;Fig Don'T")))) - -;; (test (let* ((str0 (copy-seq " hello ")) -;; (str (nstring-capitalize str0))) -;; (and (eq str0 str) -;; (string= str " Hello ")))) -;; (test (let* ((str0 (copy-seq -;; "occlUDeD cASEmenTs FOreSTAll iNADVertent DEFenestraTION")) -;; (str (nstring-capitalize str0))) -;; (and (eq str0 str) -;; (string= str -;; "Occluded Casements Forestall Inadvertent Defenestration")))) -;; (test (let* ((str0 (copy-seq "DON'T!")) -;; (str (nstring-capitalize str0))) -;; (and (eq str0 str) -;; (string= str "Don'T!")))) ;not "Don't!" -;; (test (let* ((str0 (copy-seq "pipe 13a, foo16c")) -;; (str (nstring-capitalize str0))) -;; (and (eq str0 str) -;; (string= str "Pipe 13a, Foo16c")))) -;; (test (let* ((str0 (copy-seq "a fool")) -;; (str (nstring-capitalize str0 :start 2 :end nil))) -;; (string= str "a Fool"))) - - - -;; JSCL: my implementation of these needs :FROM-END, which doesn't exist yet. -;; (test (string= (string-trim "abc" "abcaakaaakabcaaa") "kaaak")) +;; JSCL HACK: a simple COPY-SEQ for testing string functions, since we don't have a real one yet +(defun copy-seq (string) + (let ((copy (make-string (length string)))) + (dotimes (i (length string) copy) + (aset copy i (char string i))))) + +(test (let ((str (copy-seq "0123ABCD890a"))) + (and (string= (nstring-downcase str :start 5 :end 7) "0123AbcD890a") + (string= str "0123AbcD890a")))) + +(test (let* ((str0 (copy-seq "abcde")) + (str (nstring-upcase str0))) + (and (eq str0 str) + (string= str "ABCDE")))) +(test (let* ((str0 (copy-seq "Dr. Livingston, I presume?")) + (str (nstring-upcase str0))) + (and (eq str0 str) + (string= str "DR. LIVINGSTON, I PRESUME?")))) +(test (let* ((str0 (copy-seq "Dr. Livingston, I presume?")) + (str (nstring-upcase str0 :start 6 :end 10))) + (and (eq str0 str) + (string= str "Dr. LiVINGston, I presume?")))) + +(test (let* ((str0 (copy-seq "abcde")) + (str (nstring-upcase str0 :start 2 :end nil))) + (string= str "abCDE"))) + + + +(test (let* ((str0 (copy-seq "Dr. Livingston, I presume?")) + (str (nstring-downcase str0))) + (and (eq str0 str) + (string= str "dr. livingston, i presume?")))) +(test (let* ((str0 (copy-seq "ABCDE")) + (str (nstring-downcase str0 :start 2 :end nil))) + (string= str "ABcde"))) + +(test (let* ((str0 (copy-seq "elm 13c arthur;fig don't")) + (str (nstring-capitalize str0))) + (and (eq str0 str) + (string= str "Elm 13c Arthur;Fig Don'T")))) + +(test (let* ((str0 (copy-seq " hello ")) + (str (nstring-capitalize str0))) + (and (eq str0 str) + (string= str " Hello ")))) +(test (let* ((str0 (copy-seq + "occlUDeD cASEmenTs FOreSTAll iNADVertent DEFenestraTION")) + (str (nstring-capitalize str0))) + (and (eq str0 str) + (string= str + "Occluded Casements Forestall Inadvertent Defenestration")))) +(test (let* ((str0 (copy-seq "DON'T!")) + (str (nstring-capitalize str0))) + (and (eq str0 str) + (string= str "Don'T!")))) ;not "Don't!" +(test (let* ((str0 (copy-seq "pipe 13a, foo16c")) + (str (nstring-capitalize str0))) + (and (eq str0 str) + (string= str "Pipe 13a, Foo16c")))) +(test (let* ((str0 (copy-seq "a fool")) + (str (nstring-capitalize str0 :start 2 :end nil))) + (string= str "a Fool"))) + + + +(test (string= (string-trim "abc" "abcaakaaakabcaaa") "kaaak")) ;; (test (string= (string-trim '(#\Space #\Tab #\Newline) " garbanzo beans ;; ") "garbanzo beans")) -;; (test (string= (string-trim " (*)" " ( *three (silly) words* ) ") -;; "three (silly) words")) -;; (test (string= (string-left-trim "abc" "labcabcabc") "labcabcabc")) -;; (test (string= (string-left-trim " (*)" " ( *three (silly) words* ) ") -;; "three (silly) words* ) ")) -;; (test (string= (string-right-trim " (*)" " ( *three (silly) words* ) ") -;; " ( *three (silly) words")) -;; (test (string= (string-trim "ABC" "abc") "abc")) -;; (test (string= (string-trim "AABBCC" "abc") "abc")) -;; (test (string= (string-trim "" "abc") "abc")) -;; (test (string= (string-trim "ABC" "") "")) -;; (test (string= (string-trim "cba" "abc") "")) -;; (test (string= (string-trim "cba" "abccba") "")) -;; (test (string= (string-trim "ccbbba" "abccba") "")) -;; (test (string= (string-trim "cba" "abcxabc") "x")) -;; (test (string= (string-trim "xyz" "xxyabcxyyz") "abc")) -;; (test (string= (string-trim "CBA" 'abcxabc) "X")) -;; (test (string= (string-trim "a" #\a) "")) +(test (string= (string-trim " (*)" " ( *three (silly) words* ) ") + "three (silly) words")) +(test (string= (string-left-trim "abc" "labcabcabc") "labcabcabc")) +(test (string= (string-left-trim " (*)" " ( *three (silly) words* ) ") + "three (silly) words* ) ")) +(test (string= (string-right-trim " (*)" " ( *three (silly) words* ) ") + " ( *three (silly) words")) +(test (string= (string-trim "ABC" "abc") "abc")) +(test (string= (string-trim "AABBCC" "abc") "abc")) +(test (string= (string-trim "" "abc") "abc")) +(test (string= (string-trim "ABC" "") "")) +(test (string= (string-trim "cba" "abc") "")) +(test (string= (string-trim "cba" "abccba") "")) +(test (string= (string-trim "ccbbba" "abccba") "")) +(test (string= (string-trim "cba" "abcxabc") "x")) +(test (string= (string-trim "xyz" "xxyabcxyyz") "abc")) +(test (string= (string-trim "CBA" 'abcxabc) "X")) +(test (string= (string-trim "a" #\a) "")) (test (string= (string-left-trim "ABC" "abc") "abc")) @@ -225,15 +229,15 @@ (test (string= (string-left-trim "CBA" 'abcxabc) "XABC")) (test (string= (string-left-trim "a" #\a) "")) -;; (test (string= (string-right-trim "ABC" "abc") "abc")) -;; (test (string= (string-right-trim "" "abc") "abc")) -;; (test (string= (string-right-trim "ABC" "") "")) -;; (test (string= (string-right-trim "cba" "abc") "")) -;; (test (string= (string-right-trim "cba" "abccba") "")) -;; (test (string= (string-right-trim "cba" "abcxabc") "abcx")) -;; (test (string= (string-right-trim "xyz" "xxyabcxyz") "xxyabc")) -;; (test (string= (string-right-trim "CBA" 'abcxabc) "ABCX")) -;; (test (string= (string-right-trim "a" #\a) "")) +(test (string= (string-right-trim "ABC" "abc") "abc")) +(test (string= (string-right-trim "" "abc") "abc")) +(test (string= (string-right-trim "ABC" "") "")) +(test (string= (string-right-trim "cba" "abc") "")) +(test (string= (string-right-trim "cba" "abccba") "")) +(test (string= (string-right-trim "cba" "abcxabc") "abcx")) +(test (string= (string-right-trim "xyz" "xxyabcxyz") "xxyabc")) +(test (string= (string-right-trim "CBA" 'abcxabc) "ABCX")) +(test (string= (string-right-trim "a" #\a) ""))