From a97886efb72e40c2a46b44916ae87dab53bfae00 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 16 Apr 2019 17:04:03 -0700 Subject: 5094 Split off a couple of tests so we can name desired behaviors. --- subx/038---literal_strings.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'subx') diff --git a/subx/038---literal_strings.cc b/subx/038---literal_strings.cc index 72534697..5afda221 100644 --- a/subx/038---literal_strings.cc +++ b/subx/038---literal_strings.cc @@ -77,11 +77,11 @@ void add_global_to_data_segment(const string& name, const word& value, segment& void test_instruction_with_string_literal() { parse_instruction_character_by_character( - "a \"abc \\\"def\\nwee\" z\n" // two spaces inside string + "a \"abc def\" z\n" // two spaces inside string ); CHECK_TRACE_CONTENTS( "parse2: word: a\n" - "parse2: word: \"abc \"def\\nwee\"\n" + "parse2: word: \"abc def\"\n" "parse2: word: z\n" ); // no other words @@ -127,6 +127,7 @@ void parse_instruction_character_by_character(const string& line_data, vector
  • > c; if (c == 'n') d << '\n'; else if (c == '"') d << '"'; + else if (c == '\\') d << '\\'; else { raise << "parse_instruction_character_by_character: unknown escape sequence '\\" << c << "'\n" << end(); return; @@ -298,3 +299,25 @@ void test_parse2_string_containing_slashes() { "parse2: word: \"bc/def\" /disp32\n" ); } + +void test_instruction_with_string_literal_with_escaped_quote() { + parse_instruction_character_by_character( + "\"a\\\"b\"\n" // escaped quote inside string + ); + CHECK_TRACE_CONTENTS( + "parse2: word: \"a\"b\"\n" + ); + // no other words + CHECK_TRACE_COUNT("parse2", 1); +} + +void test_instruction_with_string_literal_with_escaped_backslash() { + parse_instruction_character_by_character( + "\"a\\\\b\"\n" // escaped backslash inside string + ); + CHECK_TRACE_CONTENTS( + "parse2: word: \"a\\b\"\n" + ); + // no other words + CHECK_TRACE_COUNT("parse2", 1); +} -- cgit 1.4.1-2-gfad0