Skip to content

Commit

Permalink
Add SatisfiesParameter to Validate.Param and Validate.ParamCollection (
Browse files Browse the repository at this point in the history
…#91)

* Add SatisfiesPredicate for Validation

Add SatisfiesPredicate for Validation for Param and ParamCollection

* Update ValidationFunctions.fs

* Update ARCExpectTests.fs

Add StatisfiedPredicate Tests

* Create validation_prototype.fsx

Add validation_prototype
  • Loading branch information
LibraChris authored Apr 19, 2024
1 parent 6bc8f0d commit b283580
Show file tree
Hide file tree
Showing 3 changed files with 635 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/ARCExpect/ValidationFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ module Validate =
|> ErrorMessage.ofIParam "is invalid."
|> Expecto.Tests.failtestNoStackf "%s"

/// <summary>
/// Validates if the given Param satisfies a predicate (meaning a function that for a given Param returns either true or false)
/// </summary>
/// <param name="predicate">The predicate that the Param should satisfy</param>
/// <param name="param">The param to validate</param>
static member SatisfiesPredicate (predicate: IParam -> bool) (param : #IParam) =
if not (predicate param) then
param
|> ErrorMessage.ofIParam "is invalid."
|> Expecto.Tests.failtestNoStackf "%s"

/// <summary>
/// Validation functions to perform on a collection containing any type implementing the `IParam` interface.
/// </summary>
Expand Down Expand Up @@ -152,6 +163,21 @@ module Validate =
|> ErrorMessage.ofIParam $"does not exist"
|> Expecto.Tests.failtestNoStackf "%s"

/// <summary>
/// Generic method to validate wether a collection of IParams satisfies any kind of predicate.
/// </summary>
/// <summary>
/// Validates whether a given predicate function returns true for the sequence of IParams.
/// </summary>
/// <param name="predicate">Function that projects the whole sequence.</param>
/// <param name="paramCollection">The param collection to validate.</param>
static member SatisfiesPredicate (predicate :#seq<#IParam> -> bool) (paramCollection : #seq<#IParam>) =
match predicate paramCollection with
| true -> ()
| false ->
ErrorMessage.ofValue $"The does not satisfy the predicate." "paramCollection"
|> Expecto.Tests.failtestNoStackf "%s"


/// <summary>
/// Validates wether the given Param's value is an email that matches a pre-defined regex pattern ("^[^@\s]+@[^@\s]+\.[^@\s]+$")
Expand All @@ -160,4 +186,6 @@ module Validate =
/// <param name="param"></param>
let email (param : #IParam) =
param |> Param.ValueMatchesRegex StringValidationPattern.email
param |> Param.TermIsEqualTo INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Email``
param |> Param.TermIsEqualTo INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Email``


Loading

0 comments on commit b283580

Please sign in to comment.