diff options
-rwxr-xr-x | ftt-docgen | 34 | ||||
-rw-r--r-- | muck.yaml | 52 |
2 files changed, 50 insertions, 36 deletions
@@ -12,10 +12,26 @@ def format_keyword(line): keyword = words[0] return '**{}** '.format(keyword) + line[len(keyword):] -def format_scenario_step(bind, line): +def format_scenario_step(bind, line, prev_keyword): + debug('step: line={!r} prev_keyword={}'.format(line, prev_keyword)) + words = line.split() + if not words: + return line.strip(), prev_keyword + keyword = words[0] + real_keyword = keyword + if keyword.lower() == 'and': + if prev_keyword is None: + sys.exit('AND may not be used on first step in snippet') + real_keyword = prev_keyword + line = ' '.join(words[1:]) + debug(' keyword={!r} rest={!r}'.format(keyword, line)) + for b in bind: - m = re.match(b['pattern'], line, re.I) + if real_keyword not in b: + continue + m = re.match(b[real_keyword], line, re.I) if m and m.end() == len(line): + debug(' found binding: {!r}'.format(b)) n = len(m.groups()) if n > 0: end = 0 @@ -26,13 +42,23 @@ def format_scenario_step(bind, line): parts.append('_{}_'.format(thispart)) end = m.end(i) line = ''.join(parts) + line[m.end(n):] + line = '{} {}'.format(keyword, line) + debug(' match: {!r}'.format(line)) + break if not line.strip(): return line - return format_keyword(line) + + return format_keyword(line), real_keyword def format_fable_snippet(bind, lines): - return [format_scenario_step(bind, line) for line in lines] + debug('snippet: lines={!r}'.format(lines)) + prev_keyword = None + output = [] + for line in lines: + ln, prev_keyword = format_scenario_step(bind, line, prev_keyword) + output.append(ln) + return output def is_fable_snippet(o): prefix = "```fable\n" @@ -1,32 +1,20 @@ -- pattern: when I fetch resource (?P<id>\S+) -- pattern: and I fetch resource (?P<id>\S+) - -- pattern: then it has revision (?P<revision>\S+) -- pattern: and it has revision (?P<revision>\S+) - -- pattern: then it is mine -- pattern: and it is mine - -- pattern: then remember the resource id as (?P<name>\S+) -- pattern: and remember the resource id as (?P<name>\S+) - -- pattern: then remember the resource revision as (?P<name>\S+) -- pattern: and remember the resource revision as (?P<name>\S+) - -- pattern: given I am (?P<username>\S+) -- pattern: given a running Muck -- pattern: then I only get resource (?P<id>\S+) -- pattern: then I get (?P<json>.+) -- pattern: "then it doesn't exist" -- pattern: then it works -- pattern: then there are no resources in Muck - -- pattern: then there is (?P<number>\d+) resource in Muck -- pattern: then there are (?P<number>\d+) resources in Muck - -- pattern: then there are no matches -- pattern: when I create a resource (?P<json>.+) -- pattern: when I delete (?P<id>\S+) -- pattern: when I search for (?P<field>\S+) being (?P<value>.+) -- pattern: when I update (?P<id>\S+), revision (?P<rev>\S+), with (?P<json>.+) -- pattern: when Muck is restarted +- given: I am (?P<username>\S+) +- given: a running Muck +- then: "it doesn't exist" +- then: I get (?P<json>.+) +- then: I only get resource (?P<id>\S+) +- then: it has revision (?P<revision>\S+) +- then: it is mine +- then: it works +- then: remember the resource id as (?P<name>\S+) +- then: remember the resource revision as (?P<name>\S+) +- then: there are (?P<number>\d+) resources in Muck +- then: there are no matches +- then: there are no resources in Muck +- then: there is (?P<number>\d+) resource in Muck +- when: I create a resource (?P<json>.+) +- when: I delete (?P<id>\S+) +- when: I fetch resource (?P<id>\S+) +- when: I search for (?P<field>\S+) being (?P<value>.+) +- when: I update (?P<id>\S+), revision (?P<rev>\S+), with (?P<json>.+) +- when: Muck is restarted |