diff --git a/test/shaping/hb-diff b/test/shaping/hb-diff index 81ef7d90c..46ad19c31 100755 --- a/test/shaping/hb-diff +++ b/test/shaping/hb-diff @@ -10,7 +10,7 @@ if "--color" in sys.argv or os.isatty (sys.stdout.fileno ()): green_color = '\033[42;37;1m' end_color = '\033[m' -def fancy_diff (l1, l2): +def fancy_diff_lines (l1, l2): ss = [re.sub ('([A-Za-z0-9_]*)([^A-Za-z0-9_]?)', r'\1\n\2\n', l).splitlines (True) for l in (l1, l2)] oo = ["",""] @@ -45,26 +45,31 @@ def fancy_diff (l1, l2): return [' ', oo[0], '\n'] return ['-', oo[0], '\n', '+', oo[1], '\n'] +def fancy_diff_files (f1, f2): + for (l1,l2) in zip (f1, f2): + if l1 == l2: + sys.stdout.writelines ([" ", l1]) + continue + + sys.stdout.writelines (fancy_diff_lines (l1, l2)) + # Print out residues + for l in f1: + sys.stdout.writelines (["-", red_color, l1, end_color]) + for l in f1: + sys.stdout.writelines (["-", green_color, l1, end_color]) + def open_file (f): if f == '-': return sys.stdin return file (f) -if len (sys.argv) != 3: - print "Usage: %s [--color] FILE1 FILE2" % sys.argv[0] - sys.exit (1) +if __name__ == '__main__': -f1, f2 = (open_file (f) for f in sys.argv[1:3]) + if len (sys.argv) != 3: + print "Usage: %s [--color] FILE1 FILE2" % sys.argv[0] + sys.exit (1) -for (l1,l2) in zip (f1, f2): - if l1 == l2: - sys.stdout.writelines ([" ", l1]) - continue + f1, f2 = (open_file (f) for f in sys.argv[1:3]) - sys.stdout.writelines (fancy_diff (l1, l2)) -# Print out residues -for l in f1: - sys.stdout.writelines (["-", red_color, l1, end_color]) -for l in f1: - sys.stdout.writelines (["-", green_color, l1, end_color]) + fancy_diff_files (f1, f2)