summaryrefslogtreecommitdiffstats
path: root/src/parsers_test.cc
diff options
context:
space:
mode:
authorEvan Jones <ej@evanjones.ca>2012-01-05 13:28:54 (GMT)
committerEvan Jones <ej@evanjones.ca>2012-01-05 15:12:41 (GMT)
commit831775c7ecb5f4b9548a55a6f603e057fad3fea2 (patch)
tree94275311078d438c8604c42a78516c52b7e3201c /src/parsers_test.cc
parent4b019b3cebf40ca9b1b95741f6336b843a9dad55 (diff)
downloadNinja-831775c7ecb5f4b9548a55a6f603e057fad3fea2.zip
Ninja-831775c7ecb5f4b9548a55a6f603e057fad3fea2.tar.gz
Ninja-831775c7ecb5f4b9548a55a6f603e057fad3fea2.tar.bz2
Lexer: include leading spaces in the newline token.
This means that indented blank lines are skipped without causing errors.
Diffstat (limited to 'src/parsers_test.cc')
-rw-r--r--src/parsers_test.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/parsers_test.cc b/src/parsers_test.cc
index 356b880..f3ac517 100644
--- a/src/parsers_test.cc
+++ b/src/parsers_test.cc
@@ -82,6 +82,21 @@ TEST_F(ParserTest, IgnoreIndentedComments) {
EXPECT_FALSE(rule->generator());
}
+TEST_F(ParserTest, IgnoreIndentedBlankLines) {
+ // the indented blanks used to cause parse errors
+ ASSERT_NO_FATAL_FAILURE(AssertParse(
+" \n"
+"rule cat\n"
+" command = cat $in > $out\n"
+" \n"
+"build result: cat in_1.cc in-2.O\n"
+" \n"
+"variable=1\n"));
+
+ // the variable must be in the top level environment
+ EXPECT_EQ("1", state.bindings_.LookupVariable("variable"));
+}
+
TEST_F(ParserTest, Variables) {
ASSERT_NO_FATAL_FAILURE(AssertParse(
"l = one-letter-test\n"
@@ -466,6 +481,19 @@ TEST_F(ParserTest, Errors) {
// as we see them, not after we've read them all!
EXPECT_EQ("input:4: empty path\n", err);
}
+
+ {
+ State state;
+ ManifestParser parser(&state, NULL);
+ string err;
+ // the indented blank line must terminate the rule
+ // this also verifies that "unexpected (token)" errors are correct
+ EXPECT_FALSE(parser.ParseTest("rule r\n"
+ " command = r\n"
+ " \n"
+ " generator = 1\n", &err));
+ EXPECT_EQ("input:4: unexpected indent\n", err);
+ }
}
TEST_F(ParserTest, MissingInput) {