From e0b3406a8c0fa27345883adb94fd55e1955febd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 30 Jun 2022 00:22:46 +0200 Subject: C-parser add strings. --- tests/test/cpp.scm | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'tests/test') diff --git a/tests/test/cpp.scm b/tests/test/cpp.scm index 8a53ecce..f7b11296 100644 --- a/tests/test/cpp.scm +++ b/tests/test/cpp.scm @@ -13,8 +13,6 @@ ;; So changing the lexer test cases isn't a problem ;; but don't change the parser test cases -;; Strings aren't yet implemented -(test-skip "Strings") ;; __asm__ always has strings as arguments (test-skip "__asm__") ;; not implemented @@ -24,6 +22,10 @@ ;; order of operation is wrong, leading to an incorrect result (test-skip "Cast with operation") +;; A string follewed by a macro (which expands to a string) +;; should be concatenated. This is however not yet implemented +(test-skip "Implicit concatenation of string and macro") + (define run (compose parse-lexeme-tree lex)) (define-syntax let-group @@ -366,7 +368,7 @@ (test-group "Strings" (test-group "Empty string" (let ((form "\"\"")) - (test-equal '(string "") (lex form)) + (test-equal 'string (lex form)) (test-equal #vu8(0) (run form)))) (test-group "Simple string" @@ -384,13 +386,28 @@ (test-group "Implicit concatenation of string and macro" (let ((form "\"a\" MACRO")) - (test-equal '() (lex form)) + (test-equal '((string "a") (variable "MACRO")) (lex form)) (test-equal '() (run form)))) - (test-group "String with escape" - (let ((form (string #\\ #\"))) - (test-equal `(string ,(string #\")) (lex form)) - (test-equal #vu8(34 0) (run form))))) + (test-group "String with only escape" + (let ((form (string #\" #\\ #\" #\"))) + (test-equal `(string "\"") (lex form)) + (test-equal #vu8(34 0) (run form)))) + + (test-group "String with escape at start" + (let ((form (string #\" #\\ #\" #\a #\"))) + (test-equal `(string "\"a") (lex form)) + (test-equal #vu8(34 #x61 0) (run form)))) + + (test-group "String with escape at end" + (let ((form (string #\" #\a #\\ #\" #\"))) + (test-equal `(string "a\"") (lex form)) + (test-equal #vu8(#x61 34 0) (run form)))) + + (test-group "String with escape in middle" + (let ((form (string #\" #\a #\\ #\" #\b #\"))) + (test-equal `(string "a\"b") (lex form)) + (test-equal #vu8(#x61 34 #x62 0) (run form))))) (test-group "__asm__" (let ((form "__asm__(\".globl \" __XSTRING(sym))")) -- cgit v1.2.3