-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add anchors to link json artifact (#353)
* Add anchors to link json artifact Refactored `LinkReference` to use a dictionary for better anchor tracking and adjusted anchor validations. Added extensive test coverage, revamped test setup, and improved generator logic for markdown files.``` * rename union creation methods * add license headers * make links on object holding anchors * dotnet format
- Loading branch information
Showing
14 changed files
with
341 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
namespace authoring | ||
|
||
open System.Diagnostics | ||
open System.Text.Json | ||
open DiffPlex.DiffBuilder | ||
open DiffPlex.DiffBuilder.Model | ||
open FsUnit.Xunit | ||
open JetBrains.Annotations | ||
open Xunit.Sdk | ||
|
||
[<AutoOpen>] | ||
module ResultsAssertions = | ||
|
||
let diff expected actual = | ||
let diffLines = InlineDiffBuilder.Diff(expected, actual).Lines | ||
|
||
let mutatedCount = | ||
diffLines | ||
|> Seq.filter (fun l -> | ||
match l.Type with | ||
| ChangeType.Modified -> true | ||
| ChangeType.Inserted -> true | ||
| _ -> false | ||
) | ||
|> Seq.length | ||
|
||
let actualLineLength = actual.Split("\n").Length | ||
match mutatedCount with | ||
| 0 -> "" | ||
| _ when mutatedCount >= actualLineLength -> $"Mutations {mutatedCount} on all {actualLineLength} showing actual: \n\n{actual}" | ||
| _ -> | ||
diffLines | ||
|> Seq.map(fun l -> | ||
match l.Type with | ||
| ChangeType.Deleted -> "- " + l.Text | ||
| ChangeType.Modified -> "+ " + l.Text | ||
| ChangeType.Inserted -> "+ " + l.Text | ||
| _ -> " " + l.Text | ||
) | ||
|> String.concat "\n" | ||
|
||
|
||
[<DebuggerStepThrough>] | ||
let converts file (results: Lazy<GeneratorResults>) = | ||
let results = results.Value | ||
|
||
let result = | ||
results.MarkdownResults | ||
|> Seq.tryFind (fun m -> m.File.RelativePath = file) | ||
|
||
match result with | ||
| None -> | ||
raise (XunitException($"{file} not part of the markdown results")) | ||
| Some result -> result | ||
|
||
[<AutoOpen>] | ||
module JsonAssertions = | ||
|
||
[<DebuggerStepThrough>] | ||
let convertsToJson artifact ([<LanguageInjection("json")>]expected: string) (actual: Lazy<GeneratorResults>) = | ||
let actual = actual.Value | ||
let fs = actual.Context.ReadFileSystem | ||
|
||
let fi = fs.FileInfo.New(artifact) | ||
if not <| fi.Exists then | ||
raise (XunitException($"{artifact} is not part of the output")) | ||
|
||
let actual = fs.File.ReadAllText(fi.FullName) | ||
use actualJson = JsonDocument.Parse(actual); | ||
let actual = JsonSerializer.Serialize(actualJson, JsonSerializerOptions(WriteIndented = true)) | ||
|
||
use expectedJson = JsonDocument.Parse(expected); | ||
let expected = JsonSerializer.Serialize(expectedJson, JsonSerializerOptions(WriteIndented = true)) | ||
|
||
diff expected actual |> should be NullOrEmptyString | ||
|
||
|
Oops, something went wrong.