Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 1-based column numbers in tests #7141

Merged
merged 2 commits into from
Jul 11, 2019
Merged
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
18 changes: 12 additions & 6 deletions tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ module CompilerAssert =
Assert.IsEmpty(typeCheckResults.Errors, sprintf "Type Check errors: %A" typeCheckResults.Errors)


let TypeCheckSingleError (source: string) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) =

let TypeCheckWithErrors (source: string) expectedTypeErrors =
lock gate <| fun () ->
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions) |> Async.RunSynchronously

Expand All @@ -125,15 +126,20 @@ module CompilerAssert =
typeCheckResults.Errors
|> Array.distinctBy (fun e -> e.Severity, e.ErrorNumber, e.StartLineAlternate, e.StartColumn, e.EndLineAlternate, e.EndColumn, e.Message)

Assert.AreEqual(1, errors.Length, sprintf "Expected one type check error: %A" typeCheckResults.Errors)
errors
|> Array.iter (fun info ->
Assert.AreEqual(FSharpErrorSeverity.Error, info.Severity)
Assert.AreEqual(Array.length expectedTypeErrors, errors.Length, sprintf "Type check errors: %A" typeCheckResults.Errors)

Array.zip errors expectedTypeErrors
|> Array.iter (fun (info, expectedError) ->
let (expectedServerity: FSharpErrorSeverity, expectedErrorNumber: int, expectedErrorRange: int * int * int * int, expectedErrorMsg: string) = expectedError
Assert.AreEqual(expectedServerity, info.Severity)
Assert.AreEqual(expectedErrorNumber, info.ErrorNumber, "expectedErrorNumber")
Assert.AreEqual(expectedErrorRange, (info.StartLineAlternate, info.StartColumn, info.EndLineAlternate, info.EndColumn), "expectedErrorRange")
Assert.AreEqual(expectedErrorRange, (info.StartLineAlternate, info.StartColumn + 1, info.EndLineAlternate, info.EndColumn + 1), "expectedErrorRange")
Assert.AreEqual(expectedErrorMsg, info.Message, "expectedErrorMsg")
)

let TypeCheckSingleError (source: string) (expectedServerity: FSharpErrorSeverity) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) =
TypeCheckWithErrors (source: string) [| expectedServerity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |]

let CompileExe (source: string) =
compile true source (fun (errors, _) ->
if errors.Length > 0 then
Expand Down
9 changes: 6 additions & 3 deletions tests/fsharp/Compiler/Language/AnonRecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module AnonRecordsTests =
Expand Down Expand Up @@ -30,8 +31,9 @@ let sAnon = StructClass<struct {| S: int |}>()
type RefClass<'a when 'a : not struct>() = class end
let rAnon = RefClass<struct {| R: int |}>()
"""
FSharpErrorSeverity.Error
1
(3, 12, 3, 41)
(3, 13, 3, 42)
"A generic construct requires that the type 'struct {|R : int|}' have reference semantics, but it does not, i.e. it is a struct"

[<Test>]
Expand All @@ -40,7 +42,8 @@ let rAnon = RefClass<struct {| R: int |}>()
"""
type StructClass<'a when 'a : struct>() = class end
let sAnon = StructClass<{| S: int |}>()
"""
"""
FSharpErrorSeverity.Error
1
(3, 12, 3, 37)
(3, 13, 3, 38)
"A generic construct requires that the type '{|S : int|}' is a CLI or F# struct type"