5 |
|
|
6 |
(in-package :cl-test) |
(in-package :cl-test) |
7 |
|
|
8 |
;;; Test that |
(compile-and-load "reader-aux.lsp") |
9 |
|
|
10 |
(def-syntax-test syntax.whitespace.1 |
(def-syntax-test syntax.whitespace.1 |
11 |
;; Check that various standard or semistandard characters are whitespace[2] |
;; Check that various standard or semistandard characters are whitespace[2] |
12 |
(let ((names '("Tab" "Newline" "Linefeed" "Space" "Return" "Page"))) |
(let ((names '("Tab" "Newline" "Linefeed" "Space" "Return" "Page"))) |
301 |
|
|
302 |
;;; Tess of #(...) |
;;; Tess of #(...) |
303 |
|
|
|
(defmacro def-syntax-vector-test (name form &body expected-elements) |
|
|
`(def-syntax-test ,name |
|
|
(let ((v (read-from-string ,form))) |
|
|
(assert (simple-vector-p v)) |
|
|
v) |
|
|
,(apply #'vector expected-elements))) |
|
|
|
|
304 |
(def-syntax-vector-test syntax.sharp-left-paren.1 |
(def-syntax-vector-test syntax.sharp-left-paren.1 |
305 |
"#()") |
"#()") |
306 |
|
|
341 |
|
|
342 |
;;; Tests of #* |
;;; Tests of #* |
343 |
|
|
|
(defmacro def-syntax-bit-vector-test (name form &body expected-elements) |
|
|
`(def-syntax-test ,name |
|
|
(let ((v (read-from-string ,form))) |
|
|
(assert (simple-bit-vector-p v)) |
|
|
v) |
|
|
,(make-array (length expected-elements) :element-type 'bit :initial-contents expected-elements))) |
|
|
|
|
344 |
(def-syntax-bit-vector-test syntax.sharp-asterisk.1 |
(def-syntax-bit-vector-test syntax.sharp-asterisk.1 |
345 |
"#*") |
"#*") |
346 |
|
|
403 |
|
|
404 |
;;; Tests of #: ... |
;;; Tests of #: ... |
405 |
|
|
|
(defmacro def-syntax-unintern-test (name string) |
|
|
`(deftest ,name |
|
|
(let ((s (read-from-string ,(concatenate 'string "#:" string)))) |
|
|
(values |
|
|
(symbol-package s) |
|
|
(symbol-name s))) |
|
|
nil ,(string-upcase string))) |
|
|
|
|
406 |
; (def-syntax-unintern-test syntax.sharp-colon.1 "") |
; (def-syntax-unintern-test syntax.sharp-colon.1 "") |
407 |
(def-syntax-unintern-test syntax.sharp-colon.2 "#") |
(def-syntax-unintern-test syntax.sharp-colon.2 "#") |
408 |
(def-syntax-unintern-test syntax.sharp-colon.3 "a") |
(def-syntax-unintern-test syntax.sharp-colon.3 "a") |
674 |
|
|
675 |
;;; Tests of #a |
;;; Tests of #a |
676 |
|
|
|
(defmacro def-syntax-array-test (name form expected-result) |
|
|
`(def-syntax-test ,name |
|
|
(let ((v (read-from-string ,form))) |
|
|
(assert (typep v 'simple-array)) |
|
|
(assert (not (array-has-fill-pointer-p v))) |
|
|
(assert (eql (array-element-type v) |
|
|
(upgraded-array-element-type t))) |
|
|
v) |
|
|
,(eval expected-result))) |
|
|
|
|
677 |
(def-syntax-array-test syntax.sharp-a.1 |
(def-syntax-array-test syntax.sharp-a.1 |
678 |
"#0anil" |
"#0anil" |
679 |
(make-array nil :initial-element nil)) |
(make-array nil :initial-element nil)) |
791 |
|
|
792 |
;;; Tests of #S |
;;; Tests of #S |
793 |
|
|
794 |
(defstruct syntax-test-struct-1 |
(unless (find-class 'syntax-test-struct-1) |
795 |
a b c) |
(defstruct syntax-test-struct-1 |
796 |
|
a b c)) |
797 |
|
|
798 |
(def-syntax-test syntax.sharp-s.1 |
(def-syntax-test syntax.sharp-s.1 |
799 |
(let ((v (read-from-string "#s(syntax-test-struct-1)"))) |
(let ((v (read-from-string "#s(syntax-test-struct-1)"))) |
907 |
(read-from-string "#p\"syntax.lsp\"")) |
(read-from-string "#p\"syntax.lsp\"")) |
908 |
#.(parse-namestring "syntax.lsp") 14) |
#.(parse-namestring "syntax.lsp") 14) |
909 |
|
|
910 |
|
(def-syntax-test syntax.sharp-p.5 |
911 |
|
(read-from-string "#P#.(make-array '(10) :initial-contents \"syntax.lsp\" :element-type 'base-char)") |
912 |
|
#.(parse-namestring "syntax.lsp") 78) |
913 |
|
|
914 |
|
;;; #<number># and #<number>= |
915 |
|
|
916 |
|
(def-syntax-test syntax.sharp-circle.1 |
917 |
|
(let ((x (read-from-string "(#1=(17) #1#)"))) |
918 |
|
(assert (eq (car x) (cadr x))) |
919 |
|
x) |
920 |
|
((17) (17))) |
921 |
|
|
922 |
|
(def-syntax-test syntax.sharp-circle.2 |
923 |
|
(let ((x (read-from-string "(#0=(17) #0#)"))) |
924 |
|
(assert (eq (car x) (cadr x))) |
925 |
|
x) |
926 |
|
((17) (17))) |
927 |
|
|
928 |
|
(def-syntax-test syntax.sharp-circle.3 |
929 |
|
(let ((x (read-from-string "(#123456789123456789=(17) #123456789123456789#)"))) |
930 |
|
(assert (eq (car x) (cadr x))) |
931 |
|
x) |
932 |
|
((17) (17))) |
933 |
|
|
934 |
|
(def-syntax-test syntax.sharp-circle.4 |
935 |
|
(let ((x (read-from-string "#1=(A B . #1#)"))) |
936 |
|
(assert (eq (cddr x) x)) |
937 |
|
(values (car x) (cadr x))) |
938 |
|
a b) |
939 |
|
|
940 |
|
(def-syntax-test syntax.sharp-circle.5 |
941 |
|
(let ((x (read-from-string "#1=#(A B #1#)"))) |
942 |
|
(assert (typep x '(simple-vector 3))) |
943 |
|
(assert (eq (elt x 2) x)) |
944 |
|
(values (elt x 0) (elt x 1))) |
945 |
|
a b) |
946 |
|
|
947 |
|
(def-syntax-test syntax.sharp-circle.6 |
948 |
|
(let ((x (read-from-string "((#1=(17)) #1#)"))) |
949 |
|
(assert (eq (caar x) (cadr x))) |
950 |
|
x) |
951 |
|
(((17)) (17))) |
952 |
|
|
953 |
|
(def-syntax-test syntax.sharp-circle.7 |
954 |
|
(let ((x (read-from-string "((#1=#2=(:x)) #1# #2#)"))) |
955 |
|
(assert (eq (caar x) (cadr x))) |
956 |
|
(assert (eq (caar x) (caddr x))) |
957 |
|
x) |
958 |
|
(((:x)) (:x) (:x))) |
959 |
|
|
960 |
|
;;; #+ |
961 |
|
|
962 |
|
(def-syntax-test syntax.sharp-plus.1 |
963 |
|
(let ((*features* nil)) |
964 |
|
(read-from-string "#+X :bad :good")) |
965 |
|
:good 14) |
966 |
|
|
967 |
|
(def-syntax-test syntax.sharp-plus.2 |
968 |
|
(let ((*features* '(:a :x :b))) |
969 |
|
(read-from-string "#+X :good :bad")) |
970 |
|
:good 10) |
971 |
|
|
972 |
|
(def-syntax-test syntax.sharp-plus.3 |
973 |
|
(let ((*features* '(:a :x :b))) |
974 |
|
(read-from-string "#+:x :good :bad")) |
975 |
|
:good 11) |
976 |
|
|
977 |
|
(def-syntax-test syntax.sharp-plus.4 |
978 |
|
(let ((*features* '(:a :x :b))) |
979 |
|
(read-from-string "#+(and):good :bad")) |
980 |
|
:good 13) |
981 |
|
|
982 |
|
(def-syntax-test syntax.sharp-plus.5 |
983 |
|
(let ((*features* '(:a :x :b))) |
984 |
|
(read-from-string "#+(:and):good :bad")) |
985 |
|
:good 14) |
986 |
|
|
987 |
|
(def-syntax-test syntax.sharp-plus.6 |
988 |
|
(let ((*features* '(:a :x :b))) |
989 |
|
(read-from-string "#+(or) :bad :good")) |
990 |
|
:good 17) |
991 |
|
|
992 |
|
(def-syntax-test syntax.sharp-plus.7 |
993 |
|
(let ((*features* '(:a :x :b))) |
994 |
|
(read-from-string "#+(:or) :bad :good")) |
995 |
|
:good 18) |
996 |
|
|
997 |
|
(def-syntax-test syntax.sharp-plus.8 |
998 |
|
(let ((*features* '(x))) |
999 |
|
(read-from-string "#+X :bad :good")) |
1000 |
|
:good 14) |
1001 |
|
|
1002 |
|
(def-syntax-test syntax.sharp-plus.9 |
1003 |
|
(let ((*features* '(x))) |
1004 |
|
(read-from-string "#+CL-TEST::X :good :bad")) |
1005 |
|
:good 19) |
1006 |
|
|
1007 |
|
(def-syntax-test syntax.sharp-plus.10 |
1008 |
|
(let ((*features* nil)) |
1009 |
|
(read-from-string "#+(not x) :good :bad")) |
1010 |
|
:good 16) |
1011 |
|
|
1012 |
|
(def-syntax-test syntax.sharp-plus.11 |
1013 |
|
(let ((*features* '(:x))) |
1014 |
|
(read-from-string "#+(not x) :bad :good")) |
1015 |
|
:good 20) |
1016 |
|
|
1017 |
|
(def-syntax-test syntax.sharp-plus.12 |
1018 |
|
(let ((*features* nil)) |
1019 |
|
(read-from-string "#+(:not :x) :good :bad")) |
1020 |
|
:good 18) |
1021 |
|
|
1022 |
|
(def-syntax-test syntax.sharp-plus.13 |
1023 |
|
(let ((*features* '(:a :x :b))) |
1024 |
|
(read-from-string "#+(and a b) :good :bad")) |
1025 |
|
:good 18) |
1026 |
|
|
1027 |
|
(def-syntax-test syntax.sharp-plus.14 |
1028 |
|
(let ((*features* '(:a :x :b))) |
1029 |
|
(read-from-string "#+(and a c) :bad :good")) |
1030 |
|
:good 22) |
1031 |
|
|
1032 |
|
(def-syntax-test syntax.sharp-plus.15 |
1033 |
|
(let ((*features* '(:a :x :b))) |
1034 |
|
(read-from-string "#+(or c b) :good :bad")) |
1035 |
|
:good 17) |
1036 |
|
|
1037 |
|
(def-syntax-test syntax.sharp-plus.16 |
1038 |
|
(let ((*features* '(:a :x :b))) |
1039 |
|
(read-from-string "#+(or c d) :bad :good")) |
1040 |
|
:good 21) |
1041 |
|
|
1042 |
|
;;; Tests of #| |# |
1043 |
|
|
1044 |
|
(def-syntax-test syntax.sharp-bar.1 |
1045 |
|
(read-from-string "#||#1") |
1046 |
|
1 5) |
1047 |
|
|
1048 |
|
(def-syntax-test syntax.sharp-bar.2 |
1049 |
|
(read-from-string "1#||#2") |
1050 |
|
|1##2| 6) |
1051 |
|
|
1052 |
|
(def-syntax-test syntax.sharp-bar.3 |
1053 |
|
(read-from-string "#| #| |# |#1") |
1054 |
|
1 12) |
1055 |
|
|
1056 |
|
(def-syntax-test syntax.sharp-bar.4 |
1057 |
|
(read-from-string "#| ; |#1") |
1058 |
|
1 8) |
1059 |
|
|
1060 |
|
(def-syntax-test syntax.sharp-bar.5 |
1061 |
|
(read-from-string "#| ( |#1") |
1062 |
|
1 8) |
1063 |
|
|
1064 |
|
(def-syntax-test syntax.sharp-bar.6 |
1065 |
|
(read-from-string "#| # |#1") |
1066 |
|
1 8) |
1067 |
|
|
1068 |
|
(def-syntax-test syntax.sharp-bar.7 |
1069 |
|
(read-from-string "#| .. |#1") |
1070 |
|
1 9) |
1071 |
|
|
1072 |
|
(def-syntax-test syntax.sharp-bar.8 |
1073 |
|
(loop for c across +standard-chars+ |
1074 |
|
for s = (concatenate 'string "\#| " (string c) " |\#1") |
1075 |
|
for vals = (multiple-value-list (read-from-string s)) |
1076 |
|
unless (equal vals '(1 8)) |
1077 |
|
collect (list c s vals)) |
1078 |
|
nil) |
1079 |
|
|
1080 |
|
(def-syntax-test syntax.sharp-bar.9 |
1081 |
|
(loop for i below (min (ash 1 16) char-code-limit) |
1082 |
|
for c = (code-char i) |
1083 |
|
for s = (and c (concatenate 'string "\#| " (string c) " |\#1")) |
1084 |
|
for vals = (and c (multiple-value-list (read-from-string s))) |
1085 |
|
unless (or (not c) (equal vals '(1 8))) |
1086 |
|
collect (list i c s vals)) |
1087 |
|
nil) |
1088 |
|
|
1089 |
|
(def-syntax-test syntax.sharp-bar.10 |
1090 |
|
(loop for i = (random (min (ash 1 24) char-code-limit)) |
1091 |
|
for c = (code-char i) |
1092 |
|
for s = (and c (concatenate 'string "\#| " (string c) " |\#1")) |
1093 |
|
for vals = (and c (multiple-value-list (read-from-string s))) |
1094 |
|
repeat 1000 |
1095 |
|
unless (or (not c) (equal vals '(1 8))) |
1096 |
|
collect (list i c s vals)) |
1097 |
|
nil) |
1098 |
|
|
1099 |
;;;; Various error cases |
;;;; Various error cases |
1100 |
|
|
1120 |
(def-syntax-test syntax.sharp-close-paren.1 |
(def-syntax-test syntax.sharp-close-paren.1 |
1121 |
(signals-error (read-from-string "#)" nil nil) reader-error) |
(signals-error (read-from-string "#)" nil nil) reader-error) |
1122 |
t) |
t) |
1123 |
|
|
1124 |
|
(def-syntax-test syntax.single-escape-eof.1 |
1125 |
|
(signals-error (read-from-string "\\") end-of-file) |
1126 |
|
t) |
1127 |
|
|
1128 |
|
(def-syntax-test syntax.single-escape-eof.2 |
1129 |
|
(signals-error (read-from-string "\\" nil nil) end-of-file) |
1130 |
|
t) |
1131 |
|
|
1132 |
|
(def-syntax-test syntax.multiple-escape-eof.1 |
1133 |
|
(signals-error (read-from-string "|") end-of-file) |
1134 |
|
t) |
1135 |
|
|
1136 |
|
(def-syntax-test syntax.multiple-escape-eof.2 |
1137 |
|
(signals-error (read-from-string "|" nil nil) end-of-file) |
1138 |
|
t) |
1139 |
|
|