Skip to content

Commit 57e0729

Browse files
committed
Discovered a bunch of tests i hadn't convested to expecto and that were not running.
1 parent 480054a commit 57e0729

2 files changed

Lines changed: 42 additions & 46 deletions

File tree

‎tests/Expecto/LSP/JsonTests.fs‎

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,55 @@ open System
44
open System.Text.RegularExpressions
55
open FSharp.Data
66
open LSP.Json.Ser
7-
open NUnit.Framework
87
open Expecto
98

109
LSP.Log.diagnosticsLog := stdout
1110

1211
let removeSpace(expected: string) =
1312
Regex.Replace(expected, @"\s", "")
1413

15-
[<Tests>]
1614
let tests=
1715
testList "Json Tests" [
1816
test "remove space from string"{
1917
let found = removeSpace("foo bar")
20-
Assert.AreEqual("foobar", found)
18+
Expect.equal "foobar" found "fail"
2119
}
2220

2321
test "remove newline from string"{
2422
let actual = """foo
2523
bar"""
2624
let found = removeSpace(actual)
27-
Assert.AreEqual("foobar", found)
25+
Expect.equal "foobar" found "fail"
2826
}
2927

3028
test "serialize primitive types to JSON"{
3129
let found = serializerFactory<bool> defaultJsonWriteOptions true
32-
Assert.AreEqual("true", found)
30+
Expect.equal "true" found "fail"
3331
let found = serializerFactory<int> defaultJsonWriteOptions 1
34-
Assert.AreEqual("1", found)
32+
Expect.equal "1" found "fail"
3533
let found = serializerFactory<string> defaultJsonWriteOptions "foo"
36-
Assert.AreEqual("\"foo\"", found)
34+
Expect.equal "\"foo\"" found "fail"
3735
let found = serializerFactory<char> defaultJsonWriteOptions 'f'
38-
Assert.AreEqual("\"f\"", found)
36+
Expect.equal "\"f\"" found "fail"
3937
}
4038

4139
test "serialize URI to JSON"{
4240
let example = Uri("https://google.com")
4341
let found = serializerFactory<Uri> defaultJsonWriteOptions example
44-
Assert.AreEqual("\"https://google.com/\"", found)
42+
Expect.equal "\"https://google.com/\"" found "fail"
4543
}
4644

4745
test "serialize JsonValue to JSON"{
4846
let example = JsonValue.Parse "{}"
4947
let found = serializerFactory<JsonValue> defaultJsonWriteOptions example
50-
Assert.AreEqual("{}", found)
48+
Expect.equal "{}" found "fail"
5149
}
5250

5351
test "serialize option to JSON"{
5452
let found = serializerFactory<int option> defaultJsonWriteOptions (Some 1)
55-
Assert.AreEqual("1", found)
53+
Expect.equal "1" found "fail"
5654
let found = serializerFactory<int option> defaultJsonWriteOptions (None)
57-
Assert.AreEqual("null", found)
55+
Expect.equal "null" found "fail"
5856
}
5957
]
6058

@@ -65,27 +63,27 @@ let tests2=
6563
test "serialize record to JSON"{
6664
let record = {simpleMember = 1}
6765
let found = serializerFactory<SimpleRecord> defaultJsonWriteOptions record
68-
Assert.AreEqual("""{"simpleMember":1}""", found)
66+
Expect.equal """{"simpleMember":1}""" found "fail"
6967
}
7068

7169
test "serialize list of ints to JSON"{
7270
let example = [1; 2]
7371
let found = serializerFactory<int list> defaultJsonWriteOptions example
74-
Assert.AreEqual("""[1,2]""", found)
72+
Expect.equal """[1,2]""" found "fail"
7573
}
7674

7775
test "serialize list of strings to JSON"{
7876
let example = ["foo"; "bar"]
7977
let found = serializerFactory<string list> defaultJsonWriteOptions example
80-
Assert.AreEqual("""["foo","bar"]""", found)
78+
Expect.equal """["foo","bar"]""" found "fail"
8179
}
8280

8381
test "serialize a record with a custom writer"{
8482
let record = {simpleMember = 1}
8583
let customWriter(r: SimpleRecord): string = sprintf "simpleMember=%d" r.simpleMember
8684
let options = {defaultJsonWriteOptions with customWriters = [customWriter]}
8785
let found = serializerFactory<SimpleRecord> options record
88-
Assert.AreEqual("\"simpleMember=1\"", found)
86+
Expect.equal "\"simpleMember=1\"" found "fail"
8987
}
9088
]
9189
type Foo = Bar | Doh
@@ -100,7 +98,7 @@ let tests3 =
10098
| Doh -> 20
10199
let options = {defaultJsonWriteOptions with customWriters = [customWriter]}
102100
let found = serializerFactory<FooRecord> options record
103-
Assert.AreEqual("""{"foo":10}""", found)
101+
Expect.equal """{"foo":10}""" found "fail"
104102
}
105103
]
106104
// type UnionWithFields =
@@ -164,9 +162,9 @@ let tests4 =
164162
let options = {defaultJsonWriteOptions with customWriters = [customWriter]}
165163
let example = MyFoo()
166164
let found = serializerFactory<IFoo> options example
167-
Assert.AreEqual("\"foo\"", found)
165+
Expect.equal "\"foo\"" found "fail"
168166
let found = serializerFactory<MyFoo> options example
169-
Assert.AreEqual("\"foo\"", found)
167+
Expect.equal "\"foo\"" found "fail"
170168
}
171169

172170

@@ -182,12 +180,12 @@ let tests4 =
182180
}"""
183181
let options = defaultJsonReadOptions
184182
let found = deserializerFactory<SimpleTypes> options (JsonValue.Parse sample)
185-
Assert.AreEqual(true, found.b)
186-
Assert.AreEqual(1, found.i)
187-
Assert.AreEqual('x', found.c)
188-
Assert.AreEqual("foo", found.s)
189-
Assert.AreEqual(Uri("https://github.com"), found.webUri)
190-
Assert.AreEqual("d:\\foo.txt", found.fileUri.LocalPath)
183+
Expect.equal true found.b "fail"
184+
Expect.equal 1 found.i "fail"
185+
Expect.equal 'x' found.c "fail"
186+
Expect.equal "foo" found.s "fail"
187+
Expect.equal (Uri("https://github.com")) found.webUri "fail"
188+
Expect.equal "d:\\foo.txt" found.fileUri.LocalPath "fail"
191189
}
192190

193191

@@ -204,39 +202,39 @@ let tests4 =
204202
}"""
205203
let options = defaultJsonReadOptions
206204
let found = deserializerFactory<ComplexTypes> options (JsonValue.Parse sample)
207-
Assert.AreEqual({oneField=1}, found.nested)
208-
Assert.AreEqual(1, found.stringAsInt)
209-
Assert.AreEqual([1], found.intList)
210-
Assert.AreEqual(Some 1, found.intOptionPresent)
211-
Assert.AreEqual(None, found.intOptionAbsent)
205+
Expect.equal {oneField=1} found.nested "fail"
206+
Expect.equal 1 found.stringAsInt "fail"
207+
Expect.equal [1] found.intList "fail"
208+
Expect.equal (Some 1) found.intOptionPresent "fail"
209+
Expect.equal None found.intOptionAbsent "fail"
212210
}
213211

214212

215213
test "deserialize optional types"{
216214
let options = defaultJsonReadOptions
217215
let found = deserializerFactory<TestOptionalRead> options (JsonValue.Parse """{"optionField":1}""")
218-
Assert.AreEqual({optionField=Some 1}, found)
216+
Expect.equal {optionField=Some 1} found "fail"
219217
let found = deserializerFactory<TestOptionalRead> options (JsonValue.Parse """{"optionField":null}""")
220-
Assert.AreEqual({optionField=None}, found)
218+
Expect.equal {optionField=None} found "fail"
221219
let found = deserializerFactory<TestOptionalRead> options (JsonValue.Parse """{}""")
222-
Assert.AreEqual({optionField=None}, found)
220+
Expect.equal {optionField=None} found "fail"
223221
let found = deserializerFactory<int option list> options (JsonValue.Parse """[1]""")
224-
Assert.AreEqual([Some 1], found)
222+
Expect.equal [Some 1] found "fail"
225223
let found = deserializerFactory<int option list> options (JsonValue.Parse """[null]""")
226224
let noneIntList: int option list=[None]
227-
Assert.AreEqual(noneIntList, found)
225+
Expect.equal noneIntList found "fail"
228226
}
229227

