-
Notifications
You must be signed in to change notification settings - Fork 1
/
parsebdd.py
66 lines (46 loc) · 1.33 KB
/
parsebdd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import argparse
GIVEN = "Dado"
AND = "E"
WHEN = "Quando"
THEN = "Então"
def add_header(nf):
tf = open("./template", "r")
for templine in tf:
nf.write(templine)
tf.close()
add_new_line(nf)
add_new_line(nf)
def add_new_line(nf):
nf.write("\n")
def add_command(nf, text, command):
text = text.strip(" ").rstrip("\n")
if "<" in text:
text = text.replace(text[text.rfind("<"):text.rfind(">")+1], "(.*)")
nf.write("{0}(/^{1}$/,()=>{{".format(command, text))
add_new_line(nf)
add_new_line(nf)
nf.write("})")
add_new_line(nf)
add_new_line(nf)
def parse():
nf = open("./{0}.steps.js".format("sample"), "w")
add_header(nf)
f = open("./bdd", "r")
for line in f:
line = line.strip(" ")
if line.startswith(GIVEN):
add_command(nf, line.split(GIVEN)[1], GIVEN)
elif line.startswith(AND + " "):
add_command(nf, line.split(AND + " ")[1], AND)
elif line.startswith(WHEN):
add_command(nf, line.split(WHEN)[1], WHEN)
elif line.startswith(THEN):
add_command(nf, line.split(THEN)[1], THEN)
f.close()
nf.flush()
nf.close()
print("parse finished")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.parse_args()
parse()