git @ Cat's Eye Technologies Falderal / 3737669
All doctests pass once again! Chris Pressey 6 years ago
1 changed file(s) with 26 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
271271 # TODO: interpret this according to the new, not-yet-written rules.
272272 return []
273273 else:
274 if pattern_prefixes in [[u'= '], [u'? ']]:
275 raise FalderalSyntaxError(
276 ("line %d: " % self.line_num) +
277 "expectation must be preceded by test body or test input")
278
279 if pattern_prefixes in [[u'| ']]:
280 raise FalderalSyntaxError(
281 ("line %d: " % self.line_num) +
282 "test body must be followed by expectation or test input")
283
274284 valid_patterns = [
275285 [u'->'],
276286 [u'> '],
285295 return [self.PREFIX_MAP[prefix](line_num=self.line_num, filename=self.filename, lines=lines) for (prefix, lines) in pattern]
286296 raise FalderalSyntaxError(
287297 ("line %d: " % self.line_num) +
288 "test block must consist of test body and/or test input, then expectation, in that order")
298 "incorrectly formatted test block")
289299
290300
291301 class LiterateCode(Block):
431441 >>> d = Document()
432442 >>> d.append(u'This is a test file.')
433443 >>> d.append(u' -> Tests for functionality "Parse Thing"')
444 >>> d.append(u'')
434445 >>> d.append(u" | This is some test body.")
435446 >>> d.append(u" | It extends over two lines.")
436447 >>> d.append(u' ? Expected Error')
448 >>> d.append(u'')
437449 >>> d.append(u' | Test with input')
438450 >>> d.append(u' + input-for-test')
439451 >>> d.append(u' = Expected result on output')
452 >>> d.append(u'')
440453 >>> d.append(u' + Other input-for-test')
441454 >>> d.append(u' = Other Expected result on output')
455 >>> d.append(u'')
442456 >>> d.append(u' -> Tests for functionality "Run Thing"')
457 >>> d.append(u'')
443458 >>> d.append(u" | Thing")
444459 >>> d.append(u' ? Oops')
445460 >>> d.parse_lines_to_blocks()
452467 [u'This is some test body.\nIt extends over two lines.',
453468 u'Test with input', u'Test with input', u'Thing']
454469 >>> [t.input_block for t in tests]
455 [None, TestInput(u' + ', line_num=7, filename=None),
456 TestInput(u' + ', line_num=9, filename=None), None]
470 [None, TestInput(line_num=8), TestInput(line_num=12), None]
457471 >>> tests[1].input_block.text()
458472 u'input-for-test'
459473 >>> tests[2].input_block.text()
474488 >>> d.parse_blocks_to_tests({})
475489 Traceback (most recent call last):
476490 ...
477 FalderalSyntaxError: line 2: functionality under test not specified
491 FalderalSyntaxError: line 1: functionality under test not specified
478492
479493 >>> d = Document()
480494 >>> d.append(u'This is a test file.')
490504 >>> d.parse_blocks_to_tests({})
491505 Traceback (most recent call last):
492506 ...
493 FalderalSyntaxError: line 2: expectation must be preceded by test body or test input
507 FalderalSyntaxError: line 1: incorrectly formatted test block
494508
495509 >>> d = Document()
496510 >>> d.append(u' | This is test')
498512 >>> d.parse_blocks_to_tests({})
499513 Traceback (most recent call last):
500514 ...
501 FalderalSyntaxError: line 2: test body must be followed by expectation or test input
515 FalderalSyntaxError: line 1: test body must be followed by expectation or test input
502516
503517 >>> d = Document()
504518 >>> d.append(u' -> Hello, this is pragma')
506520 >>> d.parse_blocks_to_tests({})
507521 Traceback (most recent call last):
508522 ...
509 FalderalSyntaxError: line 2: test input must be preceded by test body
523 FalderalSyntaxError: line 1: incorrectly formatted test block
510524
511525 >>> d = Document()
512526 >>> funs = {}
825839
826840 TODO: maybe write a helper function for that instead.
827841
828 >>> b = TestBody(u' | ')
829 >>> b.append(u' | foo')
830 >>> b.append(u' | bar')
831 >>> i = TestInput(u' + ')
832 >>> i.append(u' + green')
842 >>> b = TestBody()
843 >>> b.append(u'foo')
844 >>> b.append(u'bar')
845 >>> i = TestInput()
846 >>> i.append(u'green')
833847 >>> t = Test(body_block=b, input_block=i)
834848 >>> print t.body
835849 foo