Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2899fb6

Browse files
start adding UnusedOpensDiagnosticAnalyzer tests
1 parent5f2eb3e commit2899fb6

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

‎vsintegration/src/FSharp.Editor/Diagnostics/UnusedOpensDiagnosticAnalyzer.fs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ open Microsoft.FSharp.Compiler.Range
1717
openMicrosoft.FSharp.Compiler.SourceCodeServices
1818
openSymbols
1919

20-
moduleprivateUnusedOpens=
20+
moduleinternalUnusedOpens=
2121
/// Represents single open statement.
22-
typeOpenStatement=
22+
typeprivateOpenStatement=
2323
{/// Open namespace or module effective names.
2424
Names:Set<string>
2525
/// Range of open statement itself.
2626
Range:range
2727
/// Enclosing module or namespace range (that is, the scope on in which this open statement is visible).
2828
ModuleRange:range}
2929

30-
let recvisitSynModuleOrNamespaceDecls(parent:Ast.LongIdent)(decls:SynModuleDecls)(moduleRange:range):OpenStatement list=
30+
let recprivatevisitSynModuleOrNamespaceDecls(parent:Ast.LongIdent)(decls:SynModuleDecls)(moduleRange:range):OpenStatement list=
3131
[for declin declsdo
3232
match declwith
3333
| SynModuleDecl.Open(LongIdentWithDots.LongIdentWithDots(id= longId), range)->
@@ -44,15 +44,15 @@ module private UnusedOpens =
4444
yield! visitSynModuleOrNamespaceDecls longId decls moduleRange
4545
|_->()]
4646

47-
letgetOpenStatements(parsedInput:ParsedInput):OpenStatement list=
47+
letprivategetOpenStatements(parsedInput:ParsedInput):OpenStatement list=
4848
match parsedInputwith
4949
| ParsedInput.ImplFile(ParsedImplFileInput(modules= modules))->
5050
[for mdin modulesdo
5151
letSynModuleOrNamespace(longId= longId; decls= decls; range= moduleRange)= md
5252
yield! visitSynModuleOrNamespaceDecls longId decls moduleRange]
5353
|_->[]
5454

55-
letgetAutoOpenAccessPath(ent:FSharpEntity)=
55+
letprivategetAutoOpenAccessPath(ent:FSharpEntity)=
5656
// Some.Namespace+AutoOpenedModule+Entity
5757

5858
// HACK: I can't see a way to get the EnclosingEntity of an Entity
@@ -63,7 +63,7 @@ module private UnusedOpens =
6363
else
6464
None)
6565

66-
letentityNamespace(entOpt:FSharpEntity option)=
66+
letprivateentityNamespace(entOpt:FSharpEntity option)=
6767
match entOptwith
6868
| Some ent->
6969
if ent.IsFSharpModulethen
@@ -84,18 +84,17 @@ module private UnusedOpens =
8484
]
8585
| None->[]
8686

87-
letsymbolIsFullyQualified(sourceText:SourceText)(sym:FSharpSymbolUse)(fullName:string)=
87+
letprivatesymbolIsFullyQualified(sourceText:SourceText)(sym:FSharpSymbolUse)(fullName:string)=
8888
letlineStr= sourceText.Lines.[Line.toZ sym.RangeAlternate.StartLine].ToString()
8989
match QuickParse.GetCompleteIdentifierIslandtrue lineStr sym.RangeAlternate.EndColumnwith
9090
| Some(island,_,_)-> island= fullName
9191
| None->false
9292

93-
typeNamespaceUse=
93+
typeprivateNamespaceUse=
9494
{ Ident:string
9595
Location:range}
9696

9797
letgetUnusedOpens(sourceText:SourceText)(parsedInput:ParsedInput)(symbolUses:FSharpSymbolUse[]):range list=
98-
9998
letgetPartNamespace(symbolUse:FSharpSymbolUse)(fullName:string)=
10099
// given a symbol range such as `Text.ISegment` and a full name of `MonoDevelop.Core.Text.ISegment`, return `MonoDevelop.Core`
101100
letlength= symbolUse.RangeAlternate.EndColumn- symbolUse.RangeAlternate.StartColumn
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
namespaceMicrosoft.VisualStudio.FSharp.Editor.Tests.Roslyn
3+
4+
openSystem
5+
6+
openNUnit.Framework
7+
8+
openMicrosoft.CodeAnalysis.Text
9+
openMicrosoft.VisualStudio.FSharp.Editor
10+
openMicrosoft.FSharp.Compiler.SourceCodeServices
11+
openMicrosoft.FSharp.Compiler.Range
12+
openFsUnit
13+
14+
[<TestFixture>]
15+
[<Category"Roslyn Services">]
16+
typeUnusedOpensDiagnosticAnalyzer()=
17+
18+
letfilePath="C:\\test.fs"
19+
20+
letprojectOptions:FSharpProjectOptions=
21+
{ ProjectFileName="C:\\test.fsproj"
22+
SourceFiles=[| filePath|]
23+
ReferencedProjects=[||]
24+
OtherOptions=[||]
25+
IsIncompleteTypeCheckEnvironment=true
26+
UseScriptResolutionRules=false
27+
LoadTime= DateTime.MaxValue
28+
OriginalLoadReferences=[]
29+
UnresolvedReferences= None
30+
ExtraProjectInfo= None
31+
Stamp= None}
32+
33+
let mutablechecker=lazy(FSharpChecker.Create())
34+
35+
let(=>)(source: string)(expectedRanges:(int*(int* int)) list)=
36+
letsourceText= SourceText.From(source)
37+
38+
letparsedInput,checkFileResults=
39+
letparseResults,checkFileAnswer= checker.Value.ParseAndCheckFileInProject(filePath,0, source, projectOptions)|> Async.RunSynchronously
40+
match checkFileAnswerwith
41+
| FSharpCheckFileAnswer.Aborted-> failwithf"ParseAndCheckFileInProject aborted"
42+
| FSharpCheckFileAnswer.Succeeded(checkFileResults)->
43+
match parseResults.ParseTreewith
44+
| None-> failwith"Parse returns None ParseTree"
45+
| Some parsedInput-> parsedInput, checkFileResults
46+
47+
letallSymbolUses= checkFileResults.GetAllUsesOfAllSymbolsInFile()|> Async.RunSynchronously
48+
letunusedOpenRanges= UnusedOpens.getUnusedOpens sourceText parsedInput allSymbolUses
49+
50+
unusedOpenRanges
51+
|> List.map(fun x-> x.StartLine,(x.StartColumn, x.EndColumn))
52+
|> shouldEqual expectedRanges
53+
54+
[<Test>]
55+
member__.``top level module``()=
56+
"""
57+
module TopModule
58+
open System
59+
open System.IO
60+
let _ = DateTime.Now
61+
"""
62+
=>[4,(5,14)]

‎vsintegration/tests/unittests/VisualFSharp.Unittests.fsproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
<CompileInclude="DocumentHighlightsServiceTests.fs">
135135
<Link>Roslyn\DocumentHighlightsServiceTests.fs</Link>
136136
</Compile>
137+
<CompileInclude="UnusedOpensDiagnosticAnalyzerTests.fs">
138+
<Link>Roslyn\UnusedOpensDiagnosticAnalyzerTests.fs</Link>
139+
</Compile>
137140
<CopyAndSubstituteTextInclude="VisualFSharp.Unittests.dll.config">
138141
<TargetFilename>VisualFSharp.Unittests.dll.config</TargetFilename>
139142
<Pattern1>{VisualStudioVersion}</Pattern1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp