Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 2.59 KB

File metadata and controls

62 lines (47 loc) · 2.59 KB

Kalicz.StrongTypes.FsCheck

NuGet version Downloads License

FsCheck arbitraries for Kalicz.StrongTypes. Lets you write property tests against code that takes or returns NonEmptyString, Digit, Positive<T>, NonNegative<T>, Negative<T>, NonPositive<T>, Maybe<T>, and NonEmptyEnumerable<T> without hand-rolling generators that re-derive each type's invariants.

Install

dotnet add package Kalicz.StrongTypes.FsCheck

Register

Register everything with one attribute on your test class:

using FsCheck.Xunit;
using StrongTypes.FsCheck;

[Properties(Arbitrary = new[] { typeof(Generators) })]
public class MyTests
{
    [Property]
    public void NonEmptyString_round_trips_through_json(NonEmptyString value)
    {
        // value is guaranteed non-null, non-empty, non-whitespace
    }

    [Property]
    public void Positive_stays_positive(Positive<int> value)
    {
        Assert.True(value.Value > 0);
    }
}

What ships

Scalar strong types ship three shapes: the type itself, its nullable form (T?, ~5% null), and Maybe<T> (~5% None).

Type T T? Maybe<T>
NonEmptyString NonEmptyString NullableNonEmptyString MaybeNonEmptyString
Digit Digit NullableDigit MaybeDigit
Positive<int> PositiveInt NullablePositiveInt MaybePositiveInt
Negative<int> NegativeInt NullableNegativeInt MaybeNegativeInt
NonNegative<int> NonNegativeInt NullableNonNegativeInt MaybeNonNegativeInt
NonPositive<int> NonPositiveInt NullableNonPositiveInt MaybeNonPositiveInt

Apart from the above, you also get:

  • NonEmptyEnumerableIntNonEmptyEnumerable<int>
  • Maybe<T> for common primitives: MaybeBool, MaybeInt, MaybeLong, MaybeDouble, MaybeChar, MaybeString, MaybeGuid — all with ~5% None.

Version matches the core Kalicz.StrongTypes package you install alongside it.