View Source Noizu.ElixirCore.PartialObjectCheck.ValueConstraint (noizu_core v1.0.28)

The ValueConstraint struct represents a value constraint for a field. It holds the actual value constraint, which can be a specific value, a POC struct (for nested assertions), or a list of constraints. The ValueConstraint is used as part of the FieldConstraint to define the expected value of a field.

The perform_check/2 function within the ValueConstraint module performs the actual value constraint check against the subject under test.

Link to this section Summary

Functions

Performs the value constraint check against the subject under test. The perform_check/2 function takes the value constraint and the subject under test (sut) and checks if the sut satisfies the constraint. It returns a tuple containing the result of the check (:met, :unmet, or :pending) and the updated constraint.

Link to this section Types

@type t() :: %Noizu.ElixirCore.PartialObjectCheck.ValueConstraint{
  assert: :met | :unmet | :pending | :not_applicable,
  constraint: nil | {:value, any()} | list() | (... -> any())
}

Link to this section Functions

Link to this function

perform_check(value_constraint, subject_under_test)

View Source

Performs the value constraint check against the subject under test. The perform_check/2 function takes the value constraint and the subject under test (sut) and checks if the sut satisfies the constraint. It returns a tuple containing the result of the check (:met, :unmet, or :pending) and the updated constraint.

examples

Examples

iex> constraint = {:value, 42} iex> Noizu.ElixirCore.PartialObjectCheck.ValueConstraint.perform_check(constraint, 42) {:met, {:value, 42}}

iex> constraint = {:value, 42} iex> Noizu.ElixirCore.PartialObjectCheck.ValueConstraint.perform_check(constraint, 50) {:unmet, {:value, 42}}

iex> constraint = %Noizu.ElixirCore.PartialObjectCheck{field_constraints: %{a: %Noizu.ElixirCore.PartialObjectCheck.FieldConstraint{required: true, value_constraint: %Noizu.ElixirCore.PartialObjectCheck.ValueConstraint{constraint: {:value, 1}}}}} iex> Noizu.ElixirCore.PartialObjectCheck.ValueConstraint.perform_check(constraint, %{a: 1}) {:met, %Noizu.ElixirCore.PartialObjectCheck{assert: :met, field_constraints: %{a: %Noizu.ElixirCore.PartialObjectCheck.FieldConstraint{assert: :met, required: true, value_constraint: %Noizu.ElixirCore.PartialObjectCheck.ValueConstraint{assert: :met, constraint: {:value, 1}}}}}}