forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeProviderTests.fs
118 lines (111 loc) · 4.49 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
module Fantomas.Tests.TypeProviderTests
open NUnit.Framework
open FsUnit
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>]
let ``should add space before type provider named argument, 1209`` () =
formatSourceString
false
"""
type Graphml = XmlProvider<Schema= @"http://graphml.graphdrawing.org/xmlns/1.0/graphml-structure.xsd">
"""
config
|> prepend newline
|> should
equal
"""
type Graphml = XmlProvider<Schema= @"http://graphml.graphdrawing.org/xmlns/1.0/graphml-structure.xsd">
"""
[<Test>]
let ``should throw FormatException on unparsed input`` () =
Assert.Throws<Fantomas.FormatConfig.FormatException> (fun () ->
formatSourceString
false
"""
type GeoResults = JsonProvider<Sample= "A" + "GitHub.json" >"""
config
|> ignore)
|> 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 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()
"""
[<Test>]
let ``multiple arguments in type provider`` () =
formatSourceString
false
"""
type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/", "password">"""
config
|> prepend newline
|> should
equal
"""
type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/", "password">
"""