@@ -4,57 +4,55 @@ open System
44open System.Text .RegularExpressions
55open FSharp.Data
66open LSP.Json .Ser
7- open NUnit.Framework
87open Expecto
98
109LSP.Log.diagnosticsLog := stdout
1110
1211let removeSpace ( expected : string ) =
1312 Regex.Replace( expected, @" \s" , " " )
1413
15- [<Tests>]
1614let 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 ]
9189type 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]
0 commit comments