From 932d28ddc86ae4044f3a6097285bacb48face779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 20 Jul 2022 16:15:47 +0200 Subject: Cleanup in lex2 test. --- tests/test/cpp/lex2.scm | 86 ++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/tests/test/cpp/lex2.scm b/tests/test/cpp/lex2.scm index b7087c3b..af6163e8 100644 --- a/tests/test/cpp/lex2.scm +++ b/tests/test/cpp/lex2.scm @@ -4,64 +4,68 @@ :use-module (ice-9 peg) :use-module (c lex2)) +(define (l s) (lexeme type: 'preprocessing-token body: s)) + +(define (ls . xs) + (map l xs)) (test-equal "Integer literal" - (list (lexeme type: 'preprocessing-token body: '(pp-number "10"))) + (ls '(pp-number "10")) (lex "10")) (test-equal "String literal" - (list (lexeme type: 'preprocessing-token body: '(string-literal "Hello"))) + (ls `(string-literal "Hello")) (lex "\"Hello\"")) (test-equal "Mulitple tokens, including whitespace" (list (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(pp-number "10")) + (l '(pp-number "10")) (lexeme type: 'whitespace body: " ")) (lex " 10 ")) (test-equal "Char literal" - (list (lexeme type: 'preprocessing-token body: '(character-constant "a"))) + (ls `(character-constant (character-prefix) "a")) (lex "'a'")) (test-equal "Comment inside string" - (list (lexeme type: 'preprocessing-token body: '(string-literal "Hel/*lo"))) + (ls `(string-literal "Hel/*lo")) (lex "\"Hel/*lo\"")) (test-equal "#define line" (list - (lexeme type: 'preprocessing-token body: '(punctuator "#")) - (lexeme type: 'preprocessing-token body: '(identifier "define")) + (l '(punctuator "#")) + (l '(identifier "define")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(identifier "f")) - (lexeme type: 'preprocessing-token body: '(punctuator "(")) - (lexeme type: 'preprocessing-token body: '(identifier "x")) - (lexeme type: 'preprocessing-token body: '(punctuator ")")) + (l '(identifier "f")) + (l '(punctuator "(")) + (l '(identifier "x")) + (l '(punctuator ")")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(pp-number "10"))) + (l '(pp-number "10"))) (lex "#define f(x) 10")) (test-equal "Nested parenthesis" (list - (lexeme type: 'preprocessing-token body: '(identifier "f")) - (lexeme type: 'preprocessing-token body: '(punctuator "(")) - (lexeme type: 'preprocessing-token body: '(pp-number "1")) - (lexeme type: 'preprocessing-token body: '(punctuator ",")) + (l '(identifier "f")) + (l '(punctuator "(")) + (l '(pp-number "1")) + (l '(punctuator ",")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(punctuator "(")) - (lexeme type: 'preprocessing-token body: '(pp-number "2")) - (lexeme type: 'preprocessing-token body: '(punctuator ",")) + (l '(punctuator "(")) + (l '(pp-number "2")) + (l '(punctuator ",")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(pp-number "3")) - (lexeme type: 'preprocessing-token body: '(punctuator ")")) - (lexeme type: 'preprocessing-token body: '(punctuator ",")) + (l '(pp-number "3")) + (l '(punctuator ")")) + (l '(punctuator ",")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(pp-number "4")) - (lexeme type: 'preprocessing-token body: '(punctuator ")"))) + (l '(pp-number "4")) + (l '(punctuator ")"))) (lex "f(1, (2, 3), 4)")) @@ -85,36 +89,36 @@ ;; Refer to 6.4 p.1 for the syntax requirement ;; 6.10.9 p. 2 for the sample string (test-equal "each non-white-space character that cannot be one of the above" - (list (lexeme type: 'preprocessing-token body: '(punctuator ".")) - (lexeme type: 'preprocessing-token body: '(punctuator ".")) + (list (l '(punctuator ".")) + (l '(punctuator ".")) (lexeme type: 'other body: "\\") ; <- Interesting part - (lexeme type: 'preprocessing-token body: '(identifier "listing")) - (lexeme type: 'preprocessing-token body: '(punctuator ".")) - (lexeme type: 'preprocessing-token body: '(identifier "dir"))) + (l '(identifier "listing")) + (l '(punctuator ".")) + (l '(identifier "dir"))) (lex "..\\listing.dir")) (test-equal "Propper H-string" - (list (lexeme type: 'preprocessing-token body: '(header-name (h-string "a")))) + (ls '(header-name (h-string "a"))) (lex "")) (test-equal "Unexpected h-string" - (list (lexeme type: 'preprocessing-token body: '(pp-number "1")) + (list (l '(pp-number "1")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(header-name (h-string " 2 "))) + (l '(header-name (h-string " 2 "))) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(pp-number "3"))) + (l '(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")))) + (ls '(header-name (h-string "a\"b"))) (lex "")) (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 ">"))) + (ls '(pp-number "1") + '(string-literal "<") + '(punctuator ">")) (lex "1\"<\">")) (test-equal "H-string, not string" @@ -124,10 +128,10 @@ (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")) + (list (l '(punctuator "#")) + (l '(identifier "include")) (lexeme type: 'whitespace body: " ") - (lexeme type: 'preprocessing-token body: '(string-literal "test"))) + (l '(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 @@ -138,7 +142,7 @@ (test-group "Unicode" (test-equal "In string literals" - (list (lexeme type: 'preprocessing-token body: '(string-literal "åäö"))) + (ls '(string-literal "åäö")) (lex "\"åäö\"")) (test-equal "Outside string literals" -- cgit v1.2.3