230228
test "deserialize map"{
231229
let options = defaultJsonReadOptions
232230
let found = deserializerFactory<Map<string, int>> options (JsonValue.Parse """{"k":1}""")
233231
let map = Map.add "k" 1 Map.empty
234-
Assert.AreEqual(map, found)
232+
Expect.equal map found "fail"
235233
}
236234

237235
test "deserialize enum"{
238236
let options = { defaultJsonReadOptions with customReaders = [deserializeTestEnum]}
239237
let found = deserializerFactory<ContainsEnum> options (JsonValue.Parse """{"e":1}""")
240-
Assert.AreEqual(One, found.e)
238+
Expect.equal One found.e "fail"
241239
}
242240
]

‎tests/Expecto/LSP/LanguageServerTests.fs‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ open System.Text
66
open FSharp.Data
77
open LSP.Types
88
open LSP.SemanticToken
9-
open NUnit.Framework
109
open SemanticToken
1110
open Expecto
1211

@@ -20,14 +19,13 @@ let binaryWriter() =
2019
Encoding.UTF8.GetString(bytes)
2120
writer, toString
2221

23-
[<Tests>]
2422
let tests =
2523
testList "language server Tests" [
2624
test "write text"{
2725
let writer, toString = binaryWriter()
2826
writer.Write(Encoding.UTF8.GetBytes "foo")
2927
let found = toString()
30-
Assert.AreEqual("foo", found)
28+
Expect.equal "foo" found "Wrong text"
3129
}
3230

3331
test "write response"{
@@ -36,7 +34,7 @@ let tests =
3634
let expected = "Content-Length: 35\r\n\r\n\
3735
{\"id\":1,\"jsonrpc\":\"2.0\",\"result\":2}"
3836
let found = toString()
39-
Assert.AreEqual(expected, found)
37+
Expect.equal expected found "wrong response"
4038
}
4139

4240
test "write multibyte characters"{
@@ -45,7 +43,7 @@ let tests =
4543
let expected = "Content-Length: 38\r\n\r\n\
4644
{\"id\":1,\"jsonrpc\":\"2.0\",\"result\":🔥}"
4745
let found = toString()
48-
Assert.AreEqual(expected, found)
46+
Expect.equal expected found "wrong text"
4947
}
5048
]
5149
let TODO() = raise (Exception "TODO")
@@ -131,22 +129,22 @@ let tests2 =
131129
let stdin = messageStream [initializeMessage]
132130
let messages = LanguageServer.readMessages(stdin)
133131
let found = Seq.toList(messages)
134-
Assert.AreEqual([Parser.RequestMessage(1, "initialize", JsonValue.Parse "{}")], found)
132+
Expect.equal [Parser.RequestMessage(1, "initialize", JsonValue.Parse "{}")] found "stream not terminated"
135133
}
136134

137135

138136
test "exit message terminates stream"{
139137
let stdin = messageStream [initializeMessage; exitMessage; initializeMessage]
140138
let messages = LanguageServer.readMessages(stdin)
141139
let found = Seq.toList messages
142-
Assert.AreEqual([Parser.RequestMessage(1, "initialize", JsonValue.Parse "{}")], found)
140+
Expect.equal [Parser.RequestMessage(1, "initialize", JsonValue.Parse "{}")] found "stream not terminated"
143141
}
144142

145143
test "end of bytes terminates stream"{
146144
let stdin = messageStream [initializeMessage]
147145
let messages = LanguageServer.readMessages(stdin)
148146
let found = Seq.toList messages
149-
Assert.AreEqual([Parser.RequestMessage(1, "initialize", JsonValue.Parse "{}")], found)
147+
Expect.equal [Parser.RequestMessage(1, "initialize", JsonValue.Parse "{}")] found "stream not terminated"
150148
}
151149
test "send Initialize"{
152150
let message = """
@@ -159,6 +157,6 @@ let tests2 =
159157
"""
160158
let server = MockServer()
161159
let result = mock server [message]
162-
if not (result.Contains("capabilities")) then Assert.Fail(sprintf "%A does not contain capabilities" result)
160+
if not (result.Contains("capabilities")) then failtestf "%A does not contain capabilities" result
163161
}
164162
]

0 commit comments

Comments
 (0)