-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
137 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,73 @@ | ||
;; Copyright 2013 Google Inc. | ||
;; | ||
;; Licensed under the Apache License, Version 2.0 (the "License"); | ||
;; you may not use this file except in compliance with the License. | ||
;; You may obtain a copy of the License at | ||
;; | ||
;; http://www.apache.org/licenses/LICENSE-2.0 | ||
;; | ||
;; Unless required by applicable law or agreed to in writing, software | ||
;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;; See the License for the specific language governing permissions and | ||
;; limitations under the License. | ||
;;; Copyright 2013 Google Inc. | ||
;;; | ||
;;; Licensed under the Apache License, Version 2.0 (the "License"); | ||
;;; you may not use this file except in compliance with the License. | ||
;;; You may obtain a copy of the License at | ||
;;; | ||
;;; http://www.apache.org/licenses/LICENSE-2.0 | ||
;;; | ||
;;; Unless required by applicable law or agreed to in writing, software | ||
;;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;;; See the License for the specific language governing permissions and | ||
;;; limitations under the License. | ||
|
||
(define-test test-double-quoted-strings-are-strings | ||
(let ((my-string "do or do not")) | ||
(true-or-false? ___ (typep my-string 'string)) | ||
"strings are the same thing as vectors of characters" | ||
(true-or-false? ___ (typep my-string 'array)) | ||
(assert-equal (aref "meat" 2) (aref "fiesta" 5)) | ||
"strings are not integers :p" | ||
(true-or-false? ___ (typep my-string 'integer)))) | ||
(define-test what-is-a-string | ||
(let ((string "Do, or do not. There is no try.")) | ||
(true-or-false? ____ (typep string 'string)) | ||
;; Strings are vectors of characters. | ||
(true-or-false? ____ (typep string 'array)) | ||
(true-or-false? ____ (typep string 'vector)) | ||
(true-or-false? ____ (typep string '(vector character))) | ||
(true-or-false? ____ (typep string 'integer)))) | ||
|
||
(define-test multiline-string | ||
;; A Lisp string can span multiple lines. | ||
(let ((string "this is | ||
a multi | ||
line string")) | ||
(true-or-false? ___ (typep string 'string)))) | ||
|
||
(define-test test-multi-line-strings-are-strings | ||
(let ((my-string "this is | ||
a multi | ||
line string")) | ||
(true-or-false? ___ (typep my-string 'string)))) | ||
(define-test escapes-in-strings | ||
;; Quotes and backslashes in Lisp strings must be escaped. | ||
(let ((my-string "this string has one of these \" and a \\ in it")) | ||
(true-or-false? ____ (typep my-string 'string)))) | ||
|
||
(define-test substrings | ||
;; Since strings are sequences, it is possible to use SUBSEQ on them. | ||
(let ((string "Lorem ipsum dolor sit amet")) | ||
(assert-equal ____ (subseq string 12)) | ||
(assert-equal ____ (subseq string 6 11)) | ||
(assert-equal ____ (subseq string 1 5)))) | ||
|
||
(define-test test-escape-quotes | ||
(let ((my-string "this string has one of these \" in it")) | ||
(true-or-false? ___ (typep my-string 'string)))) | ||
|
||
|
||
; This test from common lisp cookbook | ||
(define-test test-substrings | ||
"since strings are sequences, you may use subseq" | ||
(let ((my-string "Groucho Marx")) | ||
(assert-equal "Marx" (subseq my-string 8)) | ||
(assert-equal (subseq my-string 0 7) ____) | ||
(assert-equal (subseq my-string 1 5) ____))) | ||
|
||
(define-test test-accessing-individual-characters | ||
"char literals look like this" | ||
(true-or-false? ___ (typep #\a 'character)) | ||
(true-or-false? ___ (typep "A" 'character)) | ||
(true-or-false? ___ (typep #\a 'string)) | ||
"char is used to access individual characters" | ||
(define-test strings-versus-characters | ||
;; Strings and characters have distinct types. | ||
(true-or-false? ____ (typep #\a 'character)) | ||
(true-or-false? ____ (typep "A" 'character)) | ||
(true-or-false? ____ (typep #\a 'string)) | ||
;; One can use both AREF and CHAR to refer to characters in a string. | ||
(let ((my-string "Cookie Monster")) | ||
(assert-equal (char my-string 0) #\C) | ||
(assert-equal (char my-string 3) #\k) | ||
(assert-equal (char my-string 7) ___))) | ||
|
||
(assert-equal ____ (char my-string 0)) | ||
(assert-equal ____ (char my-string 3)) | ||
(assert-equal ____ (aref my-string 7)))) | ||
|
||
(define-test test-concatenating-strings | ||
"concatenating strings in lisp is a little cumbersome" | ||
(let ((a "this") | ||
(b "is") | ||
(c "unwieldy")) | ||
(assert-equal ___ (concatenate 'string a " " b " " c)))) | ||
|
||
;; Concatenating strings in Common Lisp is possible, if a little cumbersome. | ||
(let ((a "Lorem") | ||
(b "ipsum") | ||
(c "dolor")) | ||
(assert-equal ____ (concatenate 'string a " " b " " c)))) | ||
|
||
(define-test test-searching-for-characters | ||
"you can use position to detect characters in strings | ||
(or elements of sequences)" | ||
(assert-equal ___ (position #\b "abc")) | ||
(assert-equal ___ (position #\c "abc")) | ||
(assert-equal ___ (find #\d "abc"))) | ||
|
||
;; The function POSITION can be used to find the first position of an element | ||
;; in a sequence. If the element is not found, NIL is returned. | ||
(assert-equal ____ (position #\b "abc")) | ||
(assert-equal ____ (position #\c "abc")) | ||
(assert-equal ____ (position #\d "abc"))) | ||
|
||
(define-test test-finding-substrings | ||
"search finds subsequences" | ||
;; The function SEARCH can be used to search a sequence for subsequences. | ||
(let ((title "A supposedly fun thing I'll never do again")) | ||
(assert-equal 2 (search "supposedly" title)) | ||
(assert-equal 12 (search "CHANGETHISWORD" title)))) | ||
(assert-equal ____ (search "supposedly" title)) | ||
(assert-equal 12 (search ____ title)))) | ||
|