Remove PREFIXES_MAP and make all tests pass once again.
Chris Pressey
6 years ago
201 | 201 | self.lines = lines |
202 | 202 | self.line_num = line_num |
203 | 203 | 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 | ] | |
213 | 211 | self.VALID_PATTERNS = [ |
214 | 212 | [u'->'], |
215 | 213 | [u'> '], |
279 | 277 | def classify(self, state): |
280 | 278 | """Return the Test or Pragma that this Block represents.""" |
281 | 279 | |
282 | def make_block_from_pattern(pattern, prefix): | |
280 | def make_block_from_pattern(cls, pattern, prefix): | |
283 | 281 | lines = None |
284 | 282 | for (candidate_prefix, candidate_lines) in pattern: |
285 | 283 | if candidate_prefix == prefix: |
287 | 285 | break |
288 | 286 | if lines is None: |
289 | 287 | 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) | |
291 | 289 | |
292 | 290 | pattern = self.deconstruct() |
293 | 291 | pattern_prefixes = [p[0] for p in pattern] |
323 | 321 | ("line %d: " % self.line_num) + |
324 | 322 | "functionality under test not specified") |
325 | 323 | |
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 | |
336 | 335 | |
337 | 336 | test = Test(body_block=body_block, |
338 | 337 | input_block=input_block, |
348 | 347 | raise FalderalSyntaxError( |
349 | 348 | ("line %d: " % self.line_num) + |
350 | 349 | "incorrectly formatted test block") |
351 | ||
352 | ||
353 | class LiterateCode(Block): | |
354 | pass | |
355 | 350 | |
356 | 351 | |
357 | 352 | class Pragma(Block): |
417 | 412 | """ |
418 | 413 | def __init__(self): |
419 | 414 | self.lines = [] |
420 | self.blocks = None | |
421 | 415 | self.filename = None |
422 | 416 | |
423 | 417 | @classmethod |
626 | 620 | |
627 | 621 | test_or_pragma = block.classify(state) |
628 | 622 | |
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): | |
630 | 627 | tests.append(test_or_pragma) |
631 | 628 | elif isinstance(test_or_pragma, Pragma): |
632 | 629 | test_or_pragma.execute(state) |