From 39a878d1130bd33d7d1b1380617747187e01fb73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 23 Jul 2022 21:42:19 +0200 Subject: Only parse h-strings where applicable. --- tests/test/cpp/lex2.scm | 23 +++++++++++++++++++++-- tests/test/cpp/preprocessor2.scm | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test/cpp/lex2.scm b/tests/test/cpp/lex2.scm index 54bc0aff..e30aac31 100644 --- a/tests/test/cpp/lex2.scm +++ b/tests/test/cpp/lex2.scm @@ -9,6 +9,9 @@ (define (ls . xs) (map l xs)) +;; See comment on h-string-compound in (c lex2) +(test-expect-fail "H-string looking as argument to macro") + (test-equal "Integer literal" (ls '(pp-number "10")) (lex "10")) @@ -108,17 +111,33 @@ (test-equal "Propper H-string" (list (l '(punctuator "#")) (l '(identifier "include")) - (lexeme type: 'whitespace body: " ") + ;; (lexeme type: 'whitespace body: " ") (l '(h-string "a"))) (lex "#include ")) - (test-equal "Not a H string" (ls '(punctuator "<") '(identifier "a") '(punctuator ">")) (lex "")) + ;; Assume that s is defined as + ;; #define s(x) #x + ;; then the following expression would expand to + ;; "#include" + (test-equal "H-string looking as argument to macro" + (ls '(identifier "s") + '(punctuator "(") + '(punctuator "#") + '(identifier "include") + '(punctuator "<") + '(identifier "a") + '(punctuator ">") + '(punctuator ")")) + (lex "s(#include)")) + + ;; The standard says this case is undefined + ;; 6.4.7 p. 3 (test-equal "Quotation mark inside h-string" (ls '(punctuator "#") '(identifier "include") diff --git a/tests/test/cpp/preprocessor2.scm b/tests/test/cpp/preprocessor2.scm index fd18ddce..be5ba94c 100644 --- a/tests/test/cpp/preprocessor2.scm +++ b/tests/test/cpp/preprocessor2.scm @@ -591,7 +591,7 @@ (test-equal "H-string" "/usr/include/stdio.h" (resolve-header (make-environment) - (lex ""))) + (cddr (lex "#include ")))) (test-equal "Q-string" "/usr/include/stdio.h" (resolve-header (make-environment) -- cgit v1.2.3