File: simple

package info (click to toggle)
cl-interpol 20180509.git1fd288d-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 456 kB
  • sloc: lisp: 868; perl: 34; makefile: 2
file content (160 lines) | stat: -rw-r--r-- 4,951 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-INTERPOL-TEST; Base: 10 -*-
;;; $Header: /usr/local/cvsrep/cl-interpol/test/simple,v 1.4 2008/07/23 15:13:13 edi Exp $

;;; some simple tests for CL-INTERPOL - entered manually and to be
;;; read in the CL-INTERPOL-TEST package; all forms except SETQ forms
;;; are expected to return a true value on success when EVALuated

(string= #?"abc" "abc")
(string= #?'abc' "abc")
(string= #?|abc| "abc")
(string= #?/abc/ "abc")
(string= #?#abc# "abc")
(string= #?{abc} "abc")
(string= #?(abc) "abc")
(string= #?<abc> "abc")
(string= #?[abc] "abc")

(string= #?"abc\"" "abc\"")
(string= #?"abc\\" "abc\\")
(string= #?[a[b]c] "a[b]c")
(string= #?[a[[b]]c] "a[[b]]c")
(string= #?[a[[][]]b] "a[[][]]b")

(string= #?"\t\n\r\f\b\a\e"
                 (coerce (list #\Tab #\Newline #\Return #\Page #\Backspace (code-char 7) (code-char 27))
                         'string))
(string= #?"\033\x1b\c[\x{1b}"
                 (make-string 4 :initial-element (code-char 27)))
(string= #?"\x" (string (code-char 0)))
(string= #?"\x001" (format nil "~A1" (code-char 0)))
(string= #?"\0001" (format nil "~A1" (code-char 0)))

(char= (char #?"\x20" 0) #\Space)
(zerop (char-code (char #?"\x" 0)))
(zerop (char-code (char #?"\x{}" 0)))
(string= (unicode-name (char #?"\x{2323}" 0)) "SMILE")
(string=  #?"Only\x202 digits!" "Only 2 digits!")

;; might in theory fail on some Lisps - see 13.1.7
(string-equal (char-name (char #?"\cH" 0)) "Backspace")
(char= (char #?"\cj" 0) #\Newline)

;; two spaces
(string= #?"\40\040" "  "  )
;; note that \377 and \777 yield the same result
(equal (map 'list #'char-code #?"\0\377\777") '(0 255 255))
(string= #?"Only\0403 digits!" "Only 3 digits!")
(equal (map 'list #'identity #?"\9") (list #\9))

(string= #?"\N{LATIN CAPITAL LETTER A WITH DIAERESIS}" "")
(string= #?"\N{latin capital letter a with diaeresis}" "")
(string= #?{\N{LATIN CAPITAL LETTER A WITH DIAERESIS}} "")

(setq *try-abbreviations-p* t)

(string= #?"\N{Latin:A with Diaeresis}" "")
(string= #?"\N{Latin:a with diaeresis}" "")

(setq *scripts-to-try* "Latin")

(string= #?"\N{A with Diaeresis}" "")
(string= #?"\N{a with diaeresis}" "")

(setq *try-abbreviations-p* nil)
(setq *try-unicode1-names-p* t)

(string= #?"\N{LINEFEED (LF)}" #\Linefeed)

;; special CL-INTERPOL aliases
(string= #?"\N{LINEFEED}" #\Linefeed)
(string= #?"\N{CR}" #\Return)

(setq *try-hex-notation-p* t)

(= (char-code (char #?"\N{U+0042}" 0)) #x42)

(setq *try-lisp-names-p* t)

(char= (char #?"\N{Newline}" 0) #\Newline)

;; ignored newline
(string= #?"abc\
   def" "abcdef")

(string= #?/\1/ "\\1")
(string= #?r"\1" "\\1")
(string= #?r"\k<foo>" "\\k<foo>")
(string= #?r"\p{LC}" "\\p{LC}")
(string= #?x/abc / "abc")
(string= #?x/abc
                         / "abc")
(string= #?rx"abc " "abc")
(string= #?/[\1]\1/ (format nil "[~A]\\1" (code-char 1)))
(string= #?/[(?#foo)](?#foo)/ "[(?#foo)]")
(string= #?/a#bc/ "a#bc")
(string= #?x/a#bc/ "a")
(string= #?x/\d\A[\d\A]/ "\\d\\A[\\dA]")

(string= #?"\Q-" "\\-")
(string= #?"\Q-\E-" "\\--")
(string= #?"\ufoo" "Foo")
(string= #?"\Ufoo" "FOO")
(string= #?"\Ufoo\Ebar" "FOObar")
(string= #?"\Ufoo\LBAR" "FOObar")

(let ((a "foo"))
  (and (string= #?"$" "$")
       (string= #?"@ @" "@ @")
       (string= #?"${a}bar" "foobar")
       (string= #?/${a}bar/ "foobar")
       (string= #?"$[a]bar" "foobar")
       (string= #?"$(a)bar" "foobar")
       (string= #?"$<a>bar" "foobar")
       (string= #?/$<a>bar/ "$<a>bar")
       (string= #?"$a @a " "$a @a ")))

(let ((a (list 1 2 3)))
  (and (string= #?"${a}" "(1 2 3)")
       (string= #?"@{a}" "1 2 3")
       (let ((*list-delimiter* ""))
         (string= #?"@{a}" "123"))))

(let* ((a "foo")
       (b #\Space)
       (c "bar")
       (d (list a b c))
       (x 40))
  (and (string= #?"$ @" "$ @")
       (string= #?"$(a)" "foo")
       (string= #?"$<a>$[b]" "foo ")
       (string= #?"\U${a}\E \u${a}" "FOO Foo")
       (string= (let ((*list-delimiter* #\*))
                  #?"@{d}")
                "foo* *bar")
       (string= (let ((*list-delimiter* ""))
                  #?"@{d}")
                "foo bar")
       (string= #?"The result is ${(let ((y 2)) (+ x y))}"
                "The result is 42")
       (string= #?"${#?'${a} ${c}'} ${x}" "foo bar 40")))

(setq *optional-delimiters-p* t)

(string= (let ((% 23)) #?"$%a%b%") "23a%b%")
(string= (let ((%a 23)) #?"$%a%b%") "23%b%")
(string= (let ((%a% 23)) #?"$%a%b%") "23b%")
(string= (let ((%a%b 23)) #?"$%a%b%") "23%")
(string= (let ((%a%b% 23)) #?"$%a%b%") "23")

(setq *interpolate-format-directives* nil)

(string= (let ((a "abc")) (declare (ignorable a)) #?"~S(a)") "~S(a)")

(setq *interpolate-format-directives* t)

(string= (let ((a "abc")) #?"~S(a)") "\"abc\"")
(string= (let ((a "abc")) #?"~a(a)") "abc")
(string= (let ((number 41)) #?"~8,'0B((incf number) number)") "00101010")
(string= (let ((a "abc")) #?" \~~a(a)") " ~abc")
(string= #?" ~v~(4) " " ~~~~ ")