/// <summary> /// Runs the analyzer on the testSouce and expects it to succeed with the given formatted text. /// </summary> public void TestSuccess( string testSource, string expectedResult = null, string[] extraSources = null, Dictionary <string, string> modules = null, string[] options = null, bool fix = true, bool preserveTrivia = false) { TestHelper( testSource, extraSources, modules, options, fix, (success, logger, sourceFile) => { var errors = string.Join(Environment.NewLine, logger.CapturedDiagnostics.Select(d => d.Message)); Assert.True(success, "Expect to have successful run. Encountered:\r\n" + errors); Assert.False(logger.HasErrors, "Expect to have no errors. Encountered:\r\n" + errors); var writer = new ScriptWriter(); var visitor = new DScriptPrettyPrintVisitor(writer, attemptToPreserveNewlinesForListMembers: true); if (options != null && options.Contains("/s+")) { visitor.SpecialAddIfFormatting = true; } sourceFile.Cast <IVisitableNode>().Accept(visitor); var actualText = writer.ToString(); Assert.Equal(expectedResult ?? testSource, actualText); }, preserveTrivia); }
/// <summary> /// Runs DScript pretty-printer on given <paramref name="node"/> to return its formatted string representation. /// </summary> public static string GetFormattedText(INode node) { Contract.Requires(node != null); var scriptWriter = new ScriptWriter(); var visitor = new DScriptPrettyPrintVisitor(scriptWriter, false); node.Cast <IVisitableNode>().Accept(visitor); return(scriptWriter.ToString()); }
public void Bug1033268_NumberInPath() { var content = @"export namespace Onecore.Enduser.Windowsupdate.Local.Test.Client.Testdata.Scancabs { const o = d`${objRoot}\onecore\enduser\windowsupdate\local\test\client\testdata\scancabs\${buildAlt}`; export const pass0 = LegacySdk.build({ consumes: [ f`content\downloadtest\1461e379-0835-4683-b852-438ab9290577.xml`, ], produces: [], }); } ".ToCharArray(); var parser = new Parser(); var sourceFile = parser.ParseSourceFileContent( "fake.dsc", TextSource.FromCharArray(content, content.Length), new TypeScript.Net.DScript.ParsingOptions( namespacesAreAutomaticallyExported: true, generateWithQualifierFunctionForEveryNamespace: false, preserveTrivia: true, allowBackslashesInPathInterpolation: true, useSpecPublicFacadeAndAstWhenAvailable: false, escapeIdentifiers: true, convertPathLikeLiteralsAtParseTime: false)); Assert.Equal(0, sourceFile.ParseDiagnostics.Count); var binder = new Binder(); binder.BindSourceFile(sourceFile, new CompilerOptions()); Assert.Equal(0, sourceFile.BindDiagnostics.Count); var scriptWriter = new ScriptWriter(); var prettyPrintVisitor = new DScriptPrettyPrintVisitor(scriptWriter, attemptToPreserveNewlinesForListMembers: false); sourceFile.Cast <IVisitableNode>().Accept(prettyPrintVisitor); }