Skip to content

bravobike/validated_struct_generators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ValidatedStructGenerators

Tests Hex version badge

This module provides stream data generators for validated structs.

For a validated struct a stream data generator can be created using &ValidatedStruct.Generator.generator_for/2.

Installation

The package can be installed by adding validated_struct_generators to your list of dependencies in mix.exs:

def deps do
  [
    {:validated_struct_generators, "~> 0.0.2"}
  ]
end

Example

ValidatedStruct.Generator.generator_for(MyStruct)

Options for generator_for/2

We can provide opts, to influence a generators behaviour:

  • :use_defaults? (default: false) uses the default values of a validated struct, instead of generating values

  • type-based opts (available: :binary, :float, :integer, :atom, :list, :nonempty_list) which are passed to the StreamData generators. These hold for all occurances of the type in the structs.

    Example: ValidatedStruct.Generator.generator_for(MyStruct, [list: [length: 1]])

  • field-based opts - we can define the behaviour of concrete field. To do so, we put the field names with either :opts, :const or :generator into the :fields option as so:

    Example: ValidatedStruct.Generator.generator_for(MyStruct, [fields: [repairments: [opts: [length: 1]]]])

    We can either pass opts to the respective generators, or define our own generator:

    Example: ValidatedStruct.Generator.generator_for(MyStruct, [fields: [repairments: [generator: StreamData.constant([])]]])

    The :const keyword is a convienience option for [bike_id: StreamData.constant(my_bike_id)]

    Example: ValidatedStruct.Generator.generator_for(MyStruct, [fields: [bike_id: [const: my_bike_id]]])

    Example: ValidatedStruct.Generator.generator_for(MyStruct, [fields: [repairments: [generator: StreamData.constant([])]]])

    To recursively control fields in member structs, we can always place another fields-opts beside opts or generator.

About

Stream data generators for validated structs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages