Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct Generator generates normal Map #7

Open
maennchen opened this issue Jan 22, 2017 · 0 comments
Open

Struct Generator generates normal Map #7

maennchen opened this issue Jan 22, 2017 · 0 comments

Comments

@maennchen
Copy link

I have a relatively complex generator (which is not even complete by now).

@cron_expression_value list(of:
  choose(from: [
    value(:*),
    int(),
    tuple(like: {value(:L), int()})
  ]
), min: 1, max: 3)

test "parse & compose gets the same struct" do
  ptest [cron_expression: Pollution.VG.struct(%Crontab.CronExpression{
    extended: value(false),
    reboot: value(false),
    second: value([:*]),
    minute: @cron_expression_value,
    hour: @cron_expression_value,
    day: @cron_expression_value,
    month: @cron_expression_value,
    weekday: @cron_expression_value,
    year: @cron_expression_value
  })] do
    IO.inspect cron_expression
    cron_string = Crontab.CronExpression.Composer.compose(cron_expression)
    assert Crontab.CronExpression.Parser.parse!(cron_string, false) == cron_expression
  end
end

I expect this code to always generate the cron_expression property as a struct of Crontab.CronExpression.

$ mix test
.............................................................................................~e[* 0L,0 0L,-1L 0L 0,*,0L *]
~e[* 0L,0 0L,-1L 0L 0,*,0L *]
%{day: [L: 0, L: -1], extended: false, hour: [{:L, 0}, 0], minute: [:*],
  month: [L: 0], reboot: false, second: [:*], weekday: [0, :*, {:L, 0}],
  year: [:*]}


  1) test parse & compose gets the same struct (Crontab.FunctionalTest)
     test/crontab/functional_test.exs:140
     ** (FunctionClauseError) no function clause matching in Crontab.CronExpression.Composer.compose/1
     stacktrace:
       (crontab) lib/crontab/cron_expression/composer.ex:26: Crontab.CronExpression.Composer.compose(%{day: [L: 0, L: -1], extended: false, hour: [{:L, 0}, 0], minute: [:*], month: [L: 0], reboot: false, second: [:*], weekday: [0, :*, {:L, 0}], year: [:*]})
       test/crontab/functional_test.exs:153: anonymous fn/1 in Crontab.FunctionalTest.test parse & compose gets the same struct/1
       lib/pollution/shrinker.ex:41: Pollution.Shrinker.shrink/3
       lib/quixir/shrinker.ex:48: Quixir.Shrinker.try_to_shrink/2
       lib/quixir/shrinker.ex:31: Quixir.Shrinker.start_shrink/1
       test/crontab/functional_test.exs:141: anonymous fn/2 in Crontab.FunctionalTest.test parse & compose gets the same struct/1
       (elixir) lib/enum.ex:1785: Enum.reduce_range_inc/4
       test/crontab/functional_test.exs:141: (test)

....................................

Finished in 0.4 seconds
130 tests, 1 failure

Randomized with seed 522066

The output shows, that in some cases the cron_expression is just a map and not of type struct Crontab.CronExpression.

I'm not certain, that I did everything correct, but it seems like an error to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant