rast 0.11.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0a293b9cc0f4220d0405843c3fecfd785e864a5ed692bdb93e012d9e4fe193c
4
- data.tar.gz: fea9e6f8fc840f8a13f359247d6271a07d31bd7347e4b26a80f18c0c120bd709
3
+ metadata.gz: 810c0efa487bd01ba81b1d2cf93a99bf46ef46c7cf614ba89d0e738f11d69269
4
+ data.tar.gz: 3ab5f8339648ef7740671bdd158357daab93cd887edadd506938072d4232b4de
5
5
  SHA512:
6
- metadata.gz: 35c464882474876e96bd37b96ff77dee3b4102b8ee179be1d283b89172b57a6981ad5fb27a25d3b4bf983dab494ea63bbc9caec4fa4678b0501a4e83ada9ce65
7
- data.tar.gz: b50894ddf29e3756f7f64377227cacce683f6977e82a2d1af45dd075452e478dcfe84067e9dd773eac4a21cd7fa4a58425c05639dacbc85781cdefd896fb95fd
6
+ metadata.gz: 7232e32ecc826d7224e79a0e6d551b4d00bf7973b29c34ec9bc970f17ff58ec787a480b347fb612155b2a650fffd908ec8f1b388c8148dc16584b51ae9e5cd0c
7
+ data.tar.gz: 40e29551bba818a212168dc2a39112e28f35168b6a9164d4cdbcd4daf4f89215b3e8f0aec0a49cdc81e3ea4f0bf7d0152e1a28d64e12a1c47663887cd90b48aa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ - 0.14.0 - Introduced an else config as substitute for pair.
4
+ - 0.13.0 - Make pair in config optional for boolean result.
5
+ - 0.12.0 - Allow non-string tokens in the rules.
6
+ - 0.11.6 - WIP moved factory girl as test and development dependency.
7
+ - 0.11.5 - Change factory girl dependency
3
8
  - 0.11.4 - Fixed assert clash. Restored dependency to Factory girl.
4
9
  - 0.11.2 - Remove dependency to Factory girl from gemspec. - YANKED!
5
10
  - 0.11.1 - Add dependency to Factory girl, fixes to examples
data/Gemfile CHANGED
@@ -4,8 +4,12 @@ source 'https://rubygems.org'
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
- group :test do
7
+
8
+ group :development, :test do
8
9
  gem 'factory_girl', '~> 4.7'
10
+ end
11
+
12
+ group :test do
9
13
 
10
14
  gem 'listen', '>= 3.0.8'
11
15
  gem 'lumberjack', '~> 1.0', '>= 1.0.13'
data/Gemfile.lock CHANGED
@@ -6,46 +6,20 @@ GEM
6
6
  minitest (~> 5.1)
7
7
  thread_safe (~> 0.3, >= 0.3.4)
8
8
  tzinfo (~> 1.1)
9
- coderay (1.1.2)
10
9
  concurrent-ruby (1.1.6)
11
10
  diff-lcs (1.3)
12
11
  docile (1.1.5)
13
12
  factory_girl (4.9.0)
14
13
  activesupport (>= 3.0.0)
15
14
  ffi (1.12.2)
16
- formatador (0.2.5)
17
- guard (2.16.2)
18
- formatador (>= 0.2.4)
19
- listen (>= 2.7, < 4.0)
20
- lumberjack (>= 1.0.12, < 2.0)
21
- nenv (~> 0.1)
22
- notiffany (~> 0.0)
23
- pry (>= 0.9.12)
24
- shellany (~> 0.0)
25
- thor (>= 0.18.1)
26
- guard-compat (1.2.1)
27
- guard-rspec (4.7.3)
28
- guard (~> 2.1)
29
- guard-compat (~> 1.1)
30
- rspec (>= 2.99.0, < 4.0)
31
15
  i18n (0.9.5)
32
16
  concurrent-ruby (~> 1.0)
33
17
  listen (3.0.8)
34
18
  rb-fsevent (~> 0.9, >= 0.9.4)
35
19
  rb-inotify (~> 0.9, >= 0.9.7)
36
20
  lumberjack (1.0.13)
37
- method_source (0.9.2)
38
21
  minitest (5.12.0)
39
22
  multi_json (1.14.1)
40
- nenv (0.3.0)
41
- notiffany (0.1.3)
42
- nenv (~> 0.1)
43
- shellany (~> 0.0)
44
- pry (0.12.2)
45
- coderay (~> 1.1.0)
46
- method_source (~> 0.9.0)
47
- pry-nav (0.3.0)
48
- pry (>= 0.9.10, < 0.13.0)
49
23
  rb-fsevent (0.10.3)
