diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-04-16 17:04:03 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-04-16 17:04:03 -0700 |
commit | a97886efb72e40c2a46b44916ae87dab53bfae00 (patch) | |
tree | 37780ec586a523ebb2c700b9f786901713404d4e | |
parent | cb2344a2655e3097394a91168a5f046956d23cb8 (diff) | |
download | mu-a97886efb72e40c2a46b44916ae87dab53bfae00.tar.gz |
5094
Split off a couple of tests so we can name desired behaviors.
-rw-r--r-- | subx/038---literal_strings.cc | 27 |
1 files changed, 25 insertions, 2 deletions
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<li in >> 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); +} |