Skip to content

Commit 9f719a6

Browse files
committed
Add F# collections test.
1 parent a68758e commit 9f719a6

8 files changed

Lines changed: 979 additions & 0 deletions

test/MsgPack.UnitTest.BclExtensions/MsgPack.UnitTest.BclExtensions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<AssemblyOriginatorKeyFile>..\..\src\MsgPack.snk</AssemblyOriginatorKeyFile>
4040
</PropertyGroup>
4141
<ItemGroup>
42+
<Reference Include="FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
4243
<Reference Include="nunit.framework, Version=3.2.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
4344
<HintPath>..\..\packages\NUnit.3.2.1\lib\net45\nunit.framework.dll</HintPath>
4445
<Private>True</Private>

test/MsgPack.UnitTest.BclExtensions/Serialization/ArrayCodeDomBasedCustomCollectionSerializersTest.cs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
using MsgPack.Serialization.CodeDomSerializers;
3333
using MsgPack.Serialization.EmittingSerializers;
3434
#endif // SILVERLIGHT && !NETSTANDARD1_1 && !NETSTANDARD1_3
35+
#if !NETFX_CORE
36+
using Microsoft.FSharp.Collections;
37+
#endif // !NETFX_CORE
3538
#if !MSTEST
3639
using NUnit.Framework;
3740
#else
@@ -555,5 +558,155 @@ public void ImmutableSortedDictionaryTest_2_Success()
555558
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
556559
}
557560
}
561+
562+
#if !NETFX_CORE
563+
564+
565+
[Test]
566+
public void FSharpListTest_0_Success()
567+
{
568+
var collection = FSharpList<int>.Empty;
569+
var target = this.CreateTarget<FSharpList<int>>();
570+
using ( var buffer = new MemoryStream() )
571+
{
572+
target.Pack( buffer, collection );
573+
buffer.Position = 0;
574+
var unpacked = target.Unpack( buffer );
575+
buffer.Position = 0;
576+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
577+
}
578+
}
579+
580+
[Test]
581+
public void FSharpListTest_1_Success()
582+
{
583+
var collection = FSharpList<int>.Empty;
584+
collection = new FSharpList<int>( 0, collection );
585+
var target = this.CreateTarget<FSharpList<int>>();
586+
using ( var buffer = new MemoryStream() )
587+
{
588+
target.Pack( buffer, collection );
589+
buffer.Position = 0;
590+
var unpacked = target.Unpack( buffer );
591+
buffer.Position = 0;
592+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
593+
}
594+
}
595+
596+
[Test]
597+
public void FSharpListTest_2_Success()
598+
{
599+
var collection = FSharpList<int>.Empty;
600+
collection = new FSharpList<int>( 0, collection );
601+
collection = new FSharpList<int>( 1, collection );
602+
var target = this.CreateTarget<FSharpList<int>>();
603+
using ( var buffer = new MemoryStream() )
604+
{
605+
target.Pack( buffer, collection );
606+
buffer.Position = 0;
607+
var unpacked = target.Unpack( buffer );
608+
buffer.Position = 0;
609+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
610+
}
611+
}
612+
613+
[Test]
614+
public void FSharpSetTest_0_Success()
615+
{
616+
var collection = new FSharpSet<int>( Enumerable.Empty<int>() );
617+
var target = this.CreateTarget<FSharpSet<int>>();
618+
using ( var buffer = new MemoryStream() )
619+
{
620+
target.Pack( buffer, collection );
621+
buffer.Position = 0;
622+
var unpacked = target.Unpack( buffer );
623+
buffer.Position = 0;
624+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
625+
}
626+
}
627+
628+
[Test]
629+
public void FSharpSetTest_1_Success()
630+
{
631+
var collection = new FSharpSet<int>( Enumerable.Empty<int>() );
632+
collection = collection.Add( 0 );
633+
var target = this.CreateTarget<FSharpSet<int>>();
634+
using ( var buffer = new MemoryStream() )
635+
{
636+
target.Pack( buffer, collection );
637+
buffer.Position = 0;
638+
var unpacked = target.Unpack( buffer );
639+
buffer.Position = 0;
640+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
641+
}
642+
}
643+
644+
[Test]
645+
public void FSharpSetTest_2_Success()
646+
{
647+
var collection = new FSharpSet<int>( Enumerable.Empty<int>() );
648+
collection = collection.Add( 0 );
649+
collection = collection.Add( 1 );
650+
var target = this.CreateTarget<FSharpSet<int>>();
651+
using ( var buffer = new MemoryStream() )
652+
{
653+
target.Pack( buffer, collection );
654+
buffer.Position = 0;
655+
var unpacked = target.Unpack( buffer );
656+
buffer.Position = 0;
657+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
658+
}
659+
}
660+
661+
[Test]
662+
public void FSharpMapTest_0_Success()
663+
{
664+
var collection = new FSharpMap<int, int>( Enumerable.Empty<Tuple<int, int>>() );
665+
var target = this.CreateTarget<FSharpMap<int, int>>();
666+
using ( var buffer = new MemoryStream() )
667+
{
668+
target.Pack( buffer, collection );
669+
buffer.Position = 0;
670+
var unpacked = target.Unpack( buffer );
671+
buffer.Position = 0;
672+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
673+
}
674+
}
675+
676+
[Test]
677+
public void FSharpMapTest_1_Success()
678+
{
679+
var collection = new FSharpMap<int, int>( Enumerable.Empty<Tuple<int, int>>() );
680+
collection = collection.Add( 0, 0 );
681+
var target = this.CreateTarget<FSharpMap<int, int>>();
682+
using ( var buffer = new MemoryStream() )
683+
{
684+
target.Pack( buffer, collection );
685+
buffer.Position = 0;
686+
var unpacked = target.Unpack( buffer );
687+
buffer.Position = 0;
688+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
689+
}
690+
}
691+
692+
[Test]
693+
public void FSharpMapTest_2_Success()
694+
{
695+
var collection = new FSharpMap<int, int>( Enumerable.Empty<Tuple<int, int>>() );
696+
collection = collection.Add( 0, 0 );
697+
collection = collection.Add( 1, 1 );
698+
var target = this.CreateTarget<FSharpMap<int, int>>();
699+
using ( var buffer = new MemoryStream() )
700+
{
701+
target.Pack( buffer, collection );
702+
buffer.Position = 0;
703+
var unpacked = target.Unpack( buffer );
704+
buffer.Position = 0;
705+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
706+
}
707+
}
708+
709+
#endif // !NETFX_CORE
710+
558711
}
559712
}

