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.
Files changed (55) hide show
  1. data/.document +5 -0
  2. data/.rvmrc +52 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +48 -0
  5. data/Guardfile +12 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.rdoc +19 -0
  8. data/Rakefile +46 -0
  9. data/VERSION +1 -0
  10. data/guided_path.gemspec +87 -0
  11. data/lib/guided_path/goto_node.rb +23 -0
  12. data/lib/guided_path/lead_in_node.rb +28 -0
  13. data/lib/guided_path/multimedia_node.rb +38 -0
  14. data/lib/guided_path/node.rb +33 -0
  15. data/lib/guided_path/parser/spec1.rb +206 -0
  16. data/lib/guided_path/program.rb +84 -0
  17. data/lib/guided_path/question_multiple_choice_node.rb +28 -0
  18. data/lib/guided_path/question_textbox_node.rb +31 -0
  19. data/lib/guided_path/script.rb +14 -0
  20. data/lib/guided_path/text_node.rb +26 -0
  21. data/lib/guided_path.rb +10 -0
  22. data/test/fixtures/spec1/empty_file.yml +0 -0
  23. data/test/fixtures/spec1/goto_jump_script_a.yml +7 -0
  24. data/test/fixtures/spec1/goto_jump_script_b.yml +6 -0
  25. data/test/fixtures/spec1/goto_node_jumps.yml +10 -0
  26. data/test/fixtures/spec1/goto_simple_jumps.yml +10 -0
  27. data/test/fixtures/spec1/image_captions.yml +10 -0
  28. data/test/fixtures/spec1/image_simple.yml +3 -0
  29. data/test/fixtures/spec1/leadin_multiple.yml +8 -0
  30. data/test/fixtures/spec1/multiple_simple.yml +5 -0
  31. data/test/fixtures/spec1/multiple_with_loops.yml +19 -0
  32. data/test/fixtures/spec1/multiple_with_sub_questions.yml +10 -0
  33. data/test/fixtures/spec1/sequences_three_textnodes.yml +7 -0
  34. data/test/fixtures/spec1/textbox_simple.yml +10 -0
  35. data/test/fixtures/spec1/textnode_simple_attribute_list.yml +3 -0
  36. data/test/fixtures/spec1/textnode_simple_hash.yml +1 -0
  37. data/test/fixtures/spec1/textnode_simple_string.yml +2 -0
  38. data/test/fixtures/spec1/yes_no_simple.yml +11 -0
  39. data/test/fixtures/spec1/youtube_captions.yml +10 -0
  40. data/test/fixtures/spec1/youtube_simple.yml +6 -0
  41. data/test/fixtures/test/a_fixture.yml +1 -0
  42. data/test/guided_path/parser/spec1/test_goto.rb +44 -0
  43. data/test/guided_path/parser/spec1/test_lead_in_nodes.rb +19 -0
  44. data/test/guided_path/parser/spec1/test_multimedia_nodes.rb +41 -0
  45. data/test/guided_path/parser/spec1/test_question_multiple.rb +37 -0
  46. data/test/guided_path/parser/spec1/test_question_textbox.rb +17 -0
  47. data/test/guided_path/parser/spec1/test_question_yes_no.rb +23 -0
  48. data/test/guided_path/parser/spec1/test_sequences.rb +22 -0
  49. data/test/guided_path/parser/spec1/test_text_nodes.rb +23 -0
  50. data/test/guided_path/program/test_program_output.rb +52 -0
  51. data/test/guided_path/program/test_program_script_handling.rb +29 -0
  52. data/test/guided_path/test_helper_functions.rb +16 -0
  53. data/test/guided_path/test_text_node.rb +26 -0
  54. data/test/helper.rb +32 -0
  55. 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,14 @@
