git @ Cat's Eye Technologies Falderal / 7d97f0e
Remove PREFIXES_MAP and make all tests pass once again. Chris Pressey 6 years ago
1 changed file(s) with 24 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
201201 self.lines = lines
202202 self.line_num = line_num
203203 self.filename = filename
204 self.PREFIX_MAP = {
205 u'| ': TestBody,
206 u'+ ': TestInput,
207 u'? ': ExpectedError,
208 u'= ': ExpectedResult,
209 u'->': Pragma,
210 u'> ': LiterateCode,
211 }
212 self.PREFIXES = self.PREFIX_MAP.keys()
204 self.PREFIXES = [
205 u'| ',
206 u'+ ',
207 u'? ',
208 u'= ',
209 u'->',
210 ]
213211 self.VALID_PATTERNS = [
214212 [u'->'],
215213 [u'> '],
279277 def classify(self, state):
280278 """Return the Test or Pragma that this Block represents."""
281279
282 def make_block_from_pattern(pattern, prefix):
280 def make_block_from_pattern(cls, pattern, prefix):
283281 lines = None
284282 for (candidate_prefix, candidate_lines) in pattern:
285283 if candidate_prefix == prefix:
287285 break
288286 if lines is None:
289287 return None
290 return self.PREFIX_MAP[prefix](line_num=self.line_num, filename=self.filename, lines=lines)
288 return cls(line_num=self.line_num, filename=self.filename, lines=lines)
291289
292290 pattern = self.deconstruct()
293291 pattern_prefixes = [p[0] for p in pattern]
323321 ("line %d: " % self.line_num) +
324322 "functionality under test not specified")
325323
326 body_block = make_block_from_pattern(pattern, u'| ') or state.last_test_body_block
327 input_block = make_block_from_pattern(pattern, u'+ ') or state.last_test_input_block
328 expectation_block = make_block_from_pattern(pattern, pattern_prefixes[-1])
329 expectation_class = None
330 if isinstance(expectation_block, ExpectedError):
331 expectation_class = ErrorOutcome
332 if isinstance(expectation_block, ExpectedResult):
333 expectation_class = OutputOutcome
334 assert expectation_class
335 expectation = expectation_class(expectation_block.text())
324 body_block = make_block_from_pattern(TestBody, pattern, u'| ') or state.last_test_body_block
325 input_block = make_block_from_pattern(TestInput, pattern, u'+ ') or state.last_test_input_block
326
327 if pattern_prefixes[-1] == u'= ':
328 expectation_block = make_block_from_pattern(ExpectedResult, pattern, u'= ')
329 expectation = OutputOutcome(expectation_block.text())
330 elif pattern_prefixes[-1] == u'? ':
331 expectation_block = make_block_from_pattern(ExpectedError, pattern, u'? ')
332 expectation = ErrorOutcome(expectation_block.text())
333 else:
334 raise NotImplementedError
336335
337336 test = Test(body_block=body_block,
338337 input_block=input_block,
348347 raise FalderalSyntaxError(
349348 ("line %d: " % self.line_num) +
350349 "incorrectly formatted test block")
351
352
353 class LiterateCode(Block):
354 pass
355350
356351
357352 class Pragma(Block):
417412 """
418413 def __init__(self):
419414 self.lines = []
420 self.blocks = None
421415 self.filename = None
422416
423417 @classmethod
626620
627621 test_or_pragma = block.classify(state)
628622
629 if isinstance(test_or_pragma, Test):
623 if test_or_pragma is None:
624 # It was just some indented text which doesn't concern us
625 pass
626 elif isinstance(test_or_pragma, Test):
630627 tests.append(test_or_pragma)
631628 elif isinstance(test_or_pragma, Pragma):
632629 test_or_pragma.execute(state)