From ece82982d2b461801e451f92b12e994deb6df391 Mon Sep 17 00:00:00 2001 From: Robin Neatherway Date: Sun, 31 May 2015 18:44:47 +0100 Subject: [PATCH] Adjust for 1-based column indexing Add unit test project to check parsing functionality is correct --- .gitignore | 1 + FSharp.AutoComplete.sln | 34 +++---- .../FSharp.AutoComplete.fsproj | 8 +- FSharp.AutoComplete/Program.fs | 7 +- .../CompletionFilterRunner.fsx | 6 +- .../integration/ErrorTests/ErrorsRunner.fsx | 4 +- .../ErrorTestsJson/ErrorsRunner.fsx | 4 +- .../FindDeclarations/FindDeclRunner.fsx | 10 +- .../integration/MultiProj/MultiProjRunner.fsx | 32 +++---- .../OutOfRange/OutOfRangeRunner.fsx | 6 +- .../test/integration/RawIdTest/Runner.fsx | 12 +-- .../CompleteNoSuchFileRunner.fsx | 2 +- .../CompleteWithoutProjectRunner.fsx | 4 +- .../SymOpActivePatTooltips/Runner.fsx | 8 +- .../test/integration/Test1/Test1Runner.fsx | 19 ++-- .../integration/Test1Json/Test1JsonRunner.fsx | 22 ++--- .../FSharp.CompilerBinding.Tests.fsproj | 92 +++++++++++++++++++ FSharp.CompilerBinding.Tests/Tests.fs | 36 ++++++++ FSharp.CompilerBinding.Tests/paket.references | 2 + .../FSharp.CompilerBinding.fsproj | 2 +- FSharp.CompilerBinding/LanguageService.fs | 22 ++--- FSharp.CompilerBinding/Parser.fs | 4 +- build.fsx | 17 +++- paket.dependencies | 4 +- paket.lock | 4 +- 25 files changed, 250 insertions(+), 112 deletions(-) mode change 100644 => 100755 FSharp.AutoComplete/test/integration/Test1/Test1Runner.fsx create mode 100644 FSharp.CompilerBinding.Tests/FSharp.CompilerBinding.Tests.fsproj create mode 100644 FSharp.CompilerBinding.Tests/Tests.fs create mode 100644 FSharp.CompilerBinding.Tests/paket.references diff --git a/.gitignore b/.gitignore index 57c00c713..41b438284 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,6 @@ FSharp.AutoComplete/test/unit/build packages .paket/paket.exe +TestResults.xml .DS_Store diff --git a/FSharp.AutoComplete.sln b/FSharp.AutoComplete.sln index 3b095224d..74ad1bb10 100644 --- a/FSharp.AutoComplete.sln +++ b/FSharp.AutoComplete.sln @@ -12,43 +12,31 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.CompilerBinding", "F EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.AutoComplete", "FSharp.AutoComplete\FSharp.AutoComplete.fsproj", "{B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.CompilerBinding.Tests", "FSharp.CompilerBinding.Tests\FSharp.CompilerBinding.Tests.fsproj", "{F5EBDD99-5ED7-4311-A5CB-7CFCE696FF88}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Debug|Any CPU.Build.0 = Debug|Any CPU - {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Debug|x86.ActiveCfg = Debug|Any CPU {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Release|Any CPU.ActiveCfg = Release|Any CPU {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Release|Any CPU.Build.0 = Release|Any CPU - {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {88F6940F-D300-474C-B2A7-E2ECD5B04B57}.Release|x86.ActiveCfg = Release|Any CPU - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|Any CPU.ActiveCfg = Debug|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|Any CPU.Build.0 = Debug|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|x86.ActiveCfg = Debug|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|x86.Build.0 = Debug|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|Any CPU.ActiveCfg = Release|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|Any CPU.Build.0 = Release|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|Mixed Platforms.Build.0 = Release|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|x86.ActiveCfg = Release|x86 - {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|x86.Build.0 = Release|x86 + {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E}.Release|Any CPU.Build.0 = Release|Any CPU + {F5EBDD99-5ED7-4311-A5CB-7CFCE696FF88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5EBDD99-5ED7-4311-A5CB-7CFCE696FF88}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5EBDD99-5ED7-4311-A5CB-7CFCE696FF88}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5EBDD99-5ED7-4311-A5CB-7CFCE696FF88}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = FSharp.AutoComplete.fsproj + StartupItem = FSharp.AutoComplete\FSharp.AutoComplete.fsproj EndGlobalSection EndGlobal diff --git a/FSharp.AutoComplete/FSharp.AutoComplete.fsproj b/FSharp.AutoComplete/FSharp.AutoComplete.fsproj index 8100a7cd8..7d71c12ec 100644 --- a/FSharp.AutoComplete/FSharp.AutoComplete.fsproj +++ b/FSharp.AutoComplete/FSharp.AutoComplete.fsproj @@ -2,7 +2,7 @@ Debug - x86 + AnyCPU 8.0.30703 2.0 {B6AB4EF3-8F60-41A1-AB0C-851A6DEB169E} @@ -17,7 +17,7 @@ 11 - + True full False @@ -25,18 +25,16 @@ bin\Debug DEBUG;TRACE 3 - x86 bin\Debug\FSharp.InteractiveAutocomplete.XML --warnon:1182 - + pdbonly True True bin\Release TRACE 3 - x86 bin\Release\FSharp.InteractiveAutocomplete.XML False diff --git a/FSharp.AutoComplete/Program.fs b/FSharp.AutoComplete/Program.fs index 9e4ce54fc..cc037aad4 100644 --- a/FSharp.AutoComplete/Program.fs +++ b/FSharp.AutoComplete/Program.fs @@ -273,7 +273,7 @@ module internal CommandInput = // Parses always and returns default error message let error = parser { return Error("Unknown command or wrong arguments") } - // Parase any of the supported commands + // Parse any of the supported commands let parseCommand = function | null -> Quit @@ -390,11 +390,12 @@ module internal Main = ok /// Is the specified position consistent with internal state of file? - // Note that both emacs and FSC use 1-based line indexing + // Note that both emacs and FCS use 1-based line indexing + // while emacs uses 0-based column indexing and FCS is 1-based let posok file line col = let lines = state.Files.[file].Lines let ok = line <= lines.Length && line >= 1 && - col <= lines.[line - 1].Length && col >= 0 + col <= lines.[line - 1].Length + 1 && col >= 1 if not ok then printMsg "ERROR" "Position is out of range" ok diff --git a/FSharp.AutoComplete/test/integration/CompletionFilter/CompletionFilterRunner.fsx b/FSharp.AutoComplete/test/integration/CompletionFilter/CompletionFilterRunner.fsx index a23acb5ed..5c764b5f9 100644 --- a/FSharp.AutoComplete/test/integration/CompletionFilter/CompletionFilterRunner.fsx +++ b/FSharp.AutoComplete/test/integration/CompletionFilter/CompletionFilterRunner.fsx @@ -14,9 +14,9 @@ File.Delete "output.txt" let p = new FSharpAutoCompleteWrapper() p.parse "Script.fsx" -p.completion "Script.fsx" 2 6 -p.completionFilter "Script.fsx" 2 6 "StartsWith" -p.completionFilter "Script.fsx" 2 6 "Contains" +p.completion "Script.fsx" 2 7 +p.completionFilter "Script.fsx" 2 7 "StartsWith" +p.completionFilter "Script.fsx" 2 7 "Contains" p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "output.txt" diff --git a/FSharp.AutoComplete/test/integration/ErrorTests/ErrorsRunner.fsx b/FSharp.AutoComplete/test/integration/ErrorTests/ErrorsRunner.fsx index dd8c4f9b7..49d2c67ca 100644 --- a/FSharp.AutoComplete/test/integration/ErrorTests/ErrorsRunner.fsx +++ b/FSharp.AutoComplete/test/integration/ErrorTests/ErrorsRunner.fsx @@ -10,9 +10,9 @@ let p = new FSharpAutoCompleteWrapper() p.project "Test1.fsproj" p.parse "Program.fs" -p.completion "Program.fs" 6 13 +p.completion "Program.fs" 6 14 p.parse "Script.fsx" -p.completion "Script.fsx" 6 13 +p.completion "Script.fsx" 6 14 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "output.txt" diff --git a/FSharp.AutoComplete/test/integration/ErrorTestsJson/ErrorsRunner.fsx b/FSharp.AutoComplete/test/integration/ErrorTestsJson/ErrorsRunner.fsx index 3a9c42355..84a43a60b 100644 --- a/FSharp.AutoComplete/test/integration/ErrorTestsJson/ErrorsRunner.fsx +++ b/FSharp.AutoComplete/test/integration/ErrorTestsJson/ErrorsRunner.fsx @@ -13,8 +13,8 @@ p.project "Test1.fsproj" p.parse "Program.fs" p.parse "Script.fsx" Threading.Thread.Sleep(8000) -p.completion "Program.fs" 6 13 -p.completion "Script.fsx" 6 13 +p.completion "Program.fs" 6 14 +p.completion "Script.fsx" 6 14 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "output.json" diff --git a/FSharp.AutoComplete/test/integration/FindDeclarations/FindDeclRunner.fsx b/FSharp.AutoComplete/test/integration/FindDeclarations/FindDeclRunner.fsx index e985e2ec7..1cc8da0a0 100644 --- a/FSharp.AutoComplete/test/integration/FindDeclarations/FindDeclRunner.fsx +++ b/FSharp.AutoComplete/test/integration/FindDeclarations/FindDeclRunner.fsx @@ -17,11 +17,11 @@ p.project "FindDecl.fsproj" p.parse "FileTwo.fs" p.parse "Script.fsx" p.parse "Program.fs" -p.finddeclaration "Program.fs" 6 15 -p.finddeclaration "Program.fs" 8 19 -p.finddeclaration "Program.fs" 14 25 -p.finddeclaration "Program.fs" 10 19 -p.finddeclaration "Script.fsx" 6 16 +p.finddeclaration "Program.fs" 6 16 +p.finddeclaration "Program.fs" 8 20 +p.finddeclaration "Program.fs" 14 26 +p.finddeclaration "Program.fs" 10 20 +p.finddeclaration "Script.fsx" 6 17 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "output.txt" diff --git a/FSharp.AutoComplete/test/integration/MultiProj/MultiProjRunner.fsx b/FSharp.AutoComplete/test/integration/MultiProj/MultiProjRunner.fsx index 143f1e4c2..c9f236048 100644 --- a/FSharp.AutoComplete/test/integration/MultiProj/MultiProjRunner.fsx +++ b/FSharp.AutoComplete/test/integration/MultiProj/MultiProjRunner.fsx @@ -11,32 +11,32 @@ let p = new FSharpAutoCompleteWrapper() p.project "Proj1/Proj1.fsproj" p.parse "Proj1/Ops.fs" p.parse "Proj1/Program.fs" -p.completion "Proj1/Program.fs" 8 19 -p.completion "Proj1/Program.fs" 4 22 -p.completion "Proj1/Program.fs" 6 13 -p.completion "Proj1/Program.fs" 10 19 +p.completion "Proj1/Program.fs" 8 20 +p.completion "Proj1/Program.fs" 4 23 +p.completion "Proj1/Program.fs" 6 14 +p.completion "Proj1/Program.fs" 10 20 p.project "Proj2/Proj2.fsproj" p.parse "Proj2/Core.fs" p.parse "Proj2/Program.fs" -p.completion "Proj2/Program.fs" 8 19 -p.completion "Proj2/Program.fs" 4 22 -p.completion "Proj2/Program.fs" 6 13 -p.completion "Proj2/Program.fs" 10 19 +p.completion "Proj2/Program.fs" 8 20 +p.completion "Proj2/Program.fs" 4 23 +p.completion "Proj2/Program.fs" 6 14 +p.completion "Proj2/Program.fs" 10 20 p.parse "Proj1/Ops.fs" p.parse "Proj1/Program.fs" -p.completion "Proj1/Program.fs" 8 19 -p.completion "Proj1/Program.fs" 4 22 -p.completion "Proj1/Program.fs" 6 13 -p.completion "Proj1/Program.fs" 10 19 +p.completion "Proj1/Program.fs" 8 20 +p.completion "Proj1/Program.fs" 4 23 +p.completion "Proj1/Program.fs" 6 14 +p.completion "Proj1/Program.fs" 10 20 p.parse "Proj2/Core.fs" p.parse "Proj2/Program.fs" -p.completion "Proj2/Program.fs" 8 19 -p.completion "Proj2/Program.fs" 4 22 -p.completion "Proj2/Program.fs" 6 13 -p.completion "Proj2/Program.fs" 10 19 +p.completion "Proj2/Program.fs" 8 20 +p.completion "Proj2/Program.fs" 4 23 +p.completion "Proj2/Program.fs" 6 14 +p.completion "Proj2/Program.fs" 10 20 p.send "quit\n" p.finalOutput () diff --git a/FSharp.AutoComplete/test/integration/OutOfRange/OutOfRangeRunner.fsx b/FSharp.AutoComplete/test/integration/OutOfRange/OutOfRangeRunner.fsx index de69b5cbf..72d8fb785 100644 --- a/FSharp.AutoComplete/test/integration/OutOfRange/OutOfRangeRunner.fsx +++ b/FSharp.AutoComplete/test/integration/OutOfRange/OutOfRangeRunner.fsx @@ -14,16 +14,16 @@ File.Delete "output.txt" let p = new FSharpAutoCompleteWrapper() p.parse "Script.fsx" +p.completion "Script.fsx" 6 17 p.completion "Script.fsx" 6 16 -p.completion "Script.fsx" 6 15 -p.tooltip "Script.fsx" 6 13 p.tooltip "Script.fsx" 6 14 p.tooltip "Script.fsx" 6 15 p.tooltip "Script.fsx" 6 16 -p.finddeclaration "Script.fsx" 6 13 +p.tooltip "Script.fsx" 6 17 p.finddeclaration "Script.fsx" 6 14 p.finddeclaration "Script.fsx" 6 15 p.finddeclaration "Script.fsx" 6 16 +p.finddeclaration "Script.fsx" 6 17 p.send "quit\n" p.finalOutput () diff --git a/FSharp.AutoComplete/test/integration/RawIdTest/Runner.fsx b/FSharp.AutoComplete/test/integration/RawIdTest/Runner.fsx index 22d8a2c1e..e20387254 100644 --- a/FSharp.AutoComplete/test/integration/RawIdTest/Runner.fsx +++ b/FSharp.AutoComplete/test/integration/RawIdTest/Runner.fsx @@ -15,12 +15,12 @@ let p = new FSharpAutoCompleteWrapper() p.parse "Test-Module.fsx" p.parse "Test-Class.fsx" -p.completion "Test-Module.fsx" 9 2 -p.completion "Test-Module.fsx" 11 12 -p.completion "Test-Module.fsx" 13 13 -p.completion "Test-Class.fsx" 9 2 -p.completion "Test-Class.fsx" 11 12 -p.completion "Test-Class.fsx" 13 13 +p.completion "Test-Module.fsx" 9 3 +p.completion "Test-Module.fsx" 11 13 +p.completion "Test-Module.fsx" 13 14 +p.completion "Test-Class.fsx" 9 3 +p.completion "Test-Class.fsx" 11 13 +p.completion "Test-Class.fsx" 13 14 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "output.txt" diff --git a/FSharp.AutoComplete/test/integration/RobustCommands/CompleteNoSuchFileRunner.fsx b/FSharp.AutoComplete/test/integration/RobustCommands/CompleteNoSuchFileRunner.fsx index 06112ef59..f0448422a 100644 --- a/FSharp.AutoComplete/test/integration/RobustCommands/CompleteNoSuchFileRunner.fsx +++ b/FSharp.AutoComplete/test/integration/RobustCommands/CompleteNoSuchFileRunner.fsx @@ -9,7 +9,7 @@ File.Delete "completenosuchfile.txt" let p = new FSharpAutoCompleteWrapper() p.project "Project/Test1.fsproj" -p.completion "NoSuchFile.fs" 0 0 +p.completion "NoSuchFile.fs" 1 1 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "completenosuchfile.txt" diff --git a/FSharp.AutoComplete/test/integration/RobustCommands/CompleteWithoutProjectRunner.fsx b/FSharp.AutoComplete/test/integration/RobustCommands/CompleteWithoutProjectRunner.fsx index 815d93787..de4f5fcda 100644 --- a/FSharp.AutoComplete/test/integration/RobustCommands/CompleteWithoutProjectRunner.fsx +++ b/FSharp.AutoComplete/test/integration/RobustCommands/CompleteWithoutProjectRunner.fsx @@ -9,9 +9,9 @@ File.Delete "completewithoutproject.txt" let p = new FSharpAutoCompleteWrapper() p.parse "Project/Script.fsx" -p.completion "Project/Script.fsx" 6 13 +p.completion "Project/Script.fsx" 6 14 p.parse "Project/Program.fs" -p.completion "Project/Program.fs" 4 22 +p.completion "Project/Program.fs" 4 23 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "completewithoutproject.txt" diff --git a/FSharp.AutoComplete/test/integration/SymOpActivePatTooltips/Runner.fsx b/FSharp.AutoComplete/test/integration/SymOpActivePatTooltips/Runner.fsx index 8e3aab376..eaec26dbf 100644 --- a/FSharp.AutoComplete/test/integration/SymOpActivePatTooltips/Runner.fsx +++ b/FSharp.AutoComplete/test/integration/SymOpActivePatTooltips/Runner.fsx @@ -14,7 +14,6 @@ File.Delete "output.txt" let p = new FSharpAutoCompleteWrapper() p.parse "Script.fsx" -p.tooltip "Script.fsx" 6 13 p.tooltip "Script.fsx" 6 14 p.tooltip "Script.fsx" 6 15 p.tooltip "Script.fsx" 6 16 @@ -28,9 +27,10 @@ p.tooltip "Script.fsx" 6 23 p.tooltip "Script.fsx" 6 24 p.tooltip "Script.fsx" 6 25 p.tooltip "Script.fsx" 6 26 -p.tooltip "Script.fsx" 8 6 -p.tooltip "Script.fsx" 8 10 -p.tooltip "Script.fsx" 8 15 +p.tooltip "Script.fsx" 6 27 +p.tooltip "Script.fsx" 8 7 +p.tooltip "Script.fsx" 8 11 +p.tooltip "Script.fsx" 8 16 p.send "quit\n" p.finalOutput () |> writeNormalizedOutput "output.txt" diff --git a/FSharp.AutoComplete/test/integration/Test1/Test1Runner.fsx b/FSharp.AutoComplete/test/integration/Test1/Test1Runner.fsx old mode 100644 new mode 100755 index 87b089146..2045cd822 --- a/FSharp.AutoComplete/test/integration/Test1/Test1Runner.fsx +++ b/FSharp.AutoComplete/test/integration/Test1/Test1Runner.fsx @@ -1,3 +1,4 @@ +#!/usr/bin/env fsharpi --exec #load "../TestHelpers.fsx" open TestHelpers open System.IO @@ -17,15 +18,15 @@ p.project "Test1.fsproj" p.parse "FileTwo.fs" p.parse "Script.fsx" p.parse "Program.fs" -p.completion "Script.fsx" 6 15 -p.completion "Program.fs" 8 19 -p.completion "Program.fs" 4 22 -p.completion "Program.fs" 6 13 -p.completion "Program.fs" 10 19 -p.tooltip "FileTwo.fs" 9 6 -p.tooltip "Program.fs" 6 15 -p.tooltip "Program.fs" 4 8 -p.tooltip "Script.fsx" 4 9 +p.completion "Script.fsx" 6 16 +p.completion "Program.fs" 8 20 +p.completion "Program.fs" 4 23 +p.completion "Program.fs" 6 14 +p.completion "Program.fs" 10 20 +p.tooltip "FileTwo.fs" 9 7 +p.tooltip "Program.fs" 6 16 +p.tooltip "Program.fs" 4 9 +p.tooltip "Script.fsx" 4 10 p.declarations "Program.fs" p.declarations "FileTwo.fs" p.declarations "Script.fsx" diff --git a/FSharp.AutoComplete/test/integration/Test1Json/Test1JsonRunner.fsx b/FSharp.AutoComplete/test/integration/Test1Json/Test1JsonRunner.fsx index 56930daf1..11cb4b2d7 100644 --- a/FSharp.AutoComplete/test/integration/Test1Json/Test1JsonRunner.fsx +++ b/FSharp.AutoComplete/test/integration/Test1Json/Test1JsonRunner.fsx @@ -19,17 +19,17 @@ p.parse "FileTwo.fs" p.parse "Script.fsx" p.parse "Program.fs" Threading.Thread.Sleep(8000) -p.completion "Script.fsx" 6 15 -p.completion "Program.fs" 8 19 -p.completion "Program.fs" 4 22 -p.completion "Program.fs" 6 13 -p.completion "Program.fs" 10 19 -p.tooltip "FileTwo.fs" 9 6 -p.tooltip "Program.fs" 6 15 -p.tooltip "Program.fs" 4 8 -p.tooltip "Script.fsx" 4 9 -p.finddeclaration "Program.fs" 8 22 -p.finddeclaration "Script.fsx" 6 15 +p.completion "Script.fsx" 6 16 +p.completion "Program.fs" 8 20 +p.completion "Program.fs" 4 23 +p.completion "Program.fs" 6 14 +p.completion "Program.fs" 10 20 +p.tooltip "FileTwo.fs" 9 7 +p.tooltip "Program.fs" 6 16 +p.tooltip "Program.fs" 4 9 +p.tooltip "Script.fsx" 4 10 +p.finddeclaration "Program.fs" 8 23 +p.finddeclaration "Script.fsx" 6 16 p.declarations "Program.fs" p.declarations "FileTwo.fs" p.declarations "Script.fsx" diff --git a/FSharp.CompilerBinding.Tests/FSharp.CompilerBinding.Tests.fsproj b/FSharp.CompilerBinding.Tests/FSharp.CompilerBinding.Tests.fsproj new file mode 100644 index 000000000..76ab39398 --- /dev/null +++ b/FSharp.CompilerBinding.Tests/FSharp.CompilerBinding.Tests.fsproj @@ -0,0 +1,92 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + f5ebdd99-5ed7-4311-a5cb-7cfce696ff88 + Library + FSharp.CompilerBinding.Tests + FSharp.CompilerBinding.Tests + v4.5 + ..\ + False + 4.3.0.0 + FSharp.CompilerBinding.Tests + 11 + + + + True + full + False + False + bin\Debug + DEBUG;TRACE + 3 + bin\Debug\FSharp.CompilerBinding.Tests.XML + --warnon:1182 + + + pdbonly + True + True + bin\Release + TRACE + 3 + bin\Release\FSharp.CompilerBinding.Tests.xml + False + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + + + + + + + + ..\packages\FSharp.Compiler.Service\lib\net45\FSharp.Compiler.Service.dll + True + + + + + + + + {88F6940F-D300-474C-B2A7-E2ECD5B04B57} + FSharp.CompilerBinding + + + + + + + ..\packages\NUnit\lib\nunit.framework.dll + True + True + + + diff --git a/FSharp.CompilerBinding.Tests/Tests.fs b/FSharp.CompilerBinding.Tests/Tests.fs new file mode 100644 index 000000000..7fdb609f4 --- /dev/null +++ b/FSharp.CompilerBinding.Tests/Tests.fs @@ -0,0 +1,36 @@ +module FSharp.CompilerBinding.Tests + +open FSharp.CompilerBinding +open NUnit.Framework + +[] +let ``activePatternCracking`` () = + let lineStr = "let (|Zero|Succ|) n = if n = 0 then Zero else Succ(n-1)" + match Parsing.findLongIdents(8, lineStr) with + | None -> Assert.Fail() + | Some (col, _idents) -> + + Assert.AreEqual(15,col) + //Assert.AreEqual(["|Zero|Succ|"],idents) + // Actually returns "Zero|Succ|", but this is fine for tooltips + Assert.AreEqual(lineStr.[col], '|') + +[] +let ``symbolicOperatorCracking`` () = + match Parsing.findLongIdents(0, "|<>|") with + | None -> Assert.Fail() + | Some (col, idents) -> + + Assert.AreEqual(3,col) + Assert.AreEqual(["|<>|"],idents) + Assert.AreEqual("|<>|".[col], '|') + +[] +let ``normalCracking`` () = + match Parsing.findLongIdents(8, "First.Second.Third") with + | None -> Assert.Fail() + | Some (col, idents) -> + + Assert.AreEqual(11,col) + Assert.AreEqual(["First";"Second"],idents) + Assert.AreEqual("First.Second.Third".[col], 'd') diff --git a/FSharp.CompilerBinding.Tests/paket.references b/FSharp.CompilerBinding.Tests/paket.references new file mode 100644 index 000000000..37c33ed0f --- /dev/null +++ b/FSharp.CompilerBinding.Tests/paket.references @@ -0,0 +1,2 @@ +NUnit +NUnit.Runners \ No newline at end of file diff --git a/FSharp.CompilerBinding/FSharp.CompilerBinding.fsproj b/FSharp.CompilerBinding/FSharp.CompilerBinding.fsproj index e37a93e08..8955850a2 100644 --- a/FSharp.CompilerBinding/FSharp.CompilerBinding.fsproj +++ b/FSharp.CompilerBinding/FSharp.CompilerBinding.fsproj @@ -1,4 +1,4 @@ - + Debug diff --git a/FSharp.CompilerBinding/LanguageService.fs b/FSharp.CompilerBinding/LanguageService.fs index a89872fdb..96f96cd2b 100644 --- a/FSharp.CompilerBinding/LanguageService.fs +++ b/FSharp.CompilerBinding/LanguageService.fs @@ -44,7 +44,7 @@ type ParseAndCheckResults private (infoOpt: (FSharpCheckFileResults * FSharpPars match infoOpt with | None -> None | Some (checkResults, parseResults) -> - let longName,residue = Parsing.findLongIdentsAndResidue(col, lineStr) + let longName,residue = Parsing.findLongIdentsAndResidue(col - 1, lineStr) Debug.WriteLine (sprintf "GetDeclarations: '%A', '%s'" longName residue) // Get items & generate output try @@ -60,7 +60,7 @@ type ParseAndCheckResults private (infoOpt: (FSharpCheckFileResults * FSharpPars match infoOpt with | None -> None | Some (checkResults, parseResults) -> - let longName,residue = Parsing.findLongIdentsAndResidue(col, lineStr) + let longName,residue = Parsing.findLongIdentsAndResidue(col - 1, lineStr) Debug.WriteLine (sprintf "GetDeclarationSymbols: '%A', '%s'" longName residue) // Get items & generate output try @@ -77,11 +77,11 @@ type ParseAndCheckResults private (infoOpt: (FSharpCheckFileResults * FSharpPars match infoOpt with | None -> return None | Some (checkResults, _parseResults) -> - match Parsing.findLongIdents(col, lineStr) with + match Parsing.findLongIdents(col - 1, lineStr) with | None -> return None | Some(col,identIsland) -> - let! res = checkResults.GetToolTipTextAlternate(line, col, lineStr, identIsland, token) - let! sym = checkResults.GetSymbolUseAtLocation(line, col, lineStr, identIsland) + let! res = checkResults.GetToolTipTextAlternate(line, col + 1, lineStr, identIsland, token) + let! sym = checkResults.GetSymbolUseAtLocation(line, col + 1, lineStr, identIsland) Debug.WriteLine("Result: Got something, returning") return sym |> Option.bind (fun sym -> let (_, startCol), (_, endCol) = Symbols.trimSymbolRegion sym (Seq.last identIsland) Some (res, (startCol, endCol))) @@ -91,18 +91,18 @@ type ParseAndCheckResults private (infoOpt: (FSharpCheckFileResults * FSharpPars match infoOpt with | None -> return FSharpFindDeclResult.DeclNotFound FSharpFindDeclFailureReason.Unknown | Some (checkResults, _parseResults) -> - match Parsing.findLongIdents(col, lineStr) with + match Parsing.findLongIdents(col - 1, lineStr) with | None -> return FSharpFindDeclResult.DeclNotFound FSharpFindDeclFailureReason.Unknown - | Some(col,identIsland) -> return! checkResults.GetDeclarationLocationAlternate(line, col, lineStr, identIsland, false) + | Some(col,identIsland) -> return! checkResults.GetDeclarationLocationAlternate(line, col + 1, lineStr, identIsland, false) } member x.GetMethods(line, col, lineStr) = async { match infoOpt with | None -> return None | Some (checkResults, _parseResults) -> - match Parsing.findLongIdentsAtGetMethodsTrigger(col, lineStr) with + match Parsing.findLongIdentsAtGetMethodsTrigger(col - 1, lineStr) with | None -> return None - | Some(col,identIsland) -> + | Some identIsland -> let! res = checkResults.GetMethodsAlternate(line, col, lineStr, Some identIsland) Debug.WriteLine("Result: Got something, returning") return Some (res.MethodName, res.Methods) @@ -113,10 +113,10 @@ type ParseAndCheckResults private (infoOpt: (FSharpCheckFileResults * FSharpPars match infoOpt with | None -> return None | Some (checkResults, _parseResults) -> - match Parsing.findLongIdents(col, lineStr) with + match Parsing.findLongIdents(col - 1, lineStr) with | None -> return None | Some(colu, identIsland) -> - return! checkResults.GetSymbolUseAtLocation(line, colu, lineStr, identIsland) + return! checkResults.GetSymbolUseAtLocation(line, colu + 1, lineStr, identIsland) } member x.GetSymbolAtLocation(line, col, lineStr, identIsland) = diff --git a/FSharp.CompilerBinding/Parser.fs b/FSharp.CompilerBinding/Parser.fs index 0429ffb24..92419593f 100644 --- a/FSharp.CompilerBinding/Parser.fs +++ b/FSharp.CompilerBinding/Parser.fs @@ -296,7 +296,7 @@ module Parsing = match identIsland with | [] | [ "" ] -> None - | _ -> Some (col + nextIdent.Length,identIsland) + | _ -> Some (col + nextIdent.Length - 1,identIsland) /// find the identifier prior to a '(' or ',' once the method tip trigger '(' shows let findLongIdentsAtGetMethodsTrigger (col, lineStr) = @@ -313,7 +313,7 @@ module Parsing = match identIsland with | [] | [ "" ] -> None - | _ -> Some (col,identIsland) + | _ -> Some identIsland /// Returns the previous long idents and the current 'residue' let findLongIdentsAndResidue (col, lineStr) = diff --git a/build.fsx b/build.fsx index 6e9b98b19..79fc5aa22 100644 --- a/build.fsx +++ b/build.fsx @@ -25,7 +25,8 @@ let buildReleaseDir = project + "/bin/Release/" let integrationTestDir = project + "/test/integration/" let releaseArchive = "fsautocomplete.zip" - +// Pattern specifying assemblies to be tested using NUnit +let testAssemblies = "**/bin/*/*Tests*.dll" Target "BuildDebug" (fun _ -> MSBuildDebug buildDir "Build" ["./FSharp.AutoComplete.sln"] @@ -68,6 +69,15 @@ Target "IntegrationTest" (fun _ -> failwithf "Integration tests failed:\n%s" err ) +Target "UnitTest" (fun _ -> + !! testAssemblies + |> NUnit (fun p -> + { p with + DisableShadowCopy = true + TimeOut = TimeSpan.FromMinutes 20. + OutputFile = "TestResults.xml" }) +) + Target "AssemblyInfo" (fun _ -> let fileName = project + "/AssemblyInfo.fs" CreateFSharpAssemblyInfo fileName @@ -111,7 +121,12 @@ Target "Release" id ==> "Build" ==> "IntegrationTest" +"BuildDebug" + ==> "Build" + ==> "UnitTest" + "IntegrationTest" ==> "Test" +"UnitTest" ==> "Test" "BuildDebug" ==> "All" "Test" ==> "All" diff --git a/paket.dependencies b/paket.dependencies index d7f04fe30..8c7147678 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -5,4 +5,6 @@ nuget Mono.Cecil nuget NDesk.Options nuget Newtonsoft.Json nuget FAKE -nuget FSharp.Core 3.0.2 \ No newline at end of file +nuget FSharp.Core 3.0.2 +nuget NUnit +nuget NUnit.Runners \ No newline at end of file diff --git a/paket.lock b/paket.lock index 0f3dba31c..06d3adae7 100644 --- a/paket.lock +++ b/paket.lock @@ -1,9 +1,11 @@ NUGET remote: https://www.nuget.org/api/v2 specs: - FAKE (3.31.4) + FAKE (3.34.6) FSharp.Compiler.Service (0.0.89) - framework: >= net45 FSharp.Core (3.0.2) Mono.Cecil (0.9.6.1) NDesk.Options (0.2.1) Newtonsoft.Json (6.0.8) + NUnit (2.6.4) + NUnit.Runners (2.6.4)