Hoa central
Soundness.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Compiler as LUT;
40 use Hoa\File;
41 use Hoa\Iterator;
42 use Hoa\Math;
43 use Hoa\Regex;
44 use Hoa\Test;
45 
55 {
56  public function case_exaustive_json()
57  {
58  $this->with_json(
59  new LUT\Llk\Sampler\BoundedExhaustive(
60  $this->getJSONCompiler(),
61  $this->getRegexSampler(),
62  12
63  )
64  );
65  }
66 
67  public function case_coverage_json()
68  {
69  $this->with_json(
70  new LUT\Llk\Sampler\Coverage(
71  $this->getJSONCompiler(),
72  $this->getRegexSampler()
73  )
74  );
75  }
76 
77  public function case_uniform_random_json()
78  {
79  $this
80  ->given(
81  $sampler = new LUT\Llk\Sampler\Uniform(
82  $this->getJSONCompiler(),
83  $this->getRegexSampler(),
84  5
85  )
86  )
87  ->with_json(
88  new Iterator\Limit(
89  new Iterator\CallbackGenerator(function () use ($sampler) {
90  return $sampler->uniform();
91  }),
92  0,
93  1000
94  ),
95  $sampler->getCompiler()
96  );
97  }
98 
99  protected function with_json($sampler, $compiler = null)
100  {
101  if (null === $compiler) {
102  $compiler = $sampler->getCompiler();
103  }
104 
105  $this
106  ->when(function () use ($compiler, $sampler) {
107  foreach ($sampler as $datum) {
108  $this
109  ->given(json_decode($datum))
110  ->when($error = json_last_error())
111  ->then
112  ->integer($error)
113  ->isEqualTo(JSON_ERROR_NONE)
114 
115  ->when($result = $compiler->parse($datum, null, false))
116  ->then
117  ->boolean($result)
118  ->isTrue();
119  }
120  });
121  }
122 
123  protected function getJSONCompiler()
124  {
125  return LUT\Llk::load(
126  new File\Read('hoa://Library/Json/Grammar.pp')
127  );
128  }
129 
130  protected function getRegexSampler()
131  {
132  return new Regex\Visitor\Isotropic(new Math\Sampler\Random());
133  }
134 }
with_json($sampler, $compiler=null)
Definition: Soundness.php:99