50
24
  rb-inotify (0.9.10)
51
25
  ffi (>= 0.5.0, < 2)
@@ -62,13 +36,11 @@ GEM
62
36
  diff-lcs (>= 1.2.0, < 2.0)
63
37
  rspec-support (~> 3.9.0)
64
38
  rspec-support (3.9.2)
65
- shellany (0.0.1)
66
39
  simplecov (0.8.2)
67
40
  docile (~> 1.1.0)
68
41
  multi_json
69
42
  simplecov-html (~> 0.8.0)
70
43
  simplecov-html (0.8.0)
71
- thor (1.0.1)
72
44
  thread_safe (0.3.6)
73
45
  tzinfo (1.2.7)
74
46
  thread_safe (~> 0.1)
@@ -78,11 +50,8 @@ PLATFORMS
78
50
 
79
51
  DEPENDENCIES
80
52
  factory_girl (~> 4.7)
81
- guard-rspec
82
53
  listen (>= 3.0.8)
83
54
  lumberjack (~> 1.0, >= 1.0.13)
84
- pry
85
- pry-nav
86
55
  rb-inotify (~> 0.9.10)
87
56
  rspec
88
57
  simplecov (~> 0.8.2)
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Functions for detecting an enum.
4
+ module EnumModule
5
+ def enum?(back_card)
6
+ return false unless back_card.is_a?(Array) && back_card.any?
7
+
8
+ return true if ordered?(back_card) || enum_with_header?(back_card)
9
+
10
+ back_card.each { |element| return false unless element[/^[-+*]\s.*/] }
11
+
12
+ return false unless same_prefix?(back_card)
13
+
14
+ true
15
+ end
16
+
17
+ def ordered?(back_card)
18
+ back_card.each_with_index do |item, index|
19
+ return false unless item.start_with?("#{index + 1}. ")
20
+ end
21
+
22
+ true
23
+ end
24
+
25
+ private
26
+
27
+ def enum_with_header?(back_card)
28
+ return false if back_card.first[/^[-+*]\s.*/]
29
+
30
+ back_card[1..back_card.size].each { |element| return false unless element[/^[-+*]\s.*/] }
31
+
32
+ true
33
+ end
34
+
35
+ def same_prefix?(back_card)
36
+ prefix = back_card.first[0, 2]
37
+ back_card_rest = back_card - [back_card.first]
38
+ back_card_rest.all? { |list_item| list_item.start_with?(prefix) }
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Converts string into boolean
4
+ class DefaultConverter
5
+ def convert(object)
6
+ return nil if object == 'nil'
7
+
8
+ object
9
+ end
10
+ end
@@ -6,7 +6,7 @@ require 'rast/rules/rule'
6
6
  require 'rast/rules/rule_evaluator'
7
7
  require 'rast/rules/rule_validator'
8
8
 
9
- require 'rast/converters/float_converter'
9
+ require 'rast/converters/default_converter'
10
10
 
11
11
  # Generates the test parameters.
12
12
  class ParameterGenerator
@@ -101,7 +101,6 @@ class ParameterGenerator
101
101
  end
102
102
 
103
103
  def instantiate_spec(spec_config)
104
-
105
104
  if spec_config['variables'].nil?
106
105
  spec_config['variables'] = detect_variables(spec_config)
107
106
  end
@@ -112,7 +111,7 @@ class ParameterGenerator
112
111
  rule: Rule.new(rules: spec_config['rules'])
113
112
  )
114
113
 
115
- pair_config = spec_config['pair']
114
+ pair_config = calculate_pair(spec_config)
116
115
  spec.init_pair(pair_config: pair_config) unless pair_config.nil?
117
116
 
118
117
  unless spec_config['exclude'].nil?
@@ -122,12 +121,12 @@ class ParameterGenerator
122
121
  converters_config = spec_config['converters']
123
122
  converters = if converters_config.nil?
124
123
  # when no converters defined, we detect if type is consistent, otherwise assume it's string.
125
- str_converter = StrConverter.new
124
+ default_converter = DefaultConverter.new
126
125
  spec_config['variables'].map do |_key, array|
127
126
  if same_data_type(array)
128
127
  RuleEvaluator::DEFAULT_CONVERT_HASH[array.first.class]
129
128
  else
130
- str_converter
129
+ default_converter
131
130
  end
132
131
  end
133
132
  elsif converters_config.first.class == String
@@ -143,6 +142,26 @@ class ParameterGenerator
143
142
  spec.init_converters(converters: converters)
144
143
  end
145
144
 
