0 people like it.

test code for the serializer

 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: 
module Serializer.Tests
open Serializer
open System
open System.IO
open System.Text

let private test datum =
    let stream = new MemoryStream()
    serialize datum stream
    stream.Position <- 0L
    deserialize stream |> printfn "%A = %A" datum

let private caption string = printfn "-- %s --" string

caption "simple discriminated union test"

type SimpleDU =
    | One
    | Two of int
    | Three of int * string * float

test One
test <| Two(42)
test <| Three(69, "bleh", 37.0101)

caption "simple discriminated union test with generic arguments"

type 'a GenericContainer(foo : 'a) =
    member val foo = foo with get, set
    private new () = GenericContainer(Unchecked.defaultof<'a>)
    override x.ToString() = foo.ToString()

type 'a AnotherGenericContainer(bar : 'a) =
    inherit GenericContainer<'a>(bar)
    private new () = AnotherGenericContainer(Unchecked.defaultof<'a>)

type 'a SimpleGenericDU =
    | One of 'a GenericContainer
    | Two of int GenericContainer
    | Three of 'a AnotherGenericContainer
    | Four of string AnotherGenericContainer

test <| One(new GenericContainer<float>(42.69))
test <| Two(new GenericContainer<int>(37))
test <| Three(new AnotherGenericContainer<string>("r00fles!"))
test <| Four(new AnotherGenericContainer<string>("meow"))

caption "discriminated union tree"

type Datum =
    | Cons of Datum * Datum
    | Symbol of string
    | Nil

test <| Cons(Symbol("Java"), Cons(Symbol("sucks"), Cons(Symbol("bigtime"), Nil)))

Console.ReadLine () |> ignore
namespace Serializer
module Tests

from Serializer
namespace System
namespace System.IO
namespace System.Text
val private test : datum:'a -> unit

Full name: Serializer.Tests.test
val datum : 'a
val stream : MemoryStream
Multiple items
type MemoryStream =
  inherit Stream
  new : unit -> MemoryStream + 6 overloads
  member CanRead : bool
  member CanSeek : bool
  member CanWrite : bool
  member Capacity : int with get, set
  member Flush : unit -> unit
  member GetBuffer : unit -> byte[]
  member Length : int64
  member Position : int64 with get, set
  member Read : buffer:byte[] * offset:int * count:int -> int
  ...

Full name: System.IO.MemoryStream

--------------------
MemoryStream() : unit
MemoryStream(capacity: int) : unit
MemoryStream(buffer: byte []) : unit
MemoryStream(buffer: byte [], writable: bool) : unit
MemoryStream(buffer: byte [], index: int, count: int) : unit
MemoryStream(buffer: byte [], index: int, count: int, writable: bool) : unit
MemoryStream(buffer: byte [], index: int, count: int, writable: bool, publiclyVisible: bool) : unit
property MemoryStream.Position: int64
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val private caption : string:string -> unit

Full name: Serializer.Tests.caption
Multiple items
val string : string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
type SimpleDU =
  | One
  | Two of int
  | Three of int * string * float

Full name: Serializer.Tests.SimpleDU
union case SimpleDU.One: SimpleDU
union case SimpleDU.Two: int -> SimpleDU
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
union case SimpleDU.Three: int * string * float -> SimpleDU
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
Multiple items
type 'a GenericContainer =
  private new : unit -> 'a GenericContainer
  new : foo:'a -> 'a GenericContainer
  override ToString : unit -> string
  member foo : 'a
  member foo : 'a with set

Full name: Serializer.Tests.GenericContainer<_>

--------------------
private new : unit -> 'a GenericContainer
new : foo:'a -> 'a GenericContainer
val foo : 'a
val set : elements:seq<'T> -> Set<'T> (requires comparison)

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.set
module Unchecked

from Microsoft.FSharp.Core.Operators
val defaultof<'T> : 'T

Full name: Microsoft.FSharp.Core.Operators.Unchecked.defaultof
val x : 'a GenericContainer
override GenericContainer.ToString : unit -> string

Full name: Serializer.Tests.GenericContainer`1.ToString
Object.ToString() : string
Multiple items
type 'a AnotherGenericContainer =
  inherit 'a GenericContainer
  private new : unit -> 'a AnotherGenericContainer
  new : bar:'a -> 'a AnotherGenericContainer

Full name: Serializer.Tests.AnotherGenericContainer<_>

--------------------
private new : unit -> 'a AnotherGenericContainer
new : bar:'a -> 'a AnotherGenericContainer
val bar : 'a
Multiple items
type 'a GenericContainer =
  private new : unit -> 'a GenericContainer
  new : foo:'a -> 'a GenericContainer
  override ToString : unit -> string
  member foo : 'a
  member foo : 'a with set

Full name: Serializer.Tests.GenericContainer<_>

--------------------
new : foo:'a -> 'a GenericContainer
type 'a SimpleGenericDU =
  | One of 'a GenericContainer
  | Two of int GenericContainer
  | Three of 'a AnotherGenericContainer
  | Four of string AnotherGenericContainer

Full name: Serializer.Tests.SimpleGenericDU<_>
union case SimpleGenericDU.One: 'a GenericContainer -> 'a SimpleGenericDU
union case SimpleGenericDU.Two: int GenericContainer -> 'a SimpleGenericDU
union case SimpleGenericDU.Three: 'a AnotherGenericContainer -> 'a SimpleGenericDU
Multiple items
type 'a AnotherGenericContainer =
  inherit 'a GenericContainer
  private new : unit -> 'a AnotherGenericContainer
  new : bar:'a -> 'a AnotherGenericContainer

Full name: Serializer.Tests.AnotherGenericContainer<_>

--------------------
new : bar:'a -> 'a AnotherGenericContainer
union case SimpleGenericDU.Four: string AnotherGenericContainer -> 'a SimpleGenericDU
type Datum =
  | Cons of Datum * Datum
  | Symbol of string
  | Nil

Full name: Serializer.Tests.Datum
union case Datum.Cons: Datum * Datum -> Datum
union case Datum.Symbol: string -> Datum
union case Datum.Nil: Datum
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
  ...

Full name: System.Console
Console.ReadLine() : string
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Raw view Test code New version

More information

Link:http://fssnip.net/9c
Posted:14 years ago
Author:
Tags: