Skip to content

Commit af5c23f

Browse files
authored
Cleanup (#2540)
* Remove unused code in Fantomas.Core. * Remove unused code in Fantomas.Core.Tests.
1 parent f1ec008 commit af5c23f

File tree

10 files changed

+113
-213
lines changed

10 files changed

+113
-213
lines changed

src/Fantomas.Core.Tests/ClassTests.fs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,20 @@ type A() =
594594

595595
[<Test>]
596596
let ``no extra new line before nested module with attribute, 586`` () =
597-
shouldNotChangeAfterFormat
597+
formatSourceString
598+
false
599+
"""
600+
module A =
601+
let x = 0
602+
603+
[<RequireQualifiedAccess>]
604+
module B =
605+
let y = 1
606+
"""
607+
config
608+
|> prepend newline
609+
|> should
610+
equal
598611
"""
599612
module A =
600613
let x = 0
@@ -606,7 +619,20 @@ module A =
606619

607620
[<Test>]
608621
let ``no extra new line before abstract member with attribute, 586`` () =
609-
shouldNotChangeAfterFormat
622+
formatSourceString
623+
false
624+
"""
625+
type A =
626+
627+
[<EmitConstructor>]
628+
abstract Create: Unit -> A
629+
630+
abstract b: Unit -> Unit
631+
"""
632+
config
633+
|> prepend newline
634+
|> should
635+
equal
610636
"""
611637
type A =
612638
@@ -618,7 +644,21 @@ type A =
618644

619645
[<Test>]
620646
let ``no extra new line between abstract members with attribute, 586`` () =
621-
shouldNotChangeAfterFormat
647+
formatSourceString
648+
false
649+
"""
650+
type A =
651+
652+
[<Emit("a")>]
653+
abstract a: Unit -> string
654+
655+
[<Emit("b")>]
656+
abstract b: Unit -> string
657+
"""
658+
config
659+
|> prepend newline
660+
|> should
661+
equal
622662
"""
623663
type A =
624664

src/Fantomas.Core.Tests/RecordTests.fs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,19 @@ let newDocument = //somecomment
269269

270270
[<Test>]
271271
let ``|> should be on the next line if preceding expression is multiline`` () =
272-
shouldNotChangeAfterFormat
272+
formatSourceString
273+
false
274+
"""
275+
let newDocument = //somecomment
276+
{ program = "Loooooooooooooooooooooooooong"
277+
content = "striiiiiiiiiiiiiiiiiiinnnnnnnnnnng"
278+
created = document.Created.ToLocalTime() }
279+
|> JsonConvert.SerializeObject
280+
"""
281+
config
282+
|> prepend newline
283+
|> should
284+
equal
273285
"""
274286
let newDocument = //somecomment
275287
{ program = "Loooooooooooooooooooooooooong"

src/Fantomas.Core.Tests/SignatureTests.fs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,33 @@ let ``should keep the (string * string) list type signature in records`` () =
3232

3333
[<Test>]
3434
let ``should keep the (string * string) list type signature in functions`` () =
35-
shouldNotChangeAfterFormat
35+
formatSourceString
36+
false
37+
"""
38+
let MSBuildWithProjectProperties outputPath (targets: string) (properties: string -> (string * string) list) projects =
39+
doingsomstuff
40+
"""
41+
config
42+
|> prepend newline
43+
|> should
44+
equal
3645
"""
3746
let MSBuildWithProjectProperties outputPath (targets: string) (properties: string -> (string * string) list) projects =
3847
doingsomstuff
3948
"""
4049

4150
[<Test>]
4251
let ``should keep the string * string list type signature in functions`` () =
43-
shouldNotChangeAfterFormat
52+
formatSourceString
53+
false
54+
"""
55+
let MSBuildWithProjectProperties outputPath (targets: string) (properties: (string -> string) * string list) projects =
56+
doingsomstuff
57+
"""
58+
config
59+
|> prepend newline
60+
|> should
61+
equal
4462
"""
4563
let MSBuildWithProjectProperties outputPath (targets: string) (properties: (string -> string) * string list) projects =
4664
doingsomstuff
Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
module Fantomas.Core.Tests.TestHelper
22

33
open System
4-
open System.IO
54
open Fantomas.Core.TriviaTypes
65
open NUnit.Framework
7-
open FsCheck
86
open FsUnit
9-
open FSharp.Compiler.Text
107
open Fantomas.Core.FormatConfig
118
open Fantomas.Core
129

@@ -64,9 +61,6 @@ let formatSourceStringWithDefines defines (s: string) config =
6461
let isValidFSharpCode isFsiFile s =
6562
CodeFormatter.IsValidFSharpCodeAsync(isFsiFile, s) |> Async.RunSynchronously
6663

67-
let formatAST a s c =
68-
CodeFormatter.FormatASTAsync(a, s, c) |> Async.RunSynchronously
69-
7064
let equal x =
7165
let x =
7266
match box x with
@@ -76,72 +70,7 @@ let equal x =
7670
equal x
7771

7872
let inline prepend s content = s + content
79-
let inline append s content = content + s
80-
let zero = range.Zero
81-
82-
let tryFormatAST ast sourceCode config =
83-
try
84-
formatAST ast sourceCode config
85-
with _ ->
86-
""
87-
8873
let formatConfig = { FormatConfig.Default with StrictMode = true }
89-
90-
let shouldNotChangeAfterFormat source =
91-
formatSourceString false source config |> prepend newline |> should equal source
92-
9374
let (==) actual expected = Assert.AreEqual(expected, actual)
9475
let fail () = Assert.Fail()
9576
let pass () = Assert.Pass()
96-
97-
/// An FsCheck runner which reports FsCheck test results to NUnit.
98-
type NUnitRunner() =
99-
interface IRunner with
100-
member __.OnStartFixture _ = ()
101-
102-
member __.OnArguments(_ntest, _args, _every) =
103-
//stdout.Write(every ntest args)
104-
()
105-
106-
member __.OnShrink(_args, _everyShrink) =
107-
//stdout.Write(everyShrink args)
108-
()
109-
110-
member __.OnFinished(name, result) =
111-
match result with
112-
| TestResult.True (_data, _) ->
113-
// TODO : Log the result data.
114-
Runner.onFinishedToString name result |> stdout.WriteLine
115-
116-
| TestResult.Exhausted _data ->
117-
// TODO : Log the result data.
118-
Runner.onFinishedToString name result |> Assert.Inconclusive
119-
120-
| TestResult.False _ ->
121-
// TODO : Log more information about the test failure.
122-
Runner.onFinishedToString name result |> Assert.Fail
123-
124-
let private getTempFolder () = Path.GetTempPath()
125-
126-
let private mkConfigPath fileName folder =
127-
match folder with
128-
| Some folder ->
129-
let folderPath = Path.Combine(getTempFolder (), folder)
130-
Directory.CreateDirectory(folderPath) |> ignore
131-
Path.Combine(folderPath, fileName)
132-
| None -> Path.Combine(getTempFolder (), fileName)
133-
134-
let mkConfigFromContent fileName folder content =
135-
let file = mkConfigPath fileName folder
136-
File.WriteAllText(file, content)
137-
file
138-
139-
type TemporaryFileCodeSample internal (codeSnippet: string) =
140-
let filename = Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString() + ".fs")
141-
142-
do File.WriteAllText(filename, codeSnippet)
143-
144-
member __.Filename: string = filename
145-
146-
interface IDisposable with
147-
member this.Dispose() : unit = File.Delete(filename)

src/Fantomas.Core.Tests/UnionTests.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,20 @@ type X =
3535

3636
[<Test>]
3737
let ``enums conversion`` () =
38-
shouldNotChangeAfterFormat
38+
formatSourceString
39+
false
40+
"""
41+
type uColor =
42+
| Red = 0u
43+
| Green = 1u
44+
| Blue = 2u
45+
46+
let col3 = Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)
47+
"""
48+
config
49+
|> prepend newline
50+
|> should
51+
equal
3952
"""
4053
type uColor =
4154
| Red = 0u

0 commit comments

Comments
 (0)