145
+ def calculate_pair(spec_config)
146
+ pair_config = spec_config['pair']
147
+ return pair_config unless pair_config.nil?
148
+
149
+ outcomes = spec_config['rules'].keys
150
+ if outcomes.size == 1
151
+ if [TrueClass, FalseClass].include?(outcomes.first.class)
152
+ return { outcomes.first => !outcomes.first }
153
+ end
154
+
155
+ if %w[true false].include?(outcomes.first)
156
+ return { outcomes.first => outcomes.first == 'true' ? 'false' : 'true' }
157
+ end
158
+
159
+ return { outcomes.first => spec_config['else'] } if spec_config['else']
160
+ end
161
+
162
+ {}
163
+ end
164
+
146
165
  def same_data_type(array)
147
166
  type = array.first.class
148
167
  array.each do |element|
@@ -4,6 +4,7 @@ require 'rast/rules/operator'
4
4
  require 'rast/rules/logic_helper'
5
5
  require 'rast/converters/int_converter'
6
6
  require 'rast/converters/float_converter'
7
+ require 'rast/converters/default_converter'
7
8
  require 'rast/converters/bool_converter'
8
9
  require 'rast/converters/str_converter'
9
10
 
@@ -30,6 +31,7 @@ class RuleEvaluator
30
31
  Integer => IntConverter.new,
31
32
  Float => FloatConverter.new,
32
33
  Fixnum => FloatConverter.new,
34
+ Array => DefaultConverter.new,
33
35
  TrueClass => BoolConverter.new,
34
36
  FalseClass => BoolConverter.new,
35
37
  String => StrConverter.new
@@ -56,15 +58,14 @@ class RuleEvaluator
56
58
  @stack_operations.clear
57
59
  @stack_rpn.clear
58
60
 
59
- if expression.is_a?(Array)
60
- tokens = expression
61
- else
62
- tokens = RuleEvaluator.tokenize(clause: expression)
63
- end
64
-
61
+ tokens = if expression.is_a?(Array)
62
+ expression
63
+ else
64
+ RuleEvaluator.tokenize(clause: expression)
65
+ end
65
66
 
66
67
  # /* loop for handling each token - shunting-yard algorithm */
67
- tokens.each { |token| shunt_internal(token: token.strip) }
68
+ tokens.each { |token| shunt_internal(token: token) }
68
69
 
69
70
  @stack_rpn << @stack_operations.pop while @stack_operations.any?
70
71
  @stack_rpn.reverse!
@@ -105,6 +106,9 @@ class RuleEvaluator
105
106
  subscript = -1
106
107
  retval = []
107
108
  value = @stack_answer.pop
109
+
110
+ return [-1, value] if value.is_a? Array
111
+
108
112
  if TRUE != value && FALSE != value
109
113
  subscript = extract_subscript(token: value.to_s)
110
114
  value_str = value.to_s.strip
@@ -177,7 +181,7 @@ class RuleEvaluator
177
181
  # binding.pry
178
182
 
179
183
  while stack_rpn_clone.any?
180
- token = stack_rpn_clone.pop.strip
184
+ token = stack_rpn_clone.pop
181
185
  if operator?(token: token)
182
186
  if NOT.symbol == token
183
187
  evaluate_multi_not(scenario: scenario)
data/lib/rast/spec_dsl.rb CHANGED
@@ -121,7 +121,8 @@ end
121
121
  def generate_rspec(scope: nil, scenario: {}, expected: '')
122
122
  spec_params = scenario.keys.inject('') do |output, key|
123
123
  output += ', ' unless output == ''
124
- output + "#{key}: #{scenario[key]}"
124
+ calc_key = scenario[key].nil? ? nil : scenario[key]
125
+ output + "#{key}: #{calc_key}"
125
126
  end
126
127
 
127
128
  it "[#{expected}]=[#{spec_params}]" do
data/rast.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rast'
5
- spec.version = '0.11.4'
5
+ spec.version = '0.14.0'
6
6
  spec.authors = ['Royce Remulla']
7
7
  spec.email = ['royce.com@gmail.com']
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Royce Remulla
@@ -41,6 +41,7 @@ files:
41
41
  - README.md
42
42
  - examples/arithmetic_module.rb
43
43
  - examples/double_example.rb
44
+ - examples/enum_module.rb
44
45
  - examples/factory_example.rb
45
46
  - examples/logic_checker.rb
46
47
  - examples/logic_four.rb
@@ -54,6 +55,7 @@ files:
54
55
  - examples/worker.rb
55
56
  - lib/rast.rb
56
57
  - lib/rast/converters/bool_converter.rb
58
+ - lib/rast/converters/default_converter.rb
57
59
  - lib/rast/converters/float_converter.rb
58
60
  - lib/rast/converters/int_converter.rb
59
61
  - lib/rast/converters/str_converter.rb