tataru 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tataru.rb +70 -12
- data/lib/tataru/base_resource.rb +49 -0
- data/lib/tataru/base_resource_desc.rb +35 -0
- data/lib/tataru/compiler.rb +100 -0
- data/lib/tataru/create_subroutines.rb +31 -0
- data/lib/tataru/delete_subroutines.rb +42 -0
- data/lib/tataru/flattener.rb +81 -0
- data/lib/tataru/init_hash_compiler.rb +41 -0
- data/lib/tataru/instruction.rb +52 -7
- data/lib/tataru/instruction_hash.rb +54 -0
- data/lib/tataru/instructions/call_instruction.rb +19 -0
- data/lib/tataru/instructions/check_create_instruction.rb +27 -0
- data/lib/tataru/instructions/check_delete_instruction.rb +20 -0
- data/lib/tataru/instructions/check_instruction.rb +26 -0
- data/lib/tataru/instructions/check_update_instruction.rb +27 -0
- data/lib/tataru/instructions/clear_instruction.rb +12 -0
- data/lib/tataru/instructions/compare_instruction.rb +16 -0
- data/lib/tataru/instructions/create_instruction.rb +20 -0
- data/lib/tataru/instructions/delete_instruction.rb +14 -0
- data/lib/tataru/instructions/end_instruction.rb +12 -0
- data/lib/tataru/instructions/goto_if_instruction.rb +26 -0
- data/lib/tataru/instructions/immediate_mode_instruction.rb +12 -0
- data/lib/tataru/instructions/init_instruction.rb +27 -0
- data/lib/tataru/instructions/key_instruction.rb +12 -0
- data/lib/tataru/instructions/mark_deletable_instruction.rb +13 -0
- data/lib/tataru/instructions/read_instruction.rb +28 -0
- data/lib/tataru/instructions/rescmp_instruction.rb +34 -0
- data/lib/tataru/instructions/resource_instruction.rb +15 -0
- data/lib/tataru/instructions/return_instruction.rb +16 -0
- data/lib/tataru/instructions/update_instruction.rb +16 -0
- data/lib/tataru/instructions/value_instruction.rb +15 -0
- data/lib/tataru/instructions/value_rom_instruction.rb +23 -0
- data/lib/tataru/instructions/value_update_instruction.rb +18 -0
- data/lib/tataru/memory.rb +16 -0
- data/lib/tataru/quest.rb +43 -0
- data/lib/tataru/representation.rb +22 -0
- data/lib/tataru/representations/array_representation.rb +18 -0
- data/lib/tataru/representations/hash_representation.rb +20 -0
- data/lib/tataru/representations/literal_representation.rb +9 -0
- data/lib/tataru/representations/output_representation.rb +19 -0
- data/lib/tataru/representations/resource_representation.rb +49 -0
- data/lib/tataru/resolver.rb +39 -0
- data/lib/tataru/resource_dsl.rb +21 -71
- data/lib/tataru/resource_type_pool.rb +22 -0
- data/lib/tataru/rom_reader.rb +47 -0
- data/lib/tataru/runner.rb +48 -0
- data/lib/tataru/sub_planner.rb +41 -0
- data/lib/tataru/subroutine_compiler.rb +52 -0
- data/lib/tataru/top_dsl.rb +35 -0
- data/lib/tataru/update_subroutines.rb +111 -0
- data/lib/tataru/version.rb +1 -1
- data/spec/compiler_spec.rb +181 -0
- data/spec/flattener_spec.rb +88 -0
- data/spec/init_hash_compiler_spec.rb +85 -0
- data/spec/instruction_hash_spec.rb +63 -0
- data/spec/instruction_spec.rb +36 -0
- data/spec/instructions/call_instruction_spec.rb +28 -0
- data/spec/instructions/check_create_instruction_spec.rb +67 -0
- data/spec/instructions/check_delete_instruction_spec.rb +47 -0
- data/spec/instructions/check_update_instruction_spec.rb +67 -0
- data/spec/instructions/clear_instruction_spec.rb +16 -0
- data/spec/instructions/compare_instruction_spec.rb +29 -0
- data/spec/instructions/create_instruction_spec.rb +62 -0
- data/spec/instructions/delete_instruction_spec.rb +20 -0
- data/spec/instructions/end_instruction_spec.rb +15 -0
- data/spec/instructions/goto_if_instruction_spec.rb +42 -0
- data/spec/instructions/init_instruction_spec.rb +16 -0
- data/spec/instructions/key_instruction_spec.rb +15 -0
- data/spec/instructions/mark_deletable_instruction_spec.rb +20 -0
- data/spec/instructions/read_instruction_spec.rb +34 -0
- data/spec/instructions/rescmp_instruction_spec.rb +113 -0
- data/spec/instructions/return_instruction_spec.rb +28 -0
- data/spec/instructions/update_instruction_spec.rb +39 -0
- data/spec/instructions/value_instruction_spec.rb +27 -0
- data/spec/instructions/value_rom_instruction_spec.rb +170 -0
- data/spec/instructions/value_update_instruction_spec.rb +35 -0
- data/spec/quest_spec.rb +9 -0
- data/spec/representations/array_representation_spec.rb +29 -0
- data/spec/representations/hash_representation_spec.rb +29 -0
- data/spec/representations/literal_representation_spec.rb +10 -0
- data/spec/representations/output_representation_spec.rb +11 -0
- data/spec/representations/resource_representation_spec.rb +50 -0
- data/spec/resource_dsl_spec.rb +71 -0
- data/spec/runner_spec.rb +99 -0
- data/spec/spec_helper.rb +401 -0
- data/spec/subroutine_compiler_spec.rb +39 -0
- data/spec/taru_spec.rb +616 -0
- data/spec/top_dsl_spec.rb +68 -0
- data/tataru.gemspec +45 -0
- metadata +145 -27
- data/Rakefile +0 -8
- data/lib/tataru/default_resource_finder.rb +0 -10
- data/lib/tataru/execution_step.rb +0 -79
- data/lib/tataru/planner.rb +0 -93
- data/lib/tataru/requirements.rb +0 -67
- data/lib/tataru/requirements_dsl.rb +0 -33
- data/lib/tataru/resource.rb +0 -52
- data/lib/tataru/state.rb +0 -64
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# class resource type pool
|
5
|
+
class ResourceTypePool
|
6
|
+
def initialize
|
7
|
+
@pool = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_resource_desc(symbol, classconstant)
|
11
|
+
@pool[symbol] = classconstant
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_desc_for(symbol)
|
15
|
+
@pool[symbol]
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_desc_exist?(symbol)
|
19
|
+
@pool.key? symbol
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# Reads Rom values
|
5
|
+
module RomReader
|
6
|
+
def rom
|
7
|
+
memory.hash[:rom]
|
8
|
+
end
|
9
|
+
|
10
|
+
def resolve(object)
|
11
|
+
case object[:type]
|
12
|
+
when :literal
|
13
|
+
object[:value]
|
14
|
+
when :hash
|
15
|
+
resolve_hash(object)
|
16
|
+
when :array
|
17
|
+
resolve_array(object)
|
18
|
+
when :output
|
19
|
+
resolve_output(object)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def resolve_array(object)
|
24
|
+
result = []
|
25
|
+
object[:references].each do |k, v|
|
26
|
+
result[k] = resolve(rom[v])
|
27
|
+
end
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
def resolve_hash(object)
|
32
|
+
result = {}
|
33
|
+
object[:references].each do |k, v|
|
34
|
+
result[k] = resolve(rom[v])
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
def resolve_output(object)
|
40
|
+
if object[:output] == :remote_id
|
41
|
+
memory.hash[:remote_ids][object[:resource]]
|
42
|
+
else
|
43
|
+
memory.hash[:outputs][object[:resource]][object[:output]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# thing that runs a quest
|
5
|
+
class Runner
|
6
|
+
attr_reader :memory, :oplog
|
7
|
+
|
8
|
+
def initialize(instruction_list)
|
9
|
+
@memory = Memory.new
|
10
|
+
@instruction_list = instruction_list
|
11
|
+
@oplog = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def ended?
|
15
|
+
@memory.program_counter >= @instruction_list.length ||
|
16
|
+
!@memory.error.nil? ||
|
17
|
+
@memory.end
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_operation(instr)
|
21
|
+
return unless instr.is_a? Instructions::ResourceInstruction
|
22
|
+
|
23
|
+
oplog << {
|
24
|
+
operation: instr.class.name.underscore
|
25
|
+
.sub(%r{^tataru/instructions/}, '')
|
26
|
+
.sub(/_instruction$/, '').upcase.to_s,
|
27
|
+
resource: (memory.hash[:temp][:resource_name]).to_s
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_next
|
32
|
+
return if ended?
|
33
|
+
|
34
|
+
instr = @instruction_list[@memory.program_counter]
|
35
|
+
|
36
|
+
log_operation(instr)
|
37
|
+
|
38
|
+
instr.execute(@memory)
|
39
|
+
@memory.program_counter += 1
|
40
|
+
rescue RuntimeError => e
|
41
|
+
@memory.error = e
|
42
|
+
rescue StandardError => e
|
43
|
+
@memory.error = e
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_state; end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# returns subroutines required based on the resource
|
5
|
+
class SubPlanner
|
6
|
+
def initialize(rrep, action)
|
7
|
+
@rrep = rrep
|
8
|
+
@action = action
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
@rrep.name
|
13
|
+
end
|
14
|
+
|
15
|
+
def compile(*args)
|
16
|
+
SubroutineCompiler.new(@rrep, *args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def extra_subroutines
|
20
|
+
return {} unless @action == :update
|
21
|
+
|
22
|
+
{
|
23
|
+
"#{name}_modify" => compile(:modify),
|
24
|
+
"#{name}_modify_check" => compile(:modify_check),
|
25
|
+
"#{name}_recreate" => compile(:recreate),
|
26
|
+
"#{name}_recreate_check" => compile(:recreate_check),
|
27
|
+
"#{name}_recreate_commit" => compile(:recreate_commit),
|
28
|
+
"#{name}_recreate_finish" => compile(:recreate_finish)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def subroutines
|
33
|
+
{
|
34
|
+
"#{name}_start" => compile(:"#{@action}"),
|
35
|
+
"#{name}_check" => compile(:"check_#{@action}"),
|
36
|
+
"#{name}_commit" => compile(:"commit_#{@action}"),
|
37
|
+
"#{name}_finish" => compile(:"finish_#{@action}")
|
38
|
+
}.merge(extra_subroutines)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# a subroutine for handling a resource
|
5
|
+
class SubroutineCompiler
|
6
|
+
include CreateSubroutines
|
7
|
+
include UpdateSubroutines
|
8
|
+
include DeleteSubroutines
|
9
|
+
|
10
|
+
def initialize(resource_representation, action)
|
11
|
+
@rrep = resource_representation
|
12
|
+
@action = action
|
13
|
+
end
|
14
|
+
|
15
|
+
def desc
|
16
|
+
@rrep.desc
|
17
|
+
end
|
18
|
+
|
19
|
+
def label
|
20
|
+
"#{@action}_#{@rrep.name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_action
|
24
|
+
@action.to_s.split('_')[1].to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def body_instructions
|
28
|
+
[
|
29
|
+
:clear,
|
30
|
+
*inner_instructions,
|
31
|
+
:return
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_resource_instructions
|
36
|
+
[
|
37
|
+
{ key: :resource_name },
|
38
|
+
{ value: @rrep.name },
|
39
|
+
{ key: :resource_desc },
|
40
|
+
{ value: @rrep.desc.class.name }
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
def inner_instructions
|
45
|
+
send :"#{@action}_instructions"
|
46
|
+
end
|
47
|
+
|
48
|
+
def call_instruction
|
49
|
+
{ call: label }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# human representation of resources
|
5
|
+
class TopDsl
|
6
|
+
attr_reader :resources
|
7
|
+
|
8
|
+
def initialize(pool)
|
9
|
+
@resources = {}
|
10
|
+
@pool = pool
|
11
|
+
end
|
12
|
+
|
13
|
+
def resource(symbol, name, &block)
|
14
|
+
unless @pool.resource_desc_exist?(symbol)
|
15
|
+
raise "no such resource: #{symbol}"
|
16
|
+
end
|
17
|
+
raise "already defined: #{name}" if @resources.key? name
|
18
|
+
|
19
|
+
resource = ResourceDsl.new(name, @pool.resource_desc_for(symbol).new)
|
20
|
+
resource.instance_eval(&block) if block
|
21
|
+
|
22
|
+
@resources[name] = resource.representation
|
23
|
+
end
|
24
|
+
|
25
|
+
def dep_graph
|
26
|
+
@resources.map do |name, resource_representation|
|
27
|
+
deps = Set.new
|
28
|
+
resource_representation.properties.each do |_key, value|
|
29
|
+
deps += value.dependencies
|
30
|
+
end
|
31
|
+
[name, deps.to_a]
|
32
|
+
end.to_h
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tataru
|
4
|
+
# update subroutines
|
5
|
+
module UpdateSubroutines
|
6
|
+
def update_instructions
|
7
|
+
[
|
8
|
+
*load_resource_instructions,
|
9
|
+
:read,
|
10
|
+
*load_resource_instructions,
|
11
|
+
:rescmp,
|
12
|
+
{ value_update: @rrep.name },
|
13
|
+
{ compare: :recreate },
|
14
|
+
{ goto_if: "recreate_#{@rrep.name}" },
|
15
|
+
{ value_update: @rrep.name },
|
16
|
+
{ compare: :modify },
|
17
|
+
{ goto_if: "modify_#{@rrep.name}" }
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_update_instructions
|
22
|
+
[
|
23
|
+
{ value_update: @rrep.name },
|
24
|
+
{ compare: :recreate },
|
25
|
+
{ goto_if: "recreate_check_#{@rrep.name}" },
|
26
|
+
{ value_update: @rrep.name },
|
27
|
+
{ compare: :modify },
|
28
|
+
{ goto_if: "modify_check_#{@rrep.name}" }
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def commit_update_instructions
|
33
|
+
[
|
34
|
+
{ value_update: @rrep.name },
|
35
|
+
{ compare: :recreate },
|
36
|
+
{ goto_if: "recreate_commit_#{@rrep.name}" }
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def finish_update_instructions
|
41
|
+
[
|
42
|
+
{ value_update: @rrep.name },
|
43
|
+
{ compare: :recreate },
|
44
|
+
{ goto_if: "recreate_finish_#{@rrep.name}" }
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
def modify_instructions
|
49
|
+
[
|
50
|
+
*load_resource_instructions,
|
51
|
+
{ key: :properties },
|
52
|
+
{ value_rom: @rrep.name },
|
53
|
+
:update
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
def modify_check_instructions
|
58
|
+
[
|
59
|
+
*load_resource_instructions,
|
60
|
+
:check_update
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
def recreate_instructions
|
65
|
+
deletion_routine = [
|
66
|
+
*load_resource_instructions,
|
67
|
+
:mark_deletable
|
68
|
+
]
|
69
|
+
unless desc.delete_at_end?
|
70
|
+
deletion_routine = [
|
71
|
+
*delete_instructions,
|
72
|
+
*check_delete_instructions
|
73
|
+
]
|
74
|
+
end
|
75
|
+
[
|
76
|
+
*deletion_routine,
|
77
|
+
*create_instructions
|
78
|
+
]
|
79
|
+
end
|
80
|
+
|
81
|
+
def recreate_check_instructions
|
82
|
+
[
|
83
|
+
*check_create_instructions
|
84
|
+
]
|
85
|
+
end
|
86
|
+
|
87
|
+
def recreate_commit_instructions
|
88
|
+
return [] unless desc.delete_at_end?
|
89
|
+
|
90
|
+
[
|
91
|
+
{ key: :resource_name },
|
92
|
+
{ value: "_deletable_#{@rrep.name}" },
|
93
|
+
{ key: :resource_desc },
|
94
|
+
{ value: @rrep.desc.class.name },
|
95
|
+
:delete
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
def recreate_finish_instructions
|
100
|
+
return [] unless desc.delete_at_end?
|
101
|
+
|
102
|
+
[
|
103
|
+
{ key: :resource_name },
|
104
|
+
{ value: "_deletable_#{@rrep.name}" },
|
105
|
+
{ key: :resource_desc },
|
106
|
+
{ value: @rrep.desc.class.name },
|
107
|
+
:check_delete
|
108
|
+
]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/tataru/version.rb
CHANGED
@@ -0,0 +1,181 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Compiler do
|
6
|
+
it 'outputs the correct default format' do
|
7
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
8
|
+
compiler = Tataru::Compiler.new(dsl)
|
9
|
+
expect(compiler.instr_hash).to eq(
|
10
|
+
init: {
|
11
|
+
labels: {},
|
12
|
+
remote_ids: {},
|
13
|
+
rom: {}
|
14
|
+
},
|
15
|
+
instructions: [:init, :end]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'outputs top instructions and subroutine instructions' do
|
20
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
21
|
+
compiler = Tataru::Compiler.new(dsl)
|
22
|
+
|
23
|
+
allow(compiler).to receive(:top_instructions) { [:meow] }
|
24
|
+
allow(compiler).to receive(:subroutine_instructions) { [:woof] }
|
25
|
+
|
26
|
+
expect(compiler.instr_hash).to eq(
|
27
|
+
init: {
|
28
|
+
labels: {},
|
29
|
+
remote_ids: {},
|
30
|
+
rom: {}
|
31
|
+
},
|
32
|
+
instructions: [:meow, :woof]
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'wraps instructions with init and end' do
|
37
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
38
|
+
compiler = Tataru::Compiler.new(dsl)
|
39
|
+
|
40
|
+
allow(compiler).to receive(:generate_top_instructions) { [:meow] }
|
41
|
+
|
42
|
+
expect(compiler.top_instructions).to eq [:init, :meow, :end]
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'makes all the subroutine instructions mixed in' do
|
46
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
47
|
+
compiler = Tataru::Compiler.new(dsl)
|
48
|
+
|
49
|
+
a = double('SubroutineCompiler')
|
50
|
+
b = double('SubroutineCompiler')
|
51
|
+
|
52
|
+
allow(a).to receive(:body_instructions) { [:meow, :purr] }
|
53
|
+
allow(b).to receive(:body_instructions) { [:pant, :woof] }
|
54
|
+
allow(compiler).to receive(:subroutines) { {a: a, b: b} }
|
55
|
+
|
56
|
+
expect(compiler.subroutine_instructions).to eq [:meow, :purr, :pant, :woof]
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'assigns the correct numbers to labels' do
|
60
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
61
|
+
compiler = Tataru::Compiler.new(dsl)
|
62
|
+
|
63
|
+
a = double('SubroutineCompiler')
|
64
|
+
b = double('SubroutineCompiler')
|
65
|
+
|
66
|
+
allow(a).to receive(:body_instructions) { [:meow, :purr, :drink_milk] }
|
67
|
+
allow(b).to receive(:body_instructions) { [:pant, :woof] }
|
68
|
+
|
69
|
+
allow(a).to receive(:label) { :cat }
|
70
|
+
allow(b).to receive(:label) { :dog }
|
71
|
+
|
72
|
+
allow(compiler).to receive(:subroutines) { {a: a, b: b} }
|
73
|
+
|
74
|
+
expect(compiler.generate_labels).to eq(cat: 2, dog: 5)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'generates the right subroutines' do
|
78
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
79
|
+
compiler = Tataru::Compiler.new(dsl)
|
80
|
+
|
81
|
+
dummy = double('SubroutineCompiler')
|
82
|
+
allow(dummy).to receive(:call_instruction)
|
83
|
+
|
84
|
+
dummy_subroutine_hash = double('Hash')
|
85
|
+
allow(compiler).to receive(:subroutines) { dummy_subroutine_hash }
|
86
|
+
|
87
|
+
allow(dsl).to receive(:dep_graph) { { a: [:b], c: [:b], b: [] } }
|
88
|
+
|
89
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('b_start') { dummy }
|
90
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('b_check') { dummy }
|
91
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('b_commit') { dummy }
|
92
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('b_finish') { dummy }
|
93
|
+
|
94
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('a_start') { dummy }
|
95
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('a_check') { dummy }
|
96
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('a_commit') { dummy }
|
97
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('a_finish') { dummy }
|
98
|
+
|
99
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('c_start') { dummy }
|
100
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('c_check') { dummy }
|
101
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('c_commit') { dummy }
|
102
|
+
expect(dummy_subroutine_hash).to receive(:[]).with('c_finish') { dummy }
|
103
|
+
|
104
|
+
compiler.generate_top_instructions
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'generates create instructions by default' do
|
108
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
109
|
+
compiler = Tataru::Compiler.new(dsl)
|
110
|
+
|
111
|
+
cat = Tataru::Representations::ResourceRepresentation.new('ccat', Tataru::BaseResourceDesc.new, {})
|
112
|
+
dog = Tataru::Representations::ResourceRepresentation.new('ddog', Tataru::BaseResourceDesc.new, {})
|
113
|
+
allow(dsl).to receive(:resources) do
|
114
|
+
{
|
115
|
+
'cat' => cat,
|
116
|
+
'dog' => dog
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(cat, :create)
|
121
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(cat, :check_create)
|
122
|
+
|
123
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(cat, :commit_create)
|
124
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(cat, :finish_create)
|
125
|
+
|
126
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :create)
|
127
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :check_create)
|
128
|
+
|
129
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :commit_create)
|
130
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :finish_create)
|
131
|
+
|
132
|
+
expect(compiler.generate_subroutines.keys).to eq [
|
133
|
+
'ccat_start', 'ccat_check', 'ccat_commit', 'ccat_finish',
|
134
|
+
'ddog_start', 'ddog_check', 'ddog_commit', 'ddog_finish'
|
135
|
+
]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'generates delete instructions for extant names' do
|
139
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
140
|
+
compiler = Tataru::Compiler.new(dsl, { 'thing' => 'BaseResourceDesc' })
|
141
|
+
|
142
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(instance_of(Tataru::Representations::ResourceRepresentation), :delete)
|
143
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(instance_of(Tataru::Representations::ResourceRepresentation), :check_delete)
|
144
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(instance_of(Tataru::Representations::ResourceRepresentation), :commit_delete)
|
145
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(instance_of(Tataru::Representations::ResourceRepresentation), :finish_delete)
|
146
|
+
|
147
|
+
expect(compiler.generate_subroutines.keys).to eq [
|
148
|
+
'thing_start', 'thing_check', 'thing_commit', 'thing_finish'
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'generates update instructions for extant names that are set' do
|
153
|
+
dsl = Tataru::TopDsl.new(Tataru::ResourceTypePool.new)
|
154
|
+
compiler = Tataru::Compiler.new(dsl, { 'thong' => 'BaseResourceDesc' })
|
155
|
+
|
156
|
+
dog = Tataru::Representations::ResourceRepresentation.new('ddog', Tataru::BaseResourceDesc.new, {})
|
157
|
+
allow(dsl).to receive(:resources) do
|
158
|
+
{
|
159
|
+
'thong' => dog
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :update)
|
164
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :check_update)
|
165
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :commit_update)
|
166
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :finish_update)
|
167
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :modify)
|
168
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :modify_check)
|
169
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :recreate)
|
170
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :recreate_check)
|
171
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :recreate_commit)
|
172
|
+
expect(Tataru::SubroutineCompiler).to receive(:new).with(dog, :recreate_finish)
|
173
|
+
|
174
|
+
expect(compiler.generate_subroutines.keys).to eq [
|
175
|
+
'ddog_start', 'ddog_check', 'ddog_commit', 'ddog_finish',
|
176
|
+
'ddog_modify', 'ddog_modify_check',
|
177
|
+
'ddog_recreate', 'ddog_recreate_check',
|
178
|
+
'ddog_recreate_commit', 'ddog_recreate_finish'
|
179
|
+
]
|
180
|
+
end
|
181
|
+
end
|