示例#1
0
        public void TestTryParseForStringLiteral()
        {
            var f = new TestParseForStringLiteralFixture("", "");

            f.TestForFail("");
            f.TestForFail(" ");
            f.TestForFail("\"");
            f.TestForFail("\"\\\"");
            f.TestForFail("\\");

            f.TestForSuccess("@\"\"", "", 3);
            f.TestForSuccess("@\"blah\"", "blah", 7);

            // Define input strings that should match.
            var validTests = new []
            {
                // test single-substring input
                f.Test("\"\"", ""),                             // empty string
                f.Test("\"blah\"", "blah"),                     // word with no spaces
                f.Test("\" blah\"", " blah"),                   // space preceeding word
                f.Test("\" blah \"", " blah "),                 // spaces flanking word
                f.Test("\"(blah)\"", "(blah)"),                 // word in parentheses
                f.Test("\"\\\"blah\\\"\"", "\"blah\""),         // word in escaped quotes
                f.Test("\"\\n\\\"blah\\\"\"", "\n\"blah\""),    // word and escaped newline in escaped quotes
                f.Test("\"\\\"\\nblah\\\"\"", "\"\nblah\""),    // ...different position
                f.Test("\"\\\"blah\\n\\\"\"", "\"blah\n\""),    // ...different position
                f.Test("\"\\\"blah\\\"\\n\"", "\"blah\"\n"),    // ...different position

                // test single-substrinbg input, containing all possible character literals.
                // https://msdn.microsoft.com/en-us/library/aa691087(v=vs.71).aspx
                f.Test("\"\\\'\\\"\\\\\\0\\a\\b\\f\\\\n\\r\\t\\v\\xf\\x2a\\x02a\\0x002a9\\u002a\\U0000002a\"",
                       "\'\"\\\0\a\b\f\\n\r\t\v\xf\x2a\x02a\0x002a9\u002a\U0000002a"),

                // Test verbatim string with escaped double-quotes (the only possible escaped character).
                // https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
                f.Test("@\"abc 123\"\"\"\"\n\\\\\\n\\r\\t\\a\n\"", "abc 123\"\"\n\\\\\\n\\r\\t\\a\n"),

                // test multiple-substring input
                f.Test("\"\" + \"\"", ""),
                f.Test("\"\" + \"One\"", "One"),
                f.Test("\" \" + \"One\"", " One"),
                f.Test("\"One\" + \" \"", "One "),
                f.Test("\"\" + \"\" + \"\"", ""),
                f.Test("\"\" + \"One\" + \"Two\"", "OneTwo"),
                f.Test("\" \" + \"One\" + \"Two\"", " OneTwo"),
                f.Test("\"One\" + \" \" + \"Two\"", "One Two"),
                f.Test("\"One\" + \"Two\" + \"Three\"", "OneTwoThree"),
            };

            // Test: matchable inputs (without extraneous string data before or after)
            f.PreMatch  = "";
            f.PostMatch = "";
            foreach (var test in validTests)
            {
                f.TestForSuccess(test);
            }

            // Test: matchable inputs (with whitespace before and extraneous text after)
            f.PreMatch  = " \n \n";
            f.PostMatch = " , blah";
            foreach (var test in validTests)
            {
                f.TestForSuccess(test);
            }

            // Test: matchable inputs (with extraneous whitespace before, and "matchable but out-of-reach" string data after)
            f.PreMatch  = "  \n  \n";
            f.PostMatch = " , " + validTests[3].Input[0];
            foreach (var test in validTests)
            {
                f.TestForSuccess(test);
            }
        }
示例#2
0
        public void TestTryParseForStringLiteral()
        {
            var f = new TestParseForStringLiteralFixture("", "");

            f.TestForFail("");
            f.TestForFail(" ");
            f.TestForFail("\"");
            f.TestForFail("\"\\\"");
            f.TestForFail("\\");

            f.TestForSuccess("@\"\"", "", 3);
            f.TestForSuccess("@\"blah\"", "blah", 7);

            // Define input strings that should match.
            var validTests = new []
            {
                // test single-substring input
                f.Test("\"\"",                  ""),            // empty string
                f.Test("\"blah\"",              "blah"),        // word with no spaces
                f.Test("\" blah\"",             " blah"),       // space preceeding word
                f.Test("\" blah \"",            " blah "),      // spaces flanking word 
                f.Test("\"(blah)\"",            "(blah)"),      // word in parentheses
                f.Test("\"\\\"blah\\\"\"",      "\"blah\""),    // word in escaped quotes
                f.Test("\"\\n\\\"blah\\\"\"",   "\n\"blah\""),   // word and escaped newline in escaped quotes
                f.Test("\"\\\"\\nblah\\\"\"",   "\"\nblah\""),   // ...different position
                f.Test("\"\\\"blah\\n\\\"\"",   "\"blah\n\""),   // ...different position
                f.Test("\"\\\"blah\\\"\\n\"",   "\"blah\"\n"),   // ...different position

                // test single-substrinbg input, containing all possible character literals.
                // https://msdn.microsoft.com/en-us/library/aa691087(v=vs.71).aspx
                f.Test("\"\\\'\\\"\\\\\\0\\a\\b\\f\\\\n\\r\\t\\v\\xf\\x2a\\x02a\\0x002a9\\u002a\\U0000002a\"",
                                   "\'\"\\\0\a\b\f\\n\r\t\v\xf\x2a\x02a\0x002a9\u002a\U0000002a"),

                // Test verbatim string with escaped double-quotes (the only possible escaped character).
                // https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
                f.Test("@\"abc 123\"\"\"\"\n\\\\\\n\\r\\t\\a\n\"", "abc 123\"\"\n\\\\\\n\\r\\t\\a\n"),

                // test multiple-substring input
                f.Test("\"\" + \"\"",                   ""),
                f.Test("\"\" + \"One\"",                "One"),
                f.Test("\" \" + \"One\"",               " One"),
                f.Test("\"One\" + \" \"",               "One "),
                f.Test("\"\" + \"\" + \"\"",            ""),
                f.Test("\"\" + \"One\" + \"Two\"",      "OneTwo"),
                f.Test("\" \" + \"One\" + \"Two\"",     " OneTwo"),
                f.Test("\"One\" + \" \" + \"Two\"",     "One Two"),
                f.Test("\"One\" + \"Two\" + \"Three\"", "OneTwoThree"),
            };

            // Test: matchable inputs (without extraneous string data before or after)
            f.PreMatch = "";
            f.PostMatch = "";
            foreach (var test in validTests)
                f.TestForSuccess(test);

            // Test: matchable inputs (with whitespace before and extraneous text after)
            f.PreMatch = " \n \n";
            f.PostMatch = " , blah";
            foreach (var test in validTests)
                f.TestForSuccess(test);

            // Test: matchable inputs (with extraneous whitespace before, and "matchable but out-of-reach" string data after)
            f.PreMatch = "  \n  \n";
            f.PostMatch = " , " + validTests[3].Input[0];
            foreach (var test in validTests)
                f.TestForSuccess(test);
        }