1
0
mirror of synced 2026-02-11 19:04:55 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/18-3-STRING-RIGHT-TRIM.TEST

67 lines
2.4 KiB
Plaintext

;; Function To Be Tested: string-right-trim
;;
;; Source: CLtL p. 302
;; Chapter 18: Strings Section 3: String Construction and Manipulation
;;
;; Created By: Peter Reidy
;;
;; Creation Date: 23 July 86
;;
;; Last Update: 14 December 86
;;
;; Filed As: {eris}<lispcore>cml>test>18-3-string-right-trim.test
;;
;;
;; Syntax: string-right-trim character-bag string
;;
;; Function Description: starting from the right end of string and moving leftward, the function removes all occurrences of any characters found in character-bag until it encounters a character not in character-bag.
;;
;; Argument(s): character-bag - a list of characters of type string-char
;; string - any valid character string
;;
;; Returns: the substring of string consisting of string with the elements of character-bag removed as described; if the function trimmed no characters, the result is string= to string (but not eq in the Xerox implementation).
;;
(do-test-group string-right-trim-group
:before (test-setq upcase '|ABCDEFGHIJKLMNOPQRSTUVWXYZ|
lowcase '|abcdefghijklmnopqrstuvwxyz|
digits "0123456789")
;;
(do-test "string-right-trim stops when it encounters something not in character-bag"
;; In this case, W should not get trimmed.
(string= (string-right-trim '(#\A #\B #\W #\Z #\Y #\D) upcase) "ABCDEFGHIJKLMNOPQRSTUVWX")
)
;;
(do-test "string-right-trim can trim off the entire string and accept redundant characters"
(and
(string= (string-right-trim '(#\9 #\8 #\7 #\6 #\5 #\4 #\3 #\2 #\2 #\1 #\0) digits) "")
(string= (string-right-trim '(#\5) (make-string 5 :initial-element #\5)) "")
)
)
;;
(do-test "string-right-trim is case-sensitive"
(and
(not (string= lowcase (string-right-trim '(#\x #\y #\z) lowcase)))
(string= upcase (string-right-trim '(#\x #\y #\z) upcase))
)
)
;;
(do-test "string-right-trim accepts semi-standard characters"
(string=
(coerce '(#\Linefeed #\linefeed #\Return #\Linefeed) 'string)
(string-right-trim
'(#\G #\Page #\Tab)
(coerce '(#\Linefeed #\linefeed #\Return #\Linefeed #\Tab #\Page) 'string)
)
)
)
;;
(do-test "string-right-trim character-bag need not be all characters"
(and
(string= digits (string-right-trim '(50 '('(5 10) '(15 20)) |Alexis is a bitch|) digits))
(string= "0123456789" (string-right-trim '(50 #\1'('(5 10) '(15 20)) '|Alexis is a bitch| #\0) digits))
)
)
)
STOP