Class: TestCaseGenerator::DSLContext

Inherits:
Object
  • Object
show all
Defined in:
lib/test_case_generator/dsl_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSLContext

Returns a new instance of DSLContext.



8
9
10
11
12
13
14
# File 'lib/test_case_generator/dsl_context.rb', line 8

def initialize
  @patterns = []
  @before = []
  @after = []
  @children = []
  @labels = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/test_case_generator/dsl_context.rb', line 5

def children
  @children
end

#labelsObject (readonly)

Returns the value of attribute labels.



6
7
8
# File 'lib/test_case_generator/dsl_context.rb', line 6

def labels
  @labels
end

Instance Method Details

#<<(events) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/test_case_generator/dsl_context.rb', line 16

def <<(events)
  if events.is_a?(String) || events.is_a?(Symbol)
    @patterns << [events]
    @labels << events unless @labels.include? events
  else
    @patterns << events
    events.each do |label|
      @labels << label unless @labels.include? label
    end
  end
end

#after {|@after| ... } ⇒ Object

Yields:



36
37
38
# File 'lib/test_case_generator/dsl_context.rb', line 36

def after
  yield @after
end

#before {|@before| ... } ⇒ Object

Yields:



32
33
34
# File 'lib/test_case_generator/dsl_context.rb', line 32

def before
  yield @before
end

#concat(&block) ⇒ Object Also known as: seq



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/test_case_generator/dsl_context.rb', line 54

def concat(&block)
  child_context = DSLContext.new
  child_context.instance_eval &block

  first = true
  tmp = []
  child_context.children.each do |ctx|
    tmp2 = []
    ctx.raw_each do |ptn|
      if first
        tmp2 << ptn
      else
        tmp.each do |x|
          tmp2 << x + ptn
        end
      end
    end

    tmp = tmp2
    first = false
  end

  tmp.each do |x|
    @patterns << x
    x.each do |label|
      @labels << label unless @labels.include? label
    end
  end
end

#def_labels {|@labels| ... } ⇒ Object

Yields:



28
29
30
# File 'lib/test_case_generator/dsl_context.rb', line 28

def def_labels
  yield @labels
end

#eachObject



134
135
136
137
138
139
140
141
142
143
# File 'lib/test_case_generator/dsl_context.rb', line 134

def each
  raw_each do |raw_ptn|
    yield raw_ptn.map { |p|
      # p.to_s.split('_').inject([]) { |buffer, e|
      #   buffer << (buffer.empty? ? e : e.capitalize)
      # }.join
      TestCaseGenerator::Utils.make_method_name p
    }
  end
end

#parallel(&block) ⇒ Object Also known as: para



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/test_case_generator/dsl_context.rb', line 85

def parallel(&block)
  child_context = DSLContext.new
  child_context.instance_eval &block

  first = true
  tmp = []
  child_context.children.each do |ctx|
    tmp2 = []
    ctx.raw_each do |ptn|
      if first
        tmp2 << ptn
      else
        tmp.each do |x|
          (0..x.length + ptn.length - 1).to_a.combination(x.length) do |index_arr|
            x_index = 0
            ptn_index = 0
            tmp2 << (0..x.length + ptn.length - 1).map do |i|
              if index_arr.include?(i)
                ret = x[x_index]
                x_index += 1
              else
                ret = ptn[ptn_index]
                ptn_index += 1
              end

              ret
            end
          end
        end
      end
    end

    tmp = tmp2
    first = false
  end

  tmp.each do |x|
    @patterns << x
    x.each do |label|
      @labels << label unless @labels.include? label
    end
  end
end

#pattern {|child_context| ... } ⇒ Object Also known as: choice

Yields:

  • (child_context)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/test_case_generator/dsl_context.rb', line 40

def pattern
  child_context = DSLContext.new
  yield child_context
  @children << child_context

  child_context.raw_each do |ptn|
    @patterns << ptn
    ptn.each do |label|
      @labels << label unless @labels.include? label
    end
  end
end

#raw_eachObject



130
131
132
# File 'lib/test_case_generator/dsl_context.rb', line 130

def raw_each
  @patterns.each { |ptn| yield @before + ptn + @after }
end