dry-validation 0.1.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +969 -1
- data/LICENSE +1 -1
- data/README.md +19 -286
- data/config/errors.yml +4 -35
- data/dry-validation.gemspec +38 -22
- data/lib/dry/validation/config.rb +24 -0
- data/lib/dry/validation/constants.rb +43 -0
- data/lib/dry/validation/contract/class_interface.rb +230 -0
- data/lib/dry/validation/contract.rb +173 -0
- data/lib/dry/validation/evaluator.rb +233 -0
- data/lib/dry/validation/extensions/hints.rb +67 -0
- data/lib/dry/validation/extensions/monads.rb +34 -0
- data/lib/dry/validation/extensions/predicates_as_macros.rb +75 -0
- data/lib/dry/validation/failures.rb +70 -0
- data/lib/dry/validation/function.rb +43 -0
- data/lib/dry/validation/macro.rb +38 -0
- data/lib/dry/validation/macros.rb +104 -0
- data/lib/dry/validation/message.rb +100 -0
- data/lib/dry/validation/message_set.rb +97 -0
- data/lib/dry/validation/messages/resolver.rb +129 -0
- data/lib/dry/validation/result.rb +206 -38
- data/lib/dry/validation/rule.rb +116 -106
- data/lib/dry/validation/schema_ext.rb +19 -0
- data/lib/dry/validation/values.rb +108 -0
- data/lib/dry/validation/version.rb +3 -1
- data/lib/dry/validation.rb +55 -7
- data/lib/dry-validation.rb +3 -1
- metadata +80 -106
- data/.gitignore +0 -8
- data/.rspec +0 -3
- data/.rubocop.yml +0 -16
- data/.rubocop_todo.yml +0 -7
- data/.travis.yml +0 -29
- data/Gemfile +0 -11
- data/Rakefile +0 -12
- data/examples/basic.rb +0 -21
- data/examples/nested.rb +0 -30
- data/examples/rule_ast.rb +0 -33
- data/lib/dry/validation/error.rb +0 -43
- data/lib/dry/validation/error_compiler.rb +0 -116
- data/lib/dry/validation/messages.rb +0 -71
- data/lib/dry/validation/predicate.rb +0 -39
- data/lib/dry/validation/predicate_set.rb +0 -22
- data/lib/dry/validation/predicates.rb +0 -88
- data/lib/dry/validation/rule_compiler.rb +0 -57
- data/lib/dry/validation/schema/definition.rb +0 -15
- data/lib/dry/validation/schema/key.rb +0 -39
- data/lib/dry/validation/schema/rule.rb +0 -28
- data/lib/dry/validation/schema/value.rb +0 -31
- data/lib/dry/validation/schema.rb +0 -74
- data/rakelib/rubocop.rake +0 -18
- data/spec/fixtures/errors.yml +0 -4
- data/spec/integration/custom_error_messages_spec.rb +0 -35
- data/spec/integration/custom_predicates_spec.rb +0 -57
- data/spec/integration/validation_spec.rb +0 -118
- data/spec/shared/predicates.rb +0 -31
- data/spec/spec_helper.rb +0 -18
- data/spec/unit/error_compiler_spec.rb +0 -165
- data/spec/unit/predicate_spec.rb +0 -37
- data/spec/unit/predicates/empty_spec.rb +0 -38
- data/spec/unit/predicates/eql_spec.rb +0 -21
- data/spec/unit/predicates/exclusion_spec.rb +0 -35
- data/spec/unit/predicates/filled_spec.rb +0 -38
- data/spec/unit/predicates/format_spec.rb +0 -21
- data/spec/unit/predicates/gt_spec.rb +0 -40
- data/spec/unit/predicates/gteq_spec.rb +0 -40
- data/spec/unit/predicates/inclusion_spec.rb +0 -35
- data/spec/unit/predicates/int_spec.rb +0 -34
- data/spec/unit/predicates/key_spec.rb +0 -29
- data/spec/unit/predicates/lt_spec.rb +0 -40
- data/spec/unit/predicates/lteq_spec.rb +0 -40
- data/spec/unit/predicates/max_size_spec.rb +0 -49
- data/spec/unit/predicates/min_size_spec.rb +0 -49
- data/spec/unit/predicates/nil_spec.rb +0 -28
- data/spec/unit/predicates/size_spec.rb +0 -49
- data/spec/unit/predicates/str_spec.rb +0 -32
- data/spec/unit/rule/each_spec.rb +0 -20
- data/spec/unit/rule/key_spec.rb +0 -27
- data/spec/unit/rule/set_spec.rb +0 -32
- data/spec/unit/rule/value_spec.rb +0 -42
- data/spec/unit/rule_compiler_spec.rb +0 -86
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#key?' do
|
5
|
-
let(:predicate_name) { :key? }
|
6
|
-
|
7
|
-
context 'when key is present in value' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[:name, { name: 'John' }],
|
11
|
-
[:age, { age: 18 }]
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with key is not present in value' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[:name, { age: 18 }],
|
22
|
-
[:age, { name: 'Jill' }]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_behaves_like 'a failing predicate'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#lt?' do
|
5
|
-
let(:predicate_name) { :lt? }
|
6
|
-
|
7
|
-
context 'when value is less than n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[13, 12],
|
11
|
-
[13.37, 13.36],
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when value is equal to n' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[13, 13],
|
22
|
-
[13.37, 13.37]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_behaves_like 'a failing predicate'
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with value is greater than n' do
|
30
|
-
let(:arguments_list) do
|
31
|
-
[
|
32
|
-
[13, 14],
|
33
|
-
[13.37, 13.38]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a failing predicate'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#lteq?' do
|
5
|
-
let(:predicate_name) { :lteq? }
|
6
|
-
|
7
|
-
context 'when value is less than n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[13, 12],
|
11
|
-
[13.37, 13.36]
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when value is equal to n' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[13, 13],
|
22
|
-
[13.37, 13.37]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_behaves_like 'a passing predicate'
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with value is greater than n' do
|
30
|
-
let(:arguments_list) do
|
31
|
-
[
|
32
|
-
[13, 14],
|
33
|
-
[13.37, 13.38]
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
it_behaves_like 'a failing predicate'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#max_size?' do
|
5
|
-
let(:predicate_name) { :max_size? }
|
6
|
-
|
7
|
-
context 'when value size is less than n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[3, [1, 2]],
|
11
|
-
[5, 'Jill'],
|
12
|
-
[3, { 1 => 'st', 2 => 'nd' }],
|
13
|
-
[9, 1],
|
14
|
-
[6, 1..5]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
it_behaves_like 'a passing predicate'
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when value size is equal to n' do
|
22
|
-
let(:arguments_list) do
|
23
|
-
[
|
24
|
-
[2, [1, 2]],
|
25
|
-
[4, 'Jill'],
|
26
|
-
[2, { 1 => 'st', 2 => 'nd' }],
|
27
|
-
[8, 1],
|
28
|
-
[5, 1..5]
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a passing predicate'
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'with value size is greater than n' do
|
36
|
-
let(:arguments_list) do
|
37
|
-
[
|
38
|
-
[1, [1, 2]],
|
39
|
-
[3, 'Jill'],
|
40
|
-
[1, { 1 => 'st', 2 => 'nd' }],
|
41
|
-
[7, 1],
|
42
|
-
[4, 1..5]
|
43
|
-
]
|
44
|
-
end
|
45
|
-
|
46
|
-
it_behaves_like 'a failing predicate'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#min_size?' do
|
5
|
-
let(:predicate_name) { :min_size? }
|
6
|
-
|
7
|
-
context 'when value size is greater than n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[1, [1, 2]],
|
11
|
-
[3, 'Jill'],
|
12
|
-
[1, { 1 => 'st', 2 => 'nd' }],
|
13
|
-
[7, 1],
|
14
|
-
[4, 1..5]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
it_behaves_like 'a passing predicate'
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when value size is equal to n' do
|
22
|
-
let(:arguments_list) do
|
23
|
-
[
|
24
|
-
[2, [1, 2]],
|
25
|
-
[4, 'Jill'],
|
26
|
-
[2, { 1 => 'st', 2 => 'nd' }],
|
27
|
-
[8, 1],
|
28
|
-
[5, 1..5]
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a passing predicate'
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'with value size is less than n' do
|
36
|
-
let(:arguments_list) do
|
37
|
-
[
|
38
|
-
[3, [1, 2]],
|
39
|
-
[5, 'Jill'],
|
40
|
-
[3, { 1 => 'st', 2 => 'nd' }],
|
41
|
-
[9, 1],
|
42
|
-
[6, 1..5]
|
43
|
-
]
|
44
|
-
end
|
45
|
-
|
46
|
-
it_behaves_like 'a failing predicate'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#nil?' do
|
5
|
-
let(:predicate_name) { :nil? }
|
6
|
-
|
7
|
-
context 'when value is nil' do
|
8
|
-
let(:arguments_list) { [[nil]] }
|
9
|
-
it_behaves_like 'a passing predicate'
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when value is not nil' do
|
13
|
-
let(:arguments_list) do
|
14
|
-
[
|
15
|
-
[''],
|
16
|
-
[true],
|
17
|
-
[false],
|
18
|
-
[0],
|
19
|
-
[:symbol],
|
20
|
-
[[]],
|
21
|
-
[{}],
|
22
|
-
[String]
|
23
|
-
]
|
24
|
-
end
|
25
|
-
it_behaves_like 'a failing predicate'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#size?' do
|
5
|
-
let(:predicate_name) { :size? }
|
6
|
-
|
7
|
-
context 'when value size is equal to n' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[2, [1, 2]],
|
11
|
-
[4, 'Jill'],
|
12
|
-
[2, { 1 => 'st', 2 => 'nd' }],
|
13
|
-
[8, 1],
|
14
|
-
[5, 1..5]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
it_behaves_like 'a passing predicate'
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when value size is less than n' do
|
22
|
-
let(:arguments_list) do
|
23
|
-
[
|
24
|
-
[3, [1, 2]],
|
25
|
-
[5, 'Jill'],
|
26
|
-
[3, { 1 => 'st', 2 => 'nd' }],
|
27
|
-
[9, 1],
|
28
|
-
[6, 1..5]
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
it_behaves_like 'a failing predicate'
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'with value size is greater than n' do
|
36
|
-
let(:arguments_list) do
|
37
|
-
[
|
38
|
-
[1, [1, 2]],
|
39
|
-
[3, 'Jill'],
|
40
|
-
[1, { 1 => 'st', 2 => 'nd' }],
|
41
|
-
[7, 1],
|
42
|
-
[4, 1..5]
|
43
|
-
]
|
44
|
-
end
|
45
|
-
|
46
|
-
it_behaves_like 'a failing predicate'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'dry/validation/predicates'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Predicates do
|
4
|
-
describe '#str?' do
|
5
|
-
let(:predicate_name) { :str? }
|
6
|
-
|
7
|
-
context 'when value is a string' do
|
8
|
-
let(:arguments_list) do
|
9
|
-
[
|
10
|
-
[''],
|
11
|
-
['John']
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
it_behaves_like 'a passing predicate'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with value is not a string' do
|
19
|
-
let(:arguments_list) do
|
20
|
-
[
|
21
|
-
[[]],
|
22
|
-
[{}],
|
23
|
-
[nil],
|
24
|
-
[:symbol],
|
25
|
-
[String]
|
26
|
-
]
|
27
|
-
end
|
28
|
-
|
29
|
-
it_behaves_like 'a failing predicate'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/spec/unit/rule/each_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'dry/validation/rule'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Rule::Each do
|
4
|
-
include_context 'predicates'
|
5
|
-
|
6
|
-
subject(:address_rule) do
|
7
|
-
Dry::Validation::Rule::Each.new(:name, is_string)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:is_string) { Dry::Validation::Rule::Value.new(:name, str?) }
|
11
|
-
|
12
|
-
describe '#call' do
|
13
|
-
it 'applies its rules to all elements in the input' do
|
14
|
-
expect(address_rule.(['Address'])).to be_success
|
15
|
-
|
16
|
-
expect(address_rule.([nil, 'Address'])).to be_failure
|
17
|
-
expect(address_rule.([:Address, 'Address'])).to be_failure
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/spec/unit/rule/key_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'dry/validation/rule'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Rule::Key do
|
4
|
-
include_context 'predicates'
|
5
|
-
|
6
|
-
subject(:rule) { Dry::Validation::Rule::Key.new(:name, key?) }
|
7
|
-
|
8
|
-
describe '#call' do
|
9
|
-
it 'applies predicate to the value' do
|
10
|
-
expect(rule.(name: 'Jane')).to be_success
|
11
|
-
expect(rule.({})).to be_failure
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#and' do
|
16
|
-
let(:other) { Dry::Validation::Rule::Value.new(:name, str?) }
|
17
|
-
|
18
|
-
it 'returns conjunction rule where value is passed to the right' do
|
19
|
-
present_and_string = rule.and(other)
|
20
|
-
|
21
|
-
expect(present_and_string.(name: 'Jane')).to be_success
|
22
|
-
|
23
|
-
expect(present_and_string.({})).to be_failure
|
24
|
-
expect(present_and_string.(name: 1)).to be_failure
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/spec/unit/rule/set_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'dry/validation/rule'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Rule::Set do
|
4
|
-
include_context 'predicates'
|
5
|
-
|
6
|
-
subject(:rule) do
|
7
|
-
Dry::Validation::Rule::Set.new(:address, [is_string, min_size.curry(6)])
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:is_string) { Dry::Validation::Rule::Value.new(:name, str?) }
|
11
|
-
let(:min_size) { Dry::Validation::Rule::Value.new(:name, min_size?) }
|
12
|
-
|
13
|
-
describe '#call' do
|
14
|
-
it 'applies its rules to the input' do
|
15
|
-
expect(rule.('Address')).to be_success
|
16
|
-
expect(rule.('Addr')).to be_failure
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#to_ary' do
|
21
|
-
it 'returns an array representation' do
|
22
|
-
expect(rule).to match_array([
|
23
|
-
:set, [
|
24
|
-
:address, [
|
25
|
-
[:val, [:name, [:predicate, [:str?, []]]]],
|
26
|
-
[:val, [:name, [:predicate, [:min_size?, [6]]]]]
|
27
|
-
]
|
28
|
-
]
|
29
|
-
])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'dry/validation/rule'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::Rule::Value do
|
4
|
-
include_context 'predicates'
|
5
|
-
|
6
|
-
let(:is_nil) { Dry::Validation::Rule::Value.new(:name, nil?) }
|
7
|
-
|
8
|
-
let(:is_string) { Dry::Validation::Rule::Value.new(:name, str?) }
|
9
|
-
|
10
|
-
let(:min_size) { Dry::Validation::Rule::Value.new(:name, min_size?) }
|
11
|
-
|
12
|
-
describe '#call' do
|
13
|
-
it 'returns result of a predicate' do
|
14
|
-
expect(is_string.(1)).to be_failure
|
15
|
-
expect(is_string.('1')).to be_success
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#and' do
|
20
|
-
it 'returns a conjunction' do
|
21
|
-
string_and_min_size = is_string.and(min_size.curry(3))
|
22
|
-
|
23
|
-
expect(string_and_min_size.('abc')).to be_success
|
24
|
-
expect(string_and_min_size.('abcd')).to be_success
|
25
|
-
|
26
|
-
expect(string_and_min_size.(1)).to be_failure
|
27
|
-
expect(string_and_min_size.('ab')).to be_failure
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#or' do
|
32
|
-
it 'returns a disjunction' do
|
33
|
-
nil_or_string = is_nil.or(is_string)
|
34
|
-
|
35
|
-
expect(nil_or_string.(nil)).to be_success
|
36
|
-
expect(nil_or_string.('abcd')).to be_success
|
37
|
-
|
38
|
-
expect(nil_or_string.(true)).to be_failure
|
39
|
-
expect(nil_or_string.(1)).to be_failure
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'dry/validation/rule_compiler'
|
2
|
-
|
3
|
-
RSpec.describe Dry::Validation::RuleCompiler, '#call' do
|
4
|
-
subject(:compiler) { RuleCompiler.new(predicates) }
|
5
|
-
|
6
|
-
let(:predicates) {
|
7
|
-
{ key?: predicate, filled?: predicate }
|
8
|
-
}
|
9
|
-
|
10
|
-
let(:predicate) { double(:predicate).as_null_object }
|
11
|
-
|
12
|
-
let(:key_rule) { Rule::Key.new(:email, predicate) }
|
13
|
-
let(:val_rule) { Rule::Value.new(:email, predicate) }
|
14
|
-
let(:and_rule) { key_rule & val_rule }
|
15
|
-
let(:or_rule) { key_rule | val_rule }
|
16
|
-
let(:set_rule) { Rule::Set.new(:email, [val_rule]) }
|
17
|
-
let(:each_rule) { Rule::Each.new(:email, val_rule) }
|
18
|
-
|
19
|
-
it 'compiles key rules' do
|
20
|
-
ast = [[:key, [:email, [:predicate, [:key?, predicate]]]]]
|
21
|
-
|
22
|
-
rules = compiler.(ast)
|
23
|
-
|
24
|
-
expect(rules).to eql([key_rule])
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'compiles conjunction rules' do
|
28
|
-
ast = [
|
29
|
-
[
|
30
|
-
:and, [
|
31
|
-
[:key, [:email, [:predicate, [:key?, predicate]]]],
|
32
|
-
[:val, [:email, [:predicate, [:filled?, predicate]]]]
|
33
|
-
]
|
34
|
-
]
|
35
|
-
]
|
36
|
-
|
37
|
-
rules = compiler.(ast)
|
38
|
-
|
39
|
-
expect(rules).to eql([and_rule])
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'compiles disjunction rules' do
|
43
|
-
ast = [
|
44
|
-
[
|
45
|
-
:or, [
|
46
|
-
[:key, [:email, [:predicate, [:key?, predicate]]]],
|
47
|
-
[:val, [:email, [:predicate, [:filled?, predicate]]]]
|
48
|
-
]
|
49
|
-
]
|
50
|
-
]
|
51
|
-
|
52
|
-
rules = compiler.(ast)
|
53
|
-
|
54
|
-
expect(rules).to eql([or_rule])
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'compiles set rules' do
|
58
|
-
ast = [
|
59
|
-
[
|
60
|
-
:set, [
|
61
|
-
:email, [
|
62
|
-
[:val, [:email, [:predicate, [:filled?, predicate]]]]
|
63
|
-
]
|
64
|
-
]
|
65
|
-
]
|
66
|
-
]
|
67
|
-
|
68
|
-
rules = compiler.(ast)
|
69
|
-
|
70
|
-
expect(rules).to eql([set_rule])
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'compiles each rules' do
|
74
|
-
ast = [
|
75
|
-
[
|
76
|
-
:each, [
|
77
|
-
:email, [:val, [:email, [:predicate, [:filled?, predicate]]]]
|
78
|
-
]
|
79
|
-
]
|
80
|
-
]
|
81
|
-
|
82
|
-
rules = compiler.(ast)
|
83
|
-
|
84
|
-
expect(rules).to eql([each_rule])
|
85
|
-
end
|
86
|
-
end
|