public void Should_AcceptABoolean() { var model = new BooleanNumberString(true); var result = Fixture.SerializeObject(model); result.Should().Be("true"); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <BooleanNumberString>("true"); deresult.ShouldBeEquivalentTo(model); }
public void Should_AcceptAString() { var model = new BooleanNumberString("abc"); var result = Fixture.SerializeObject(model); result.Should().Be("\"abc\""); var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <BooleanNumberString>("\"abc\""); deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality()); }
public void Should_BeNull() { var model = new BooleanNumberString(); var result = Fixture.SerializeObject(model); result.Should().Be("null"); var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <BooleanNumberString>("null"); deresult.Should().BeEquivalentTo(model); }
public void Should_AcceptAString() { var model = new BooleanNumberString("abc"); var result = Fixture.SerializeObject(model); result.Should().Be("\"abc\""); var deresult = JsonConvert.DeserializeObject <BooleanNumberString>("\"abc\""); deresult.ShouldBeEquivalentTo(model); }
public async override Task <FormattingResult> ExecuteAsync(FormattingContext context, FormattingResult result, CancellationToken cancellationToken) { if (context.IsFormatOnType || result.Kind != RazorLanguageKind.Razor) { // We don't want to handle OnTypeFormatting here. return(result); } // Apply previous edits if any. var originalText = context.SourceText; var changedText = originalText; var changedContext = context; if (result.Edits.Length > 0) { var changes = result.Edits.Select(e => e.AsTextChange(originalText)).ToArray(); changedText = changedText.WithChanges(changes); changedContext = await context.WithTextAsync(changedText); } cancellationToken.ThrowIfCancellationRequested(); // Apply original C# edits var csharpEdits = await FormatCSharpAsync(changedContext, cancellationToken); if (csharpEdits.Count > 0) { var csharpChanges = csharpEdits.Select(c => c.AsTextChange(changedText)); changedText = changedText.WithChanges(csharpChanges); changedContext = await changedContext.WithTextAsync(changedText); } cancellationToken.ThrowIfCancellationRequested(); var indentationChanges = await AdjustIndentationAsync(changedContext, cancellationToken); if (indentationChanges.Count > 0) { // Apply the edits that modify indentation. changedText = changedText.WithChanges(indentationChanges); } // Allow benchmarks to specify a different diff algorithm if (!context.Options.TryGetValue("UseSourceTextDiffer", out var useSourceTextDiffer)) { useSourceTextDiffer = new BooleanNumberString(false); } var finalChanges = useSourceTextDiffer.Bool ? SourceTextDiffer.GetMinimalTextChanges(originalText, changedText, lineDiffOnly: false) : changedText.GetTextChanges(originalText); var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray(); return(new FormattingResult(finalEdits)); }
public async override Task <FormattingResult> ExecuteAsync(FormattingContext context, FormattingResult result, CancellationToken cancellationToken) { if (context.IsFormatOnType) { // We don't want to handle OnTypeFormatting here. return(result); } var originalText = context.SourceText; var htmlEdits = await HtmlFormatter.FormatAsync(context, cancellationToken); // Allow benchmarks to specify a different diff algorithm if (!context.Options.TryGetValue("UseSourceTextDiffer", out var useSourceTextDiffer)) { useSourceTextDiffer = new BooleanNumberString(false); } var normalizedEdits = htmlEdits; if (useSourceTextDiffer.Bool) { normalizedEdits = NormalizeTextEdits(originalText, htmlEdits); } var mappedEdits = RemapTextEdits(context.CodeDocument, normalizedEdits, RazorLanguageKind.Html); var changes = mappedEdits.Select(e => e.AsTextChange(originalText)); var changedText = originalText; var changedContext = context; if (changes.Any()) { changedText = originalText.WithChanges(changes); // Create a new formatting context for the changed razor document. changedContext = await context.WithTextAsync(changedText); } var indentationChanges = AdjustRazorIndentation(changedContext); if (indentationChanges.Count > 0) { // Apply the edits that adjust indentation. changedText = changedText.WithChanges(indentationChanges); } var finalChanges = useSourceTextDiffer.Bool ? SourceTextDiffer.GetMinimalTextChanges(originalText, changedText, lineDiffOnly: false) : changedText.GetTextChanges(originalText); var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray(); return(new FormattingResult(finalEdits)); }
public async override Task <FormattingResult> ExecuteAsync(FormattingContext context, FormattingResult result, CancellationToken cancellationToken) { if (context.IsFormatOnType) { // We don't want to handle OnTypeFormatting here. return(result); } // Apply previous edits if any. var originalText = context.SourceText; var changedText = originalText; var changedContext = context; if (result.Edits.Length > 0) { var changes = result.Edits.Select(e => e.AsTextChange(originalText)).ToArray(); changedText = changedText.WithChanges(changes); changedContext = await context.WithTextAsync(changedText); cancellationToken.ThrowIfCancellationRequested(); } // Format the razor bits of the file var syntaxTree = changedContext.CodeDocument.GetSyntaxTree(); var edits = FormatRazor(changedContext, syntaxTree); // Compute the final combined set of edits var formattingChanges = edits.Select(e => e.AsTextChange(changedText)); changedText = changedText.WithChanges(formattingChanges); // Allow benchmarks to specify a different diff algorithm if (!context.Options.TryGetValue("UseSourceTextDiffer", out var useSourceTextDiffer)) { useSourceTextDiffer = new BooleanNumberString(false); } var finalChanges = useSourceTextDiffer.Bool ? SourceTextDiffer.GetMinimalTextChanges(originalText, changedText, lineDiffOnly: false) : changedText.GetTextChanges(originalText); var finalEdits = finalChanges.Select(f => f.AsTextEdit(originalText)).ToArray(); return(new FormattingResult(finalEdits)); }