guided_path 0.3.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.
- data/.document +5 -0
- data/.rvmrc +52 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +48 -0
- data/Guardfile +12 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/guided_path.gemspec +87 -0
- data/lib/guided_path/goto_node.rb +23 -0
- data/lib/guided_path/lead_in_node.rb +28 -0
- data/lib/guided_path/multimedia_node.rb +38 -0
- data/lib/guided_path/node.rb +33 -0
- data/lib/guided_path/parser/spec1.rb +206 -0
- data/lib/guided_path/program.rb +84 -0
- data/lib/guided_path/question_multiple_choice_node.rb +28 -0
- data/lib/guided_path/question_textbox_node.rb +31 -0
- data/lib/guided_path/script.rb +14 -0
- data/lib/guided_path/text_node.rb +26 -0
- data/lib/guided_path.rb +10 -0
- data/test/fixtures/spec1/empty_file.yml +0 -0
- data/test/fixtures/spec1/goto_jump_script_a.yml +7 -0
- data/test/fixtures/spec1/goto_jump_script_b.yml +6 -0
- data/test/fixtures/spec1/goto_node_jumps.yml +10 -0
- data/test/fixtures/spec1/goto_simple_jumps.yml +10 -0
- data/test/fixtures/spec1/image_captions.yml +10 -0
- data/test/fixtures/spec1/image_simple.yml +3 -0
- data/test/fixtures/spec1/leadin_multiple.yml +8 -0
- data/test/fixtures/spec1/multiple_simple.yml +5 -0
- data/test/fixtures/spec1/multiple_with_loops.yml +19 -0
- data/test/fixtures/spec1/multiple_with_sub_questions.yml +10 -0
- data/test/fixtures/spec1/sequences_three_textnodes.yml +7 -0
- data/test/fixtures/spec1/textbox_simple.yml +10 -0
- data/test/fixtures/spec1/textnode_simple_attribute_list.yml +3 -0
- data/test/fixtures/spec1/textnode_simple_hash.yml +1 -0
- data/test/fixtures/spec1/textnode_simple_string.yml +2 -0
- data/test/fixtures/spec1/yes_no_simple.yml +11 -0
- data/test/fixtures/spec1/youtube_captions.yml +10 -0
- data/test/fixtures/spec1/youtube_simple.yml +6 -0
- data/test/fixtures/test/a_fixture.yml +1 -0
- data/test/guided_path/parser/spec1/test_goto.rb +44 -0
- data/test/guided_path/parser/spec1/test_lead_in_nodes.rb +19 -0
- data/test/guided_path/parser/spec1/test_multimedia_nodes.rb +41 -0
- data/test/guided_path/parser/spec1/test_question_multiple.rb +37 -0
- data/test/guided_path/parser/spec1/test_question_textbox.rb +17 -0
- data/test/guided_path/parser/spec1/test_question_yes_no.rb +23 -0
- data/test/guided_path/parser/spec1/test_sequences.rb +22 -0
- data/test/guided_path/parser/spec1/test_text_nodes.rb +23 -0
- data/test/guided_path/program/test_program_output.rb +52 -0
- data/test/guided_path/program/test_program_script_handling.rb +29 -0
- data/test/guided_path/test_helper_functions.rb +16 -0
- data/test/guided_path/test_text_node.rb +26 -0
- data/test/helper.rb +32 -0
- metadata +280 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
module GuidedPath
|
2
|
+
class Program
|
3
|
+
|
4
|
+
attr_reader :parser, :nodes
|
5
|
+
attr_accessor :starting_node
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@parser = options[:parser] || GuidedPath::Parser::Spec1
|
9
|
+
|
10
|
+
@scripts = options[:scripts] || raise(ArgumentError, "Must specify scripts.")
|
11
|
+
raise(ArgumentError, "Scripts must be an hash") unless @scripts.kind_of?(Hash)
|
12
|
+
raise(ArgumentError, "Must pass along at least one script") if @scripts.empty?
|
13
|
+
|
14
|
+
@starting_script = options[:starting_script] || raise(ArgumentError, "Must specify starting script.")
|
15
|
+
raise(ArgumentError, "Starting script not present in script hash") unless @scripts.has_key?(@starting_script)
|
16
|
+
|
17
|
+
parse_scripts
|
18
|
+
postprocess_scripts
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def add_node(options)
|
23
|
+
script_name = options[:script_name] || raise(ArgumentError, "Script name missing")
|
24
|
+
node = options[:node] || raise(ArgumentError, "Script node")
|
25
|
+
full_label = nil
|
26
|
+
|
27
|
+
if node.next_node.kind_of?(String)
|
28
|
+
node.next_node = "#{script_name}#~##{node.next_node}".strip unless node.next_node.include?("#~#")
|
29
|
+
end
|
30
|
+
if node.label
|
31
|
+
full_label = "#{script_name}#~##{node.label}"
|
32
|
+
raise "Manually specified label #{full_label} already exists!" if nodes.has_key?(full_label)
|
33
|
+
else
|
34
|
+
begin
|
35
|
+
full_label = "#{script_name}#~##{node.class.to_s.gsub("GuidedPath::","")}~#{rand(1000000)}"
|
36
|
+
end while nodes.has_key?(full_label)
|
37
|
+
end
|
38
|
+
|
39
|
+
node.label = full_label
|
40
|
+
@nodes[full_label] = node
|
41
|
+
|
42
|
+
if @starting_node.nil? && @starting_script == script_name
|
43
|
+
@starting_node = node
|
44
|
+
end
|
45
|
+
|
46
|
+
return node
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_hash
|
50
|
+
node_hash = {}
|
51
|
+
@nodes.each_pair { |label, node| node_hash[label] = node.to_hash }
|
52
|
+
|
53
|
+
output = {:starting_node => nil }
|
54
|
+
output[:starting_node] = @starting_node.label if @starting_node
|
55
|
+
output[:nodes] = node_hash
|
56
|
+
|
57
|
+
return output
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def postprocess_scripts
|
63
|
+
# check for label based gotos and change to full nodes.
|
64
|
+
@nodes.each do |label, node|
|
65
|
+
if node.next_node.kind_of?(String)
|
66
|
+
next_node = @nodes[node.next_node]
|
67
|
+
|
68
|
+
|
69
|
+
node.next_node = next_node
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_scripts
|
75
|
+
@nodes = {}
|
76
|
+
@starting_node = nil
|
77
|
+
|
78
|
+
# parse the starting script first
|
79
|
+
@scripts.each do |script_name, script|
|
80
|
+
@parser.new(program: self, script_name: script_name, script: script)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "active_model"
|
2
|
+
require "active_support/core_ext/hash"
|
3
|
+
|
4
|
+
module GuidedPath
|
5
|
+
class QuestionMultipleChoiceNode < Node
|
6
|
+
|
7
|
+
attr_reader :text, :answers
|
8
|
+
|
9
|
+
def initialize(args = {})
|
10
|
+
super
|
11
|
+
args = args.symbolize_keys
|
12
|
+
|
13
|
+
@answers = args[:answers]
|
14
|
+
raise(ArgumentError, "Must specify answers in an Hash") unless args[:answers] && args[:answers].kind_of?(Hash)
|
15
|
+
@text = args[:text]
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
output = super
|
21
|
+
output[:type] = 'question_multiple_choice'
|
22
|
+
output[:answers] = Hash[@answers.collect { |answer,node| [answer, node.label] }]
|
23
|
+
output[:text] = @text
|
24
|
+
return output
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "active_model"
|
2
|
+
require "active_support/core_ext/hash"
|
3
|
+
|
4
|
+
module GuidedPath
|
5
|
+
class QuestionTextBoxNode < Node
|
6
|
+
|
7
|
+
attr_reader :text, :answers, :otherwise, :blank
|
8
|
+
|
9
|
+
def initialize(args = {})
|
10
|
+
super
|
11
|
+
args = args.symbolize_keys
|
12
|
+
|
13
|
+
@answers = args[:answers]
|
14
|
+
raise(ArgumentError, "Must specify answers in an Hash") unless args[:answers] && args[:answers].kind_of?(Hash)
|
15
|
+
@text = args[:text]
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
output = super
|
22
|
+
output[:type] = 'question_text_box'
|
23
|
+
output[:answers] = Hash[@answers.collect { |answer,node| [answer, node.label] }]
|
24
|
+
output[:text] = @text
|
25
|
+
return output
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "active_model"
|
2
|
+
require "active_support/core_ext/hash"
|
3
|
+
|
4
|
+
module GuidedPath
|
5
|
+
class TextNode < Node
|
6
|
+
|
7
|
+
attr_reader :value
|
8
|
+
|
9
|
+
def initialize(args = {})
|
10
|
+
super
|
11
|
+
args = args.symbolize_keys
|
12
|
+
|
13
|
+
raise(ArgumentError, "Must specify a value for the node") unless args[:value]
|
14
|
+
@value = args[:value].to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
output = super
|
20
|
+
output[:type] = 'text'
|
21
|
+
output[:value] = @value
|
22
|
+
output
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/guided_path.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
require 'guided_path/parser/spec1'
|
3
|
+
require 'guided_path/program'
|
4
|
+
require 'guided_path/node'
|
5
|
+
require 'guided_path/text_node'
|
6
|
+
require 'guided_path/goto_node'
|
7
|
+
require 'guided_path/lead_in_node'
|
8
|
+
require 'guided_path/multimedia_node'
|
9
|
+
require 'guided_path/question_textbox_node'
|
10
|
+
require 'guided_path/question_multiple_choice_node'
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
- q:
|
2
|
+
label: question
|
3
|
+
text: Choose the banana!
|
4
|
+
answers:
|
5
|
+
Banana: Yay!
|
6
|
+
Mango:
|
7
|
+
text:
|
8
|
+
value: Not acceptable.
|
9
|
+
next_node: question
|
10
|
+
- q:
|
11
|
+
label: question_mango
|
12
|
+
text: Choose the mango!
|
13
|
+
answers:
|
14
|
+
Banana:
|
15
|
+
text:
|
16
|
+
value: Not acceptable.
|
17
|
+
next_node: question_mango
|
18
|
+
Mango: Yay!
|
19
|
+
- Question done!
|
@@ -0,0 +1 @@
|
|
1
|
+
text: Welcome back!
|
@@ -0,0 +1 @@
|
|
1
|
+
test: nodes
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1Goto < MiniTest::Unit::TestCase
|
4
|
+
def load_program_with_scripts(scripts, starting_script)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: Hash[scripts.collect { |name, filename| [name, load_fixture("spec1/#{filename}")]}] , starting_script: starting_script)
|
6
|
+
end
|
7
|
+
|
8
|
+
def load_program_fixture(spec_name)
|
9
|
+
load_program_with_scripts({'test' => spec_name}, 'test')
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_simple_goto_nodes
|
14
|
+
@program = load_program_fixture("goto_simple_jumps.yml")
|
15
|
+
assert_nodes_equal @program, {TextNode => 3, GotoNode => 2}
|
16
|
+
|
17
|
+
assert_equal "Let's start here.", @program.starting_node.value
|
18
|
+
assert_kind_of GotoNode, @program.starting_node.next_node
|
19
|
+
assert_equal "Let's loop some!", @program.starting_node.next_node.next_node.value
|
20
|
+
assert_kind_of GotoNode, @program.starting_node.next_node.next_node.next_node
|
21
|
+
assert_equal "Let's start here.", @program.starting_node.next_node.next_node.next_node.next_node.value
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_simple_node_jumps
|
25
|
+
@program = load_program_fixture("goto_node_jumps.yml")
|
26
|
+
assert_nodes_equal @program, {TextNode => 3}
|
27
|
+
|
28
|
+
assert_equal "Let's start here.", @program.starting_node.value
|
29
|
+
assert_equal "Let's loop some!", @program.starting_node.next_node.value
|
30
|
+
assert_equal "Let's start here.", @program.starting_node.next_node.next_node.value
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_cross_script_jumps
|
34
|
+
@program = load_program_with_scripts({'scripta' => 'goto_jump_script_a.yml', 'scriptb' => 'goto_jump_script_b.yml'}, 'scripta')
|
35
|
+
|
36
|
+
assert_equal "Hey there!", @program.starting_node.value
|
37
|
+
assert_equal "On target!", @program.starting_node.next_node.value
|
38
|
+
assert_equal "Hey there!", @program.starting_node.next_node.next_node.next_node.value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1LeadInNodes < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_lead_in_node
|
10
|
+
@program = load_program_fixture("leadin_multiple.yml")
|
11
|
+
assert_nodes_equal @program, {LeadInNode => 1, QuestionMultipleChoiceNode => 1, TextNode => 2}
|
12
|
+
|
13
|
+
assert_kind_of LeadInNode, @program.starting_node
|
14
|
+
assert_equal "5", @program.starting_node.pause
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1MultimediaNodes < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_image_node
|
10
|
+
@program = load_program_fixture("image_simple.yml")
|
11
|
+
assert_nodes_equal @program, {MultimediaNode => 1}
|
12
|
+
assert_equal "http://businessnetworking.com/wp-content/uploads/2012/04/happy-face.jpg", @program.starting_node.url
|
13
|
+
assert_equal "image", @program.starting_node.source
|
14
|
+
|
15
|
+
@program = load_program_fixture("image_captions.yml")
|
16
|
+
assert_nodes_equal @program, {MultimediaNode => 2}
|
17
|
+
assert_equal @program.starting_node.caption, {text: "Some text", position: "bottom"}
|
18
|
+
|
19
|
+
|
20
|
+
assert_equal @program.starting_node.next_node.caption, {text: "Some text on top", position: "top"}
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_youtube_node
|
25
|
+
@program = load_program_fixture("youtube_simple.yml")
|
26
|
+
assert_nodes_equal @program, {MultimediaNode => 1}
|
27
|
+
assert_equal "http://www.youtube.com/watch?v=aHrn3-Cb3iM", @program.starting_node.url
|
28
|
+
assert_equal "youtube", @program.starting_node.source
|
29
|
+
|
30
|
+
@program = load_program_fixture("youtube_captions.yml")
|
31
|
+
assert_nodes_equal @program, {MultimediaNode => 2}
|
32
|
+
assert_equal @program.starting_node.caption, {text: "Inspiring skateboarding!", position: "bottom"}
|
33
|
+
|
34
|
+
|
35
|
+
assert_equal @program.starting_node.next_node.caption, {text: "Inspiring skateboarding!", position: "top"}
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1QuestionMultiple < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_simple_question_node
|
10
|
+
program = load_program_fixture("multiple_simple.yml")
|
11
|
+
assert_nodes_equal program, {QuestionMultipleChoiceNode => 1, TextNode => 2}
|
12
|
+
question = program.starting_node
|
13
|
+
assert_kind_of QuestionMultipleChoiceNode, question
|
14
|
+
assert_equal question.text, "How are you feeling?"
|
15
|
+
assert_equal question.to_hash[:text], "How are you feeling?"
|
16
|
+
|
17
|
+
assert_kind_of TextNode, question.answers['Unhappy']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_multiple_with_sub_questions
|
21
|
+
|
22
|
+
program = load_program_fixture("multiple_with_sub_questions.yml")
|
23
|
+
assert_nodes_equal program, {QuestionMultipleChoiceNode => 2, TextNode => 3}
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def test_multiple_with_loops
|
28
|
+
|
29
|
+
program = load_program_fixture("multiple_with_loops.yml")
|
30
|
+
assert_kind_of QuestionMultipleChoiceNode, program.starting_node.answers['Banana'].next_node
|
31
|
+
|
32
|
+
assert_equal program.starting_node.answers['Mango'].next_node, program.starting_node
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1QuestionTextBox < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_simple_textbox_node
|
10
|
+
program = load_program_fixture("textbox_simple.yml")
|
11
|
+
assert_nodes_equal program, {QuestionTextBoxNode => 1, TextNode => 5}
|
12
|
+
assert_equal "Sorry, didn't understand.", program.starting_node.answers['~not listed~'].value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1QuestionYesNo < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_simple_yes_no
|
10
|
+
program = load_program_fixture("yes_no_simple.yml")
|
11
|
+
assert_nodes_equal program, {QuestionMultipleChoiceNode => 2, TextNode => 4}
|
12
|
+
question = program.starting_node
|
13
|
+
assert_kind_of QuestionMultipleChoiceNode, question
|
14
|
+
assert_equal question.text, "Say yes?"
|
15
|
+
assert_kind_of TextNode, question.answers['Yes']
|
16
|
+
assert_kind_of QuestionMultipleChoiceNode, question.answers['Yes'].next_node
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1Sequences < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_simple_text_node
|
10
|
+
@program = load_program_fixture("sequences_three_textnodes.yml")
|
11
|
+
assert_nodes_equal @program, {TextNode => 3}
|
12
|
+
|
13
|
+
assert_equal "The beginning", @program.starting_node.value
|
14
|
+
assert_equal "The middle", @program.starting_node.next_node.value
|
15
|
+
assert_equal "The end", @program.starting_node.next_node.next_node.value
|
16
|
+
assert_equal nil, @program.starting_node.next_node.next_node.next_node
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSpec1TextNodes < MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_simple_text_node
|
10
|
+
@program = load_program_fixture("textnode_simple_string.yml")
|
11
|
+
assert_nodes_equal @program, {TextNode => 1}
|
12
|
+
|
13
|
+
@program = load_program_fixture("textnode_simple_hash.yml")
|
14
|
+
assert_nodes_equal @program, {TextNode => 1}
|
15
|
+
|
16
|
+
@program = load_program_fixture("textnode_simple_attribute_list.yml")
|
17
|
+
assert_nodes_equal @program, {TextNode => 1}
|
18
|
+
assert_equal "Welcome back!", @program.nodes.values.first.value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestProgramOuput< MiniTest::Unit::TestCase
|
4
|
+
def load_program_fixture(spec_name)
|
5
|
+
Program.new(version: GuidedPath::Parser::Spec1, scripts: {'test' => load_fixture("spec1/#{spec_name}")}, starting_script: 'test')
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_next_node(output, current_node = nil)
|
10
|
+
if current_node == nil
|
11
|
+
return output[:nodes][output[:starting_node]]
|
12
|
+
else
|
13
|
+
return output[:nodes][current_node[:next_node]]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_empty_program
|
18
|
+
@program = load_program_fixture("empty_file.yml")
|
19
|
+
|
20
|
+
assert_equal @program.to_hash, {:starting_node => nil, :nodes => {}}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_single_node
|
24
|
+
@program = load_program_fixture("textnode_simple_string.yml")
|
25
|
+
output = @program.to_hash
|
26
|
+
|
27
|
+
node = find_next_node(output)
|
28
|
+
assert_equal node[:type], 'text'
|
29
|
+
assert_equal node[:value], 'Welcome back!'
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_multiple_nodes
|
33
|
+
|
34
|
+
@program = load_program_fixture("sequences_three_textnodes.yml")
|
35
|
+
output = @program.to_hash
|
36
|
+
|
37
|
+
node = find_next_node(output)
|
38
|
+
assert_equal node[:type], 'text'
|
39
|
+
assert_equal node[:value], 'The beginning'
|
40
|
+
|
41
|
+
node = find_next_node(output, node)
|
42
|
+
assert_equal node[:type], 'text'
|
43
|
+
assert_equal node[:value], 'The middle'
|
44
|
+
|
45
|
+
node = find_next_node(output, node)
|
46
|
+
assert_equal node[:type], 'text'
|
47
|
+
assert_equal node[:value], 'The end'
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|