forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeProviderTests.fs
51 lines (45 loc) · 3.94 KB
/
TypeProviderTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Fantomas.Tests.TypeProviderTests
open NUnit.Framework
open FsUnit
open Fantomas.CodeFormatter
open Fantomas.Tests.TestHelper
[<Test>]
let ``type providers``() =
formatSourceString false """
type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/">""" config
|> prepend newline
|> should equal """
type Northwind = ODataService< "http://services.odata.org/Northwind/Northwind.svc/" >
"""
[<Test>]
let ``should add space before type provider params``() =
formatSourceString false """
type IntegerRegex = FSharpx.Regex< @"(?<value>\d+)" >""" config
|> prepend newline
|> should equal """
type IntegerRegex = FSharpx.Regex< @"(?<value>\d+)" >
"""
[<Test; ExpectedException(typeof<Fantomas.FormatConfig.FormatException>)>]
let ``should throw FormatException on unparsed input``() =
formatSourceString false """
type GeoResults = JsonProvider<Sample= "A" + "GitHub.json" >""" config
|> ignore
[<Test>]
let ``should handle lines with more than 512 characters``() =
formatSourceString false """
(new CsvFile<string * decimal * decimal>(new Func<obj, string[], string * decimal * decimal>(fun (parent : obj) (row : string[]) -> CommonRuntime.GetNonOptionalValue("Name", CommonRuntime.ConvertString(TextConversions.AsOption(row.[0])), TextConversions.AsOption(row.[0])), CommonRuntime.GetNonOptionalValue("Distance", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[1])), TextConversions.AsOption(row.[1])), CommonRuntime.GetNonOptionalValue("Time", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[2])), TextConversions.AsOption(row.[2]))), new Func<string * decimal * decimal, string[]>(fun (row : string * decimal * decimal) -> [| CommonRuntime.ConvertStringBack(CommonRuntime.GetOptionalValue((let x, _, _ = row in x))); CommonRuntime.ConvertDecimalBack("", CommonRuntime.GetOptionalValue((let _, x, _ = row in x))); CommonRuntime.ConvertDecimalBack("", CommonRuntime.GetOptionalValue((let _, _, x = row in x))) |]), (ProviderFileSystem.readTextAtRunTimeWithDesignTimeOptions @"C:\Dev\FSharp.Data-master\src\..\tests\FSharp.Data.Tests\Data" "" "SmallTest.csv"), "", '"', true, false)).Cache()
""" config
|> prepend newline
|> should equal """
(new CsvFile<string * decimal * decimal>(new Func<obj, string [], string * decimal * decimal>(fun (parent : obj) (row : string []) -> CommonRuntime.GetNonOptionalValue("Name", CommonRuntime.ConvertString(TextConversions.AsOption(row.[0])), TextConversions.AsOption(row.[0])), CommonRuntime.GetNonOptionalValue("Distance", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[1])), TextConversions.AsOption(row.[1])), CommonRuntime.GetNonOptionalValue("Time", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[2])), TextConversions.AsOption(row.[2]))),
new Func<string * decimal * decimal, string []>(fun (row : string * decimal * decimal) ->
[| CommonRuntime.ConvertStringBack(CommonRuntime.GetOptionalValue((let x, _, _ = row
x)))
CommonRuntime.ConvertDecimalBack("",
CommonRuntime.GetOptionalValue((let _, x, _ = row
x)))
CommonRuntime.ConvertDecimalBack("",
CommonRuntime.GetOptionalValue((let _, _, x = row
x))) |]), (ProviderFileSystem.readTextAtRunTimeWithDesignTimeOptions @"C:\Dev\FSharp.Data-master\src\..\tests\FSharp.Data.Tests\Data" "" "SmallTest.csv"), "", '"', true, false))
.Cache()
"""