test/MsgPack.UnitTest.BclExtensions/Serialization/ArrayFieldBasedCustomCollectionSerializersTest.cs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
using MsgPack.Serialization.CodeDomSerializers;
3333
using MsgPack.Serialization.EmittingSerializers;
3434
#endif // SILVERLIGHT && !NETSTANDARD1_1 && !NETSTANDARD1_3
35+
#if !NETFX_CORE
36+
using Microsoft.FSharp.Collections;
37+
#endif // !NETFX_CORE
3538
#if !MSTEST
3639
using NUnit.Framework;
3740
#else
@@ -555,5 +558,155 @@ public void ImmutableSortedDictionaryTest_2_Success()
555558
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
556559
}
557560
}
561+
562+
#if !NETFX_CORE
563+
564+
565+
[Test]
566+
public void FSharpListTest_0_Success()
567+
{
568+
var collection = FSharpList<int>.Empty;
569+
var target = this.CreateTarget<FSharpList<int>>();
570+
using ( var buffer = new MemoryStream() )
571+
{
572+
target.Pack( buffer, collection );
573+
buffer.Position = 0;
574+
var unpacked = target.Unpack( buffer );
575+
buffer.Position = 0;
576+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
577+
}
578+
}
579+
580+
[Test]
581+
public void FSharpListTest_1_Success()
582+
{
583+
var collection = FSharpList<int>.Empty;
584+
collection = new FSharpList<int>( 0, collection );
585+
var target = this.CreateTarget<FSharpList<int>>();
586+
using ( var buffer = new MemoryStream() )
587+
{
588+
target.Pack( buffer, collection );
589+
buffer.Position = 0;
590+
var unpacked = target.Unpack( buffer );
591+
buffer.Position = 0;
592+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
593+
}
594+
}
595+
596+
[Test]
597+
public void FSharpListTest_2_Success()
598+
{
599+
var collection = FSharpList<int>.Empty;
600+
collection = new FSharpList<int>( 0, collection );
601+
collection = new FSharpList<int>( 1, collection );
602+
var target = this.CreateTarget<FSharpList<int>>();
603+
using ( var buffer = new MemoryStream() )
604+
{
605+
target.Pack( buffer, collection );
606+
buffer.Position = 0;
607+
var unpacked = target.Unpack( buffer );
608+
buffer.Position = 0;
609+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
610+
}
611+
}
612+
613+
[Test]
614+
public void FSharpSetTest_0_Success()
615+
{
616+
var collection = new FSharpSet<int>( Enumerable.Empty<int>() );
617+
var target = this.CreateTarget<FSharpSet<int>>();
618+
using ( var buffer = new MemoryStream() )
619+
{
620+
target.Pack( buffer, collection );
621+
buffer.Position = 0;
622+
var unpacked = target.Unpack( buffer );
623+
buffer.Position = 0;
624+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
625+
}
626+
}
627+
628+
[Test]
629+
public void FSharpSetTest_1_Success()
630+
{
631+
var collection = new FSharpSet<int>( Enumerable.Empty<int>() );
632+
collection = collection.Add( 0 );
633+
var target = this.CreateTarget<FSharpSet<int>>();
634+
using ( var buffer = new MemoryStream() )
635+
{
636+
target.Pack( buffer, collection );
637+
buffer.Position = 0;
638+
var unpacked = target.Unpack( buffer );
639+
buffer.Position = 0;
640+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
641+
}
642+
}
643+
644+
[Test]
645+
public void FSharpSetTest_2_Success()
646+
{
647+
var collection = new FSharpSet<int>( Enumerable.Empty<int>() );
648+
collection = collection.Add( 0 );
649+
collection = collection.Add( 1 );
650+
var target = this.CreateTarget<FSharpSet<int>>();
651+
using ( var buffer = new MemoryStream() )
652+
{
653+
target.Pack( buffer, collection );
654+
buffer.Position = 0;
655+
var unpacked = target.Unpack( buffer );
656+
buffer.Position = 0;
657+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
658+
}
659+
}
660+
661+
[Test]
662+
public void FSharpMapTest_0_Success()
663+
{
664+
var collection = new FSharpMap<int, int>( Enumerable.Empty<Tuple<int, int>>() );
665+
var target = this.CreateTarget<FSharpMap<int, int>>();
666+
using ( var buffer = new MemoryStream() )
667+
{
668+
target.Pack( buffer, collection );
669+
buffer.Position = 0;
670+
var unpacked = target.Unpack( buffer );
671+
buffer.Position = 0;
672+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
673+
}
674+
}
675+
676+
[Test]
677+
public void FSharpMapTest_1_Success()
678+
{
679+
var collection = new FSharpMap<int, int>( Enumerable.Empty<Tuple<int, int>>() );
680+
collection = collection.Add( 0, 0 );
681+
var target = this.CreateTarget<FSharpMap<int, int>>();
682+
using ( var buffer = new MemoryStream() )
683+
{
684+
target.Pack( buffer, collection );
685+
buffer.Position = 0;
686+
var unpacked = target.Unpack( buffer );
687+
buffer.Position = 0;
688+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
689+
}
690+
}
691+
692+
[Test]
693+
public void FSharpMapTest_2_Success()
694+
{
695+
var collection = new FSharpMap<int, int>( Enumerable.Empty<Tuple<int, int>>() );
696+
collection = collection.Add( 0, 0 );
697+
collection = collection.Add( 1, 1 );
698+
var target = this.CreateTarget<FSharpMap<int, int>>();
699+
using ( var buffer = new MemoryStream() )
700+
{
701+
target.Pack( buffer, collection );
702+
buffer.Position = 0;
703+
var unpacked = target.Unpack( buffer );
704+
buffer.Position = 0;
705+
Assert.That( unpacked.ToArray(), Is.EqualTo( collection.ToArray() ) );
706+
}
707+
}
708+
709+
#endif // !NETFX_CORE
710+
558711
}
559712
}

0 commit comments

Comments
 (0)