forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexSyntaxTests.fs
150 lines (140 loc) · 2.91 KB
/
IndexSyntaxTests.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
module Fantomas.Tests.IndexSyntaxTests
open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelper
[<Test>]
let ``don't convert index syntax without dot to application`` () =
formatSourceString
false
"""
expr1[expr2]
"""
config
|> prepend newline
|> should
equal
"""
expr1[expr2]
"""
[<Test>]
let ``slicing examples`` () =
formatSourceString
false
"""
let arr = [| 1;2;3 |]
arr[0] <- 2
arr[0]
arr[0..1]
arr[..1]
arr[0..]
"""
config
|> prepend newline
|> should
equal
"""
let arr = [| 1; 2; 3 |]
arr[0] <- 2
arr[0]
arr[0..1]
arr[..1]
arr[0..]
"""
[<Test>]
let ``higher-dimensional arrays`` () =
formatSourceString
false
"""
let arr = Array4D.create 3 4 5 6 0
arr[0,2,3,4] <- 2
arr[0,2,3,4]
"""
config
|> prepend newline
|> should
equal
"""
let arr = Array4D.create 3 4 5 6 0
arr[0, 2, 3, 4] <- 2
arr[0, 2, 3, 4]
"""
[<Test>]
let ``only add spaces when expressions are atomic`` () =
formatSourceString
false
"""
let a = [ 2 .. 7 ] // integers
let b = [ one .. two ] // identifiers
let c = [ .. 9 ] // also when there is only one expression
let d = [ 0.7 .. 9.2 ] // doubles
let e = [ 2L .. number / 2L ] // complex expression
let f = [| A.B .. C.D |] // identifiers with dots
let g = [ .. (39 - 3) ] // complex expression
let h = [| 1 .. MyModule.SomeConst |] // not all expressions are atomic
for x in 1 .. 2 do
printfn " x = %d" x
let s = seq { 0..10..100 }
"""
config
|> prepend newline
|> should
equal
"""
let a = [ 2..7 ] // integers
let b = [ one..two ] // identifiers
let c = [ ..9 ] // also when there is only one expression
let d = [ 0.7 .. 9.2 ] // doubles
let e = [ 2L .. number / 2L ] // complex expression
let f = [| A.B .. C.D |] // identifiers with dots
let g = [ .. (39 - 3) ] // complex expression
let h = [| 1 .. MyModule.SomeConst |] // not all expressions are atomic
for x in 1..2 do
printfn " x = %d" x
let s = seq { 0..10..100 }
"""
[<Test>]
let ``index syntax on raw list, 1929`` () =
formatSourceString
false
"""
let y = [ 0; 2; 4 ][ 1 ]
"""
config
|> prepend newline
|> should
equal
"""
let y = [ 0; 2; 4 ][1]
"""
[<Test>]
let ``index syntax on dotget, 1985`` () =
formatSourceString
false
"""
let segment = System.Uri(ctx.Request.Path.Value).Segments[1]
"""
config
|> prepend newline
|> should
equal
"""
let segment = System.Uri(ctx.Request.Path.Value).Segments[1]
"""
[<Test>]
let ``ident and negative number should keep space, 2071`` () =
formatSourceString
false
"""
do
for i in [ maxIndex .. -1 .. startIndex ] do
stack.Push i
"""
config
|> prepend newline
|> should
equal
"""
do
for i in [ maxIndex .. -1 .. startIndex ] do
stack.Push i
"""