Class: JSON::Fuzz::Generator::Keyword::Enum

Inherits:
Object
  • Object
show all
Defined in:
lib/json/fuzz/generator/keyword/enum.rb

Class Method Summary collapse

Class Method Details

.invalid_params(attributes) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json/fuzz/generator/keyword/enum.rb', line 7

def invalid_params(attributes)
  attributes = Marshal.load(Marshal.dump(attributes))
  enum = attributes.delete("enum")
  raise "No enum keyword given: #{attributes}" unless enum

  generated_params = []
  JSON::Fuzz::Generator::PrimitiveType.type_to_class_map.each do |type, klass|
    klass.invalid_params(attributes).each do |invalid_param|
      generated_params << invalid_param unless enum.include?(invalid_param)
    end
  end

  generated_params.empty? ? [nil] : generated_params
end

.valid_param(attributes) ⇒ Object



22
23
24
25
26
27
# File 'lib/json/fuzz/generator/keyword/enum.rb', line 22

def valid_param(attributes)
  enum = attributes["enum"]
  raise "No enum keyword given: #{attributes}" unless enum

  enum.sample
end