Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions tests/FSharp.Compiler.ComponentTests/CompilerDirectives/Line.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open FSharp.Compiler.Text
open FSharp.Compiler.UnicodeLexing
open FSharp.Test.Compiler
open System.IO
open System.Threading.Tasks

module Line =

Expand All @@ -25,7 +26,7 @@ module Line =
LangVersionText = langVersion
ApplyLineDirectives = true
}
checker.ParseFile(sourceFileName, SourceText.ofString source, parsingOptions) |> Async.RunSynchronously
checker.ParseFile(sourceFileName, SourceText.ofString source, parsingOptions)


[<Literal>]
Expand Down Expand Up @@ -55,21 +56,23 @@ printfn ""
[<InlineData(1, case1, "xyz1.fs:(1,0--3,1)")>]
[<InlineData(2, case2, "Line2.fs:(2,0--5,1)")>]
[<InlineData(3, case3, "Line3.fs:(2,0--4,1)")>]
let ``check expr range interacting with line directive`` (case, source, expectedRange) =
let parseResults = parse source $"Line{case}.fs"
if parseResults.ParseHadErrors then failwith "unexpected: parse error"
let exprRange =
match parseResults.ParseTree with
| ParsedInput.ImplFile(ParsedImplFileInput(contents = contents)) ->
let (SynModuleOrNamespace(decls = decls)) = List.exactlyOne contents
match List.exactlyOne decls with
| SynModuleDecl.Expr(_, range) ->
let range = range.ApplyLineDirectives()
$"{range.FileName}:{range}"
| _ -> failwith $"unexpected: not an expr"
| ParsedInput.SigFile _ -> failwith "unexpected: sig file"
if exprRange <> expectedRange then
failwith $"case{case}: expected: {expectedRange}, found {exprRange}"
let ``check expr range interacting with line directive`` (case, source, expectedRange) : Task =
task {
let! parseResults = parse source $"Line{case}.fs"
if parseResults.ParseHadErrors then failwith "unexpected: parse error"
let exprRange =
match parseResults.ParseTree with
| ParsedInput.ImplFile(ParsedImplFileInput(contents = contents)) ->
let (SynModuleOrNamespace(decls = decls)) = List.exactlyOne contents
match List.exactlyOne decls with
| SynModuleDecl.Expr(_, range) ->
let range = range.ApplyLineDirectives()
$"{range.FileName}:{range}"
| _ -> failwith $"unexpected: not an expr"
| ParsedInput.SigFile _ -> failwith "unexpected: sig file"
if exprRange <> expectedRange then
failwith $"case{case}: expected: {expectedRange}, found {exprRange}"
}


[<Fact>]
Expand Down
Loading
Loading