-
Notifications
You must be signed in to change notification settings - Fork 2
/
gocheckdictdiffresolve
executable file
·51 lines (40 loc) · 1.16 KB
/
gocheckdictdiffresolve
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
#!/usr/bin/python3
import re
import sys
GREEN = '\033[38;5;34m'
RED = '\033[38;5;196m'
GREY = '\033[38;5;241m'
ENDC = '\033[0m'
print(GREY + "paste away" + ENDC)
got = {}
rx = re.compile(r"^\.?\.\. (obtained|expected) .*?map\[\w+\](?:\w+|interface {})({.*})$")
for line in sys.stdin:
m = rx.match(line)
if m is not None:
k=m.group(1)
s=m.group(2)
d=eval(s)
got[k] = d
if len(got) != 2:
sys.exit(1)
expected=got["expected"]
obtained=got["obtained"]
kmis = expected.keys() - obtained.keys()
kadd = obtained.keys() - expected.keys()
if kmis-kadd:
print(GREY + "missing keys:" + ENDC)
for k in kmis-kadd:
print(" %r: %s%r%s" % (k, RED, expected[k], ENDC))
if kadd-kmis:
print(GREY + "extra keys:" + ENDC)
for k in kadd-kmis:
print(" %r: %s%r%s" % (k, GREEN, obtained[k], ENDC))
diff = []
for k, v in expected.items():
if k in obtained and v != obtained[k]:
diff.append((k, v, obtained[k]))
if diff:
print(GREY + "differing keys:" + ENDC)
for k, vexp, vobt in diff:
print(" %r: expected %s%r%s, got %s%r%s"
% (k, RED, vexp, ENDC, GREEN, vobt, ENDC))