1
+ require 'active_model'
2
+
3
+ module GuidedPath
4
+ class Script
5
+
6
+ attr_accessor :start_nodes
7
+
8
+ def initialize(raw_data)
9
+ @raw_yaml = YAML.parse(raw_data)
10
+ @parse_errors = []
11
+ end
12
+
13
+ end
14
+ 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
@@ -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,7 @@
1
+ - text:
2
+ value: Hey there!
3
+ label: start
4
+ next_node: scriptb#~#target
5
+ - text:
6
+ value: Doesn't display.
7
+ label: target
@@ -0,0 +1,6 @@
1
+ - text: Also doesn't display.
2
+ - text:
3
+ value: On target!
4
+ label: target
5
+ - next_node: scripta#~#start
6
+
@@ -0,0 +1,10 @@
1
+ - text:
2
+ value: Let's start here.
3
+ label: the start
4
+ next_node: the end
5
+ - This never gets displayed.
6
+ - text:
7
+ value: Let's loop some!
8
+ label: the end
9
+ next_node: the start
10
+
@@ -0,0 +1,10 @@
1
+
2
+ - text:
3
+ value: Let's start here.
4
+ label: the start
5
+ - next_node: the end
6
+ - This never gets displayed.
7
+ - text:
8
+ value: Let's loop some!
9
+ label: the end
10
+ - next_node: the start
@@ -0,0 +1,10 @@
1
+ - image:
2
+ caption: Some text
3
+
4
+ url: http://businessnetworking.com/wp-content/uploads/2012/04/happy-face.jpg
5
+ - image:
6
+ caption:
7
+ position: top
8
+ text: Some text on top
9
+
10
+ url: http://businessnetworking.com/wp-content/uploads/2012/04/happy-face.jpg
@@ -0,0 +1,3 @@
1
+ - image:
2
+ url: http://businessnetworking.com/wp-content/uploads/2012/04/happy-face.jpg
3
+
@@ -0,0 +1,8 @@
1
+ - lead_in:
2
+ text: Close your eyes, think of the happiest thing that happened today.
3
+ pause: 5
4
+ - q:
5
+ text: How are you feeling?
6
+ answers:
7
+ Unhappy: Boo.
8
+ Happy: Yay.
@@ -0,0 +1,5 @@
1
+ - question:
2
+ text: How are you feeling?
3
+ answers:
4
+ Unhappy: Boo.
5
+ Happy: Yay.
@@ -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,10 @@
1
+ - q:
2
+ text: How are you feeling?
3
+ answers:
4
+ Happy: Yay!
5
+ Elastic:
6
+ q:
7
+ text: Are you limbs turning into taffy?
8
+ answers:
9
+ yes: Please avoid cotton candy machines.
10
+ no: Whew. Close call.
@@ -0,0 +1,7 @@
1
+ # this file tests that we can go between three simple text nodes.
2
+ # also testing that normal text node parsing works in sequences
3
+ #
4
+ - The beginning
5
+ - text: The middle
6
+ - text:
7
+ value: The end
@@ -0,0 +1,10 @@
1
+ - q:
2
+ type: textbox
3
+ text: Say yes?
4
+ answers:
5
+ Yes: :)
6
+ No: I said yes.
7
+ Yes?: Smart aleck
8
+ ~not listed~: Sorry, didn't understand.
9
+ ~blank~: Please enter something.
10
+
@@ -0,0 +1,3 @@
1
+ text:
2
+ value: Welcome back!
3
+ section_title: Quiz 2 of 4.
@@ -0,0 +1 @@
1
+ text: Welcome back!
@@ -0,0 +1,2 @@
1
+ Welcome back!
2
+
@@ -0,0 +1,11 @@
1
+ - q:
2
+ type: yes/no
3
+ text: Say yes?
4
+ yes: happy
5
+ no: sad
6
+ - yes/no q:
7
+ text: Say yes?
8
+ yes: happy happy
9
+ no: sad sad
10
+
11
+
@@ -0,0 +1,10 @@
1
+ - youtube:
2
+ url: http://www.youtube.com/watch?v=aHrn3-Cb3iM
3
+ caption: Inspiring skateboarding!
4
+ - youtube:
5
+ url: http://www.youtube.com/watch?v=aHrn3-Cb3iM
6
+ caption:
7
+ text: Inspiring skateboarding!
8
+ position: top
9
+
10
+
@@ -0,0 +1,6 @@
1
+ - youtube:
2
+ url: http://www.youtube.com/watch?v=aHrn3-Cb3iM
3
+
4
+ - video:
5
+ service: youtube
6
+ url: http://www.youtube.com/watch?v=aHrn3-Cb3iM
@@ -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
+