Skip to content

Commit

Permalink
test: tags test adaptions
Browse files Browse the repository at this point in the history
- fix tags completion tests
- add tags to document symbol tests
- implement workspace symbol tests (including tags)
  • Loading branch information
TheBlob42 authored and artempyanykh committed Nov 20, 2023
1 parent cb44455 commit dd5b4f5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 11 deletions.
75 changes: 73 additions & 2 deletions Tests/SymbolsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,76 @@ open Xunit

open Ionide.LanguageServerProtocol.Types

open Marksman.Misc
open Marksman.Helpers
open Marksman.Workspace

module WorkspaceSymbol =
let doc1 =
FakeDoc.Mk(path = "doc1.md", contentLines = [| "# A"; "#tag1" |])

let doc2 =
FakeDoc.Mk(path = "doc2.md", contentLines = [| "# B"; "#tag1 #tag2" |])

let folder = FakeFolder.Mk [ doc1; doc2 ]
let workspace = Workspace.ofFolders None [ folder ]

[<Fact>]
let symbols_noQuery =
let symbols = Symbols.workspaceSymbols "" workspace

Assert.Equal(
[ { Name = "H1: A"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc1); Range = Range.Mk(0, 0, 0, 3) } }
{ Name = "Tag: tag1"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc1); Range = Range.Mk(1, 0, 1, 5) } }
{ Name = "H1: B"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc2); Range = Range.Mk(0, 0, 0, 3) } }
{ Name = "Tag: tag1"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc2); Range = Range.Mk(1, 0, 1, 5) } }
{ Name = "Tag: tag2"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc2); Range = Range.Mk(1, 6, 1, 11) } } ],
symbols
)

[<Fact>]
let symbols_withQuery () =
let symbols = Symbols.workspaceSymbols "Tag:" workspace

Assert.Equal(
[ { Name = "Tag: tag1"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc1); Range = Range.Mk(1, 0, 1, 5) } }
{ Name = "Tag: tag1"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc2); Range = Range.Mk(1, 0, 1, 5) } }
{ Name = "Tag: tag2"
Kind = SymbolKind.String
ContainerName = None
Location = { Uri = (Doc.uri doc2); Range = Range.Mk(1, 6, 1, 11) } } ],
symbols
)

module DocSymbols =
let fakeDoc =
FakeDoc.Mk(
[| "# E" //
"## D"
"#t1"
"### B"
"#t2"
"## C"
"# A" |]
)
Expand All @@ -26,7 +88,16 @@ module DocSymbols =
| _ -> failwith "Unexpected symbol type"
|> Array.map (fun x -> x.Name)

Assert.Equal<string>([| "H1: E"; "H2: D"; "H3: B"; "H2: C"; "H1: A" |], symNames)
Assert.Equal<string>(
[| "H1: E"
"H2: D"
"H3: B"
"H2: C"
"H1: A"
"Tag: t1"
"Tag: t2" |],
symNames
)

[<Fact>]
let order_Hierarchy () =
Expand All @@ -45,4 +116,4 @@ module DocSymbols =

syms |> Array.iter collect

Assert.Equal<string>([| "E"; "D"; "B"; "C"; "A" |], names)
Assert.Equal<string>([| "E"; "D"; "t1"; "B"; "t2"; "C"; "A" |], names)
18 changes: 9 additions & 9 deletions Tests/_snapshots/Tags.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"tagOpening": {
"AutoGenerated": [
"(1,16)-(1,16): tag / ",
"(1,16)-(1,16): anotherTag / ",
"(1,16)-(1,16): ta / ",
"(1,16)-(1,16): somethingElse / ",
"(1,16)-(1,16): otherDocTag / "
"(1,16)-(1,16): tag / <no-filter>",
"(1,16)-(1,16): anotherTag / <no-filter>",
"(1,16)-(1,16): ta / <no-filter>",
"(1,16)-(1,16): somethingElse / <no-filter>",
"(1,16)-(1,16): otherDocTag / <no-filter>"
]
},
"tagWithName": {
"AutoGenerated": [
"(2,13)-(2,15): tag / ta",
"(2,13)-(2,15): anotherTag / ta",
"(2,13)-(2,15): otherDocTag / ta"
"(2,13)-(2,15): tag / <no-filter>",
"(2,13)-(2,15): anotherTag / <no-filter>",
"(2,13)-(2,15): otherDocTag / <no-filter>"
]
}
}
}

0 comments on commit dd5b4f5

Please sign in to comment.