Class: TestDocParser
- Inherits:
-
Object
- Object
- TestDocParser
- Defined in:
- lib/testdoc/testdocparser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #error(msg) ⇒ Object
-
#initialize(lines, filename) ⇒ TestDocParser
constructor
A new instance of TestDocParser.
- #process_checks ⇒ Object
- #process_tasks ⇒ Object
-
#process_testplan ⇒ Object
Directive ‘testplan:’ is optional, but is expected to be first.
- #process_tests ⇒ Object
- #progress(char) ⇒ Object
- #read_line ⇒ Object
Constructor Details
#initialize(lines, filename) ⇒ TestDocParser
Returns a new instance of TestDocParser.
24 25 26 27 28 29 30 |
# File 'lib/testdoc/testdocparser.rb', line 24 def initialize(lines,filename) @lines = lines @filename = filename @line_counter = 0 read_line() @progress = $stderr end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
22 23 24 |
# File 'lib/testdoc/testdocparser.rb', line 22 def @options end |
Instance Method Details
#error(msg) ⇒ Object
32 33 34 35 36 |
# File 'lib/testdoc/testdocparser.rb', line 32 def error(msg) puts @filename + ":" + @src_line_number.to_s + " Error: " + msg puts " # " + @tag.to_s + ":" + @param exit(0) end |
#process_checks ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/testdoc/testdocparser.rb', line 161 def process_checks checks = [] @checks_counter = 0 while(@tag == :check) do progress("c") check = Check.new check.title = @param check.id = (@tests_counter + 1).to_s check.id = check.id + "." + (@tasks_counter + 1).to_s check.id = check.id + "." + (@checks_counter + 1).to_s checks[@checks_counter] = check @checks_counter += 1 read_line() end return checks end |
#process_tasks ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/testdoc/testdocparser.rb', line 131 def process_tasks tasks = [] @tasks_counter = 0 if(@tag == :check) then error("Excepted 'task:' directive before 'check:' directive.") end while(@tag == :task) do progress(".") task = Task.new task.title = @param task.id = (@tests_counter + 1).to_s + "." + (@tasks_counter + 1).to_s read_line() task.checks = process_checks # # pad tree with 'empty' checks # if(task.checks.size == 0)then # checks = [] # check = Check.new # check.title = "- Empty -" # check.id = "0" # checks[0] = check # task.checks = checks # end tasks[@tasks_counter] = task @tasks_counter += 1 end return tasks end |
#process_testplan ⇒ Object
Directive ‘testplan:’ is optional, but is expected to be first.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/testdoc/testdocparser.rb', line 61 def process_testplan testplans = [] @testplans_counter = 0 if(@tag == :testplan) then testplan = TestPlan.new testplan.title = @param.split("#")[0] testplan.comments = @param.split("#")[1] read_line() else testplan = TestPlan.new end testplan.tests = process_tests() testplans[@testplans_counter] = testplan @testplans_counter += 1 # count number of tasks and checks for each test # for setting correct rowspan in html if (testplans == nil) return nil end testplans.each do |testplan| if (testplan.tests == nil) return nil end testplan.tests.each do |test| checks_tasks_count = 0 test.tasks.each do |task| if(task.checks.size == 0) checks_tasks_count += 1 end task.checks.each do |check| checks_tasks_count += 1 end end # number_of_checks is an alias for checks_tasks_count test.number_of_checks = checks_tasks_count.to_s test.checks_tasks_count = checks_tasks_count.to_s end end # return parsed testplan return testplans end |
#process_tests ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/testdoc/testdocparser.rb', line 107 def process_tests tests = [] @tests_counter = 0 if (@tag == :test) while(@tag == :test ) do progress("t") test = TestItem.new() test.title = @param test.id = (@tests_counter + 1).to_s read_line() test.tasks = process_tasks tests[@tests_counter] = test @tests_counter += 1 end return tests else progress("-") # progress("Warning: no directives found") ## error("Could not find any 'test:' directives.") return nil end end |
#progress(char) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/testdoc/testdocparser.rb', line 52 def progress(char) unless @options.quiet @progress.print(char) @progress.flush end end |
#read_line ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/testdoc/testdocparser.rb', line 38 def read_line src_line = @lines[@line_counter] if src_line == nil then @tag = "" @param = "" return false end @tag = src_line[0] @param = src_line[1] @src_line_number = src_line[2] @line_counter = @line_counter + 1 return true end |