aboutsummaryrefslogtreecommitdiff
path: root/tests/test/cpp/lex2.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-14 23:44:03 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-14 23:44:03 +0200
commit64375c16c8316b8381ad59fa3538ad84732d90b7 (patch)
treecec344cb9306f1353ff0c4a4daaf7a81506eef5a /tests/test/cpp/lex2.scm
parentAdd C LALR parser. (diff)
downloadcalp-64375c16c8316b8381ad59fa3538ad84732d90b7.tar.gz
calp-64375c16c8316b8381ad59fa3538ad84732d90b7.tar.xz
work
Diffstat (limited to 'tests/test/cpp/lex2.scm')
-rw-r--r--tests/test/cpp/lex2.scm54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test/cpp/lex2.scm b/tests/test/cpp/lex2.scm
index 47bb4a16..b7087c3b 100644
--- a/tests/test/cpp/lex2.scm
+++ b/tests/test/cpp/lex2.scm
@@ -92,3 +92,57 @@
(lexeme type: 'preprocessing-token body: '(punctuator "."))
(lexeme type: 'preprocessing-token body: '(identifier "dir")))
(lex "..\\listing.dir"))
+
+
+(test-equal "Propper H-string"
+ (list (lexeme type: 'preprocessing-token body: '(header-name (h-string "a"))))
+ (lex "<a>"))
+
+(test-equal "Unexpected h-string"
+ (list (lexeme type: 'preprocessing-token body: '(pp-number "1"))
+ (lexeme type: 'whitespace body: " ")
+ (lexeme type: 'preprocessing-token body: '(header-name (h-string " 2 ")))
+ (lexeme type: 'whitespace body: " ")
+ (lexeme type: 'preprocessing-token body: '(pp-number "3")))
+ (lex "1 < 2 > 3"))
+
+(test-equal "Quotation mark inside h-string"
+ (list (lexeme type: 'preprocessing-token body: '(header-name (h-string "a\"b"))))
+ (lex "<a\"b>"))
+
+(test-equal "Interaction of h-strings and regular strings"
+ (test-equal "Less than string, not h-string"
+ (list (lexeme type: 'preprocessing-token body: '(pp-number "1"))
+ (lexeme type: 'preprocessing-token body: '(string-literal "<"))
+ (lexeme type: 'preprocessing-token body: '(punctuator ">")))
+ (lex "1\"<\">"))
+
+ (test-equal "H-string, not string"
+ (list (lexeme type: 'preprocessing-token body: '(pp-number "1"))
+ (lexeme type: 'preprocessing-token body: '(header-name (h-string "\"")))
+ (lexeme type: 'other body: "\""))
+ (lex "1<\">\"")))
+
+(test-equal "Q-strings are lexed as regular strings"
+ (list (lexeme type: 'preprocessing-token body: '(punctuator "#"))
+ (lexeme type: 'preprocessing-token body: '(identifier "include"))
+ (lexeme type: 'whitespace body: " ")
+ (lexeme type: 'preprocessing-token body: '(string-literal "test")))
+ ;; # include here, since generated tokens could possible depend on that context,
+ ;; and the reason regular strings are returned is since the lexer doesn't check
+ ;; that context
+ (lex "#include \"test\"")
+ )
+
+
+
+(test-group "Unicode"
+ (test-equal "In string literals"
+ (list (lexeme type: 'preprocessing-token body: '(string-literal "åäö")))
+ (lex "\"åäö\""))
+
+ (test-equal "Outside string literals"
+ (list (lexeme type: 'other body: "å")
+ (lexeme type: 'other body: "ä")
+ (lexeme type: 'other body: "ö"))
+ (lex "åäö")))