public string GenerateTests( string val, RegexOptions options, bool runSubTreeTests, string testName, bool allowIndexOutOfRange, bool allowNullReference, bool allowOutOfMemory) { // Actually call into our regex APIs to produce figure out the tree produced. // Then spit out a test that does the same, encoding the tree as the expected var builder = new StringBuilder(); builder.AppendLine("[Fact]"); builder.AppendLine("public void " + testName + "()"); builder.AppendLine("{"); builder.Append(@" Test("); var escaped = val.Replace("\"", "\"\""); var quoted = "" + '@' + '"' + escaped + '"'; builder.Append(quoted); var token = GetStringToken(val); var allChars = _service.TryConvertToVirtualChars(token); var tree = RegexParser.TryParse(allChars, options); var actual = TreeToText(token.SyntaxTree.GetText(), tree).Replace("\"", "\"\""); builder.Append(", " + '@' + '"'); builder.Append(actual); builder.Append('"'); builder.Append(", RegexOptions." + options.ToString()); if (!runSubTreeTests) { builder.Append(", runSubTreeTests: false"); } if (allowIndexOutOfRange) { builder.Append(", allowIndexOutOfRange: true"); } if (allowNullReference) { builder.Append(", allowNullReference: true"); } if (allowOutOfMemory) { builder.Append(", allowOutOfMemory: true"); } builder.AppendLine(");"); builder.AppendLine("}"); return(builder.ToString()); }
private (SyntaxToken, RegexTree, VirtualCharSequence) JustParseTree( string stringText, RegexOptions options, bool conversionFailureOk) { var token = GetStringToken(stringText); var allChars = _service.TryConvertToVirtualChars(token); if (allChars.IsDefault) { Assert.True(conversionFailureOk, "Failed to convert text to token."); return(token, null, allChars); } var tree = RegexParser.TryParse(allChars, options); return(token, tree, allChars); }