From ccca13f8eadef31f2df873cb505ebca98501c45a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 8 Sep 2015 16:42:24 +0200 Subject: Initial take on double quote support Currently, $(foo)-style variable expansion is not supported. --- tests/lexer/driver.cxx | 24 +++++++++++++++++++++++- tests/quote/buildfile | 18 ++++++++++++++++++ tests/quote/test.out | 11 +++++++++++ tests/quote/test.sh | 3 +++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/quote/buildfile create mode 100644 tests/quote/test.out create mode 100755 tests/quote/test.sh (limited to 'tests') diff --git a/tests/lexer/driver.cxx b/tests/lexer/driver.cxx index fb5efc3..e3543da 100644 --- a/tests/lexer/driver.cxx +++ b/tests/lexer/driver.cxx @@ -63,7 +63,7 @@ main () assert (lex (" foo\\") == tokens ({""})); - // Quoting. + // Quoting ''. // assert (lex ("''") == tokens ({"", ""})); assert (lex ("'foo'") == tokens ({"foo", ""})); @@ -79,6 +79,28 @@ main () assert (lex ("'foo bar") == tokens ({""})); + // Quoting "". + // + assert (lex ("\"\"") == tokens ({"", ""})); + assert (lex ("\"foo\"") == tokens ({"foo", ""})); + assert (lex ("\"foo bar\"") == tokens ({"foo bar", ""})); + assert (lex ("\"foo \"bar") == tokens ({"foo bar", ""})); + assert (lex ("foo\" bar\"") == tokens ({"foo bar", ""})); + assert (lex ("\"foo \"\"bar\"") == tokens ({"foo bar", ""})); + assert (lex ("foo\" \"bar") == tokens ({"foo bar", ""})); + assert (lex ("\"foo\nbar\"") == tokens ({"foo\nbar", ""})); + assert (lex ("\"#:{}()=+\n\"") == tokens ({"#:{}()=+\n", ""})); + assert (lex ("\"'\"") == tokens ({"'", ""})); + assert (lex ("\"\\\"") == tokens ({"\\", ""})); + + assert (lex ("\"$\"") == tokens ({"", "$", "", ""})); + assert (lex ("\"foo$bar\"") == tokens ({"foo", "$", "bar", ""})); + assert (lex ("foo\"$\"bar") == tokens ({"foo", "$", "bar", ""})); + assert (lex ("f\"oo$ba\"r") == tokens ({"foo", "$", "bar", ""})); + + assert (lex ("\"foo bar") == tokens ({""})); + assert (lex ("\"foo $bar") == tokens ({"foo ", "$", ""})); + // Combinations. // assert (lex ("foo: bar") == tokens ({"foo", ":", "bar", ""})); diff --git a/tests/quote/buildfile b/tests/quote/buildfile new file mode 100644 index 0000000..931bc36 --- /dev/null +++ b/tests/quote/buildfile @@ -0,0 +1,18 @@ +print "foo bar" +print "foo +bar" + +foo = "fo o" +bar = " bar " + +print "$foo" +print "$bar" +print "$foo $bar" +print "$foo$bar" + +print "[ $foo ]" +print "[ $bar ]" +print "[ $foo $bar ]" +print "[ $foo/$bar ]" + +./: diff --git a/tests/quote/test.out b/tests/quote/test.out new file mode 100644 index 0000000..802f28f --- /dev/null +++ b/tests/quote/test.out @@ -0,0 +1,11 @@ +foo bar +foo +bar +fo o + bar +fo o bar +fo o bar +[ fo o ] +[ bar ] +[ fo o bar ] +[ fo o/ bar ] diff --git a/tests/quote/test.sh b/tests/quote/test.sh new file mode 100755 index 0000000..145ea6b --- /dev/null +++ b/tests/quote/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +valgrind -q b -q | diff test.out - -- cgit v1.1