[HarfBuzz] harfbuzz-ng: Branch 'master' - 4 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Tue May 8 15:03:35 PDT 2012
test/shaping/Makefile.am | 1
test/shaping/hb-diff | 10
test/shaping/hb-diff-colorize | 7
test/shaping/hb_test_tools.py | 192 ++++++----
test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/MANIFEST | 1
test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/poem.txt | 4
test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/MANIFEST | 1
test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/reph.txt | 10
8 files changed, 143 insertions(+), 83 deletions(-)
New commits:
commit f1eb008cc727370e1bd0dc32fdf301f62d9ff981
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 8 23:41:41 2012 +0200
Add hb-diff-colorize
Accepts --format=html now.
diff --git a/test/shaping/Makefile.am b/test/shaping/Makefile.am
index 1694eca..f216c5d 100644
--- a/test/shaping/Makefile.am
+++ b/test/shaping/Makefile.am
@@ -11,6 +11,7 @@ manifests:
EXTRA_DIST += \
hb-diff \
+ hb-diff-colorize \
hb-diff-filter-failures \
hb-manifest-read \
hb-manifest-update \
diff --git a/test/shaping/hb-diff b/test/shaping/hb-diff
index eac3ff6..6a13fa2 100755
--- a/test/shaping/hb-diff
+++ b/test/shaping/hb-diff
@@ -3,8 +3,8 @@
from hb_test_tools import *
import sys, os
-if len (sys.argv) < 3:
- print "usage: %s file1 file2..." % sys.argv[0]
+if len (sys.argv) < 2:
+ print "usage: %s FILES..." % sys.argv[0]
sys.exit (1)
ZipDiffer.diff_files (FileHelpers.open_file_or_stdin (f) for f in sys.argv[1:])
diff --git a/test/shaping/hb-diff-colorize b/test/shaping/hb-diff-colorize
new file mode 100755
index 0000000..4e045d2
--- /dev/null
+++ b/test/shaping/hb-diff-colorize
@@ -0,0 +1,7 @@
+#!/usr/bin/python
+
+from hb_test_tools import *
+
+formatter = ColorFormatter.Auto (sys.argv)
+colorizer = DiffColorizer (formatter=formatter)
+UtilMains.process_multiple_files (FilterHelpers.filter_printer_function_no_newline (colorizer.colorize_diff))
diff --git a/test/shaping/hb_test_tools.py b/test/shaping/hb_test_tools.py
index 65640bc..03a7710 100644
--- a/test/shaping/hb_test_tools.py
+++ b/test/shaping/hb_test_tools.py
@@ -1,65 +1,81 @@
#!/usr/bin/python
-import sys, os, re, difflib, unicodedata, errno
+import sys, os, re, difflib, unicodedata, errno, cgi
from itertools import *
diff_symbols = "-+=*&^%$#@!~/"
diff_colors = ['red', 'green', 'blue']
-class Colors:
+class ColorFormatter:
+
class Null:
- red = ''
- green = ''
- end = ''
+ @staticmethod
+ def start_color (c): return ''
+ @staticmethod
+ def end_color (): return ''
+ @staticmethod
+ def escape (s): return s
+ @staticmethod
+ def newline (): return '\n'
+
class ANSI:
- red = '\033[41;37;1m'
- green = '\033[42;37;1m'
- end = '\033[m'
+ @staticmethod
+ def start_color (c):
+ return {
+ 'red': '\033[41;37;1m',
+ 'green': '\033[42;37;1m',
+ 'blue': '\033[44;37;1m',
+ }[c]
+ @staticmethod
+ def end_color ():
+ return '\033[m'
+ @staticmethod
+ def escape (s): return s
+ @staticmethod
+ def newline (): return '\n'
+
class HTML:
- red = '<span style="color:red">'
- green = '<span style="color:green">'
- end = '</span>'
+ @staticmethod
+ def start_color (c):
+ return '<span style="background:%s">' % c
+ @staticmethod
+ def end_color ():
+ return '</span>'
+ @staticmethod
+ def escape (s): return cgi.escape (s)
+ @staticmethod
+ def newline (): return '<br/>\n'
@staticmethod
def Auto (argv = [], out = sys.stdout):
- if os.isatty (out.fileno ()):
- color = Colors.ANSI
- else:
- color = Colors.Null
- if "--color" in argv:
- argv.remove ("--color")
- color = Colors.ANSI
- if "--color=ansi" in argv:
- argv.remove ("--color=ansi")
- color = Colors.ANSI
- if "--color=html" in argv:
- argv.remove ("--color=html")
- color = Colors.HTML
- if "--no-color" in argv:
- argv.remove ("--no-color")
- color = Colors.Null
- return color
-
-
- @staticmethod
- def Default (argv = []):
- return Colors.ANSI
-
-
-class FancyDiffer:
+ format = ColorFormatter.ANSI
+ if "--format" in argv:
+ argv.remove ("--format")
+ format = ColorFormatter.ANSI
+ if "--format=ansi" in argv:
+ argv.remove ("--format=ansi")
+ format = ColorFormatter.ANSI
+ if "--format=html" in argv:
+ argv.remove ("--format=html")
+ format = ColorFormatter.HTML
+ if "--no-format" in argv:
+ argv.remove ("--no-format")
+ format = ColorFormatter.Null
+ return format
+
+
+class DiffColorizer:
diff_regex = re.compile ('([a-za-z0-9_]*)([^a-za-z0-9_]?)')
- @staticmethod
- def diff_lines (l1, l2, colors=Colors.Null):
-
- # Easy without colors
- if colors == Colors.Null:
- if l1 == l2:
- return [' ', l1]
- return ['-', l1, '+', l2]
+ def __init__ (self, formatter, colors=diff_colors, symbols=diff_symbols):
+ self.formatter = formatter
+ self.colors = colors
+ self.symbols = symbols
- ss = [FancyDiffer.diff_regex.sub (r'\1\n\2\n', l).splitlines (True) for l in (l1, l2)]
+ def colorize_lines (self, lines):
+ lines = (l if l else '' for l in lines)
+ ss = [self.diff_regex.sub (r'\1\n\2\n', l).splitlines (True) for l in lines]
oo = ["",""]
st = [False, False]
for l in difflib.Differ().compare (*ss):
@@ -68,29 +84,47 @@ class FancyDiffer:
if l[0] == ' ':
for i in range(2):
if st[i]:
- oo[i] += colors.end
+ oo[i] += self.formatter.end_color ()
st[i] = False
- oo = [o + l[2:] for o in oo]
+ oo = [o + self.formatter.escape (l[2:]) for o in oo]
continue
- if l[0] == '-':
- if not st[0]:
- oo[0] += colors.red
- st[0] = True
- oo[0] += l[2:]
+ if l[0] in self.symbols:
+ i = self.symbols.index (l[0])
+ if not st[i]:
+ oo[i] += self.formatter.start_color (self.colors[i])
+ st[i] = True
+ oo[i] += self.formatter.escape (l[2:])
continue
- if l[0] == '+':
- if not st[1]:
- oo[1] += colors.green
- st[1] = True
- oo[1] += l[2:]
for i in range(2):
if st[i]:
- oo[i] += colors.end
- st[i] = 0
+ oo[i] += self.formatter.end_color ()
+ st[i] = False
oo = [o.replace ('\n', '') for o in oo]
- if oo[0] == oo[1]:
- return [' ', oo[0], '\n']
- return ['-', oo[0], '\n', '+', oo[1], '\n']
+ return [s1+s2+self.formatter.newline () for (s1,s2) in zip (self.symbols, oo) if s2]
+
+ def colorize_diff (self, f):
+ lines = [None, None]
+ for l in f:
+ if l[0] not in self.symbols:
+ yield self.formatter.escape (l).replace ('\n', self.formatter.newline ())
+ continue
+ i = self.symbols.index (l[0])
+ if lines[i]:
+ # Flush
+ for line in self.colorize_lines (lines):
+ yield line
+ lines = [None, None]
+ lines[i] = l[1:]
+ if (all (lines)):
+ # Flush
+ for line in self.colorize_lines (lines):
+ yield line
+ lines = [None, None]
+ if (any (lines)):
+ # Flush
+ for line in self.colorize_lines (lines):
+ yield line
+
class ZipDiffer:
commit 9155e4ffe00c96a2c14e14a300004b1038ca3a9c
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 8 22:44:21 2012 +0200
Cleanup diff
Doesn't do --color anymore. That will go into a new hb-diff-colorize
tool.
diff --git a/test/shaping/hb-diff b/test/shaping/hb-diff
index 29fd119..eac3ff6 100755
--- a/test/shaping/hb-diff
+++ b/test/shaping/hb-diff
@@ -3,12 +3,8 @@
from hb_test_tools import *
import sys, os
-colors = Colors.Auto (sys.argv)
-
-if len (sys.argv) != 3:
- print "usage: %s [--color] file1 file2" % sys.argv[0]
+if len (sys.argv) < 3:
+ print "usage: %s file1 file2..." % sys.argv[0]
sys.exit (1)
-files = (FileHelpers.open_file_or_stdin (f) for f in sys.argv[1:3])
-
-FancyDiffer.diff_files (*files, colors=colors)
+ZipDiffer.diff_files (FileHelpers.open_file_or_stdin (f) for f in sys.argv[1:])
diff --git a/test/shaping/hb_test_tools.py b/test/shaping/hb_test_tools.py
index d85c38e..65640bc 100644
--- a/test/shaping/hb_test_tools.py
+++ b/test/shaping/hb_test_tools.py
@@ -3,6 +3,9 @@
import sys, os, re, difflib, unicodedata, errno
from itertools import *
+diff_symbols = "-+=*&^%$#@!~/"
+diff_colors = ['red', 'green', 'blue']
+
class Colors:
class Null:
red = ''
@@ -89,20 +92,20 @@ class FancyDiffer:
return [' ', oo[0], '\n']
return ['-', oo[0], '\n', '+', oo[1], '\n']
+class ZipDiffer:
+
@staticmethod
- def diff_files (f1, f2, colors=Colors.Null):
+ def diff_files (files, symbols=diff_symbols):
+ files = tuple (files) # in case it's a generator, copy it
try:
- for (l1,l2) in izip (f1, f2):
- if l1 == l2:
- sys.stdout.writelines ([" ", l1])
+ for lines in izip_longest (*files):
+ if all (lines[0] == line for line in lines[1:]):
+ sys.stdout.writelines ([" ", lines[0]])
continue
- sys.stdout.writelines (FancyDiffer.diff_lines (l1, l2, colors))
- # print out residues
- for l in f1:
- sys.stdout.writelines (["-", colors.red, l, colors.end])
- for l in f2:
- sys.stdout.writelines (["-", colors.green, l, colors.end])
+ for i, l in enumerate (lines):
+ if l:
+ sys.stdout.writelines ([symbols[i], l])
except IOError as e:
if e.errno != errno.EPIPE:
print >> sys.stderr, "%s: %s: %s" % (sys.argv[0], e.filename, e.strerror)
@@ -112,9 +115,9 @@ class FancyDiffer:
class DiffFilters:
@staticmethod
- def filter_failures (f):
+ def filter_failures (f, symbols=diff_symbols):
for l in f:
- if l[0] in '-+':
+ if l[0] in symbols:
# TODO retain all lines of the failure
yield l
@@ -146,12 +149,13 @@ class UtilMains:
@staticmethod
def process_multiple_files (callback, mnemonic = "FILE"):
- if len (sys.argv) == 1:
+ if "--help" in sys.argv:
print "Usage: %s %s..." % (sys.argv[0], mnemonic)
sys.exit (1)
try:
- for s in sys.argv[1:]:
+ files = sys.argv[1:] if len (sys.argv) > 1 else ['-']
+ for s in files:
callback (FileHelpers.open_file_or_stdin (s))
except IOError as e:
if e.errno != errno.EPIPE:
commit 7d22135b4c3f8fb70552302bf8239df9976dddda
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 8 19:38:49 2012 +0200
Make hb-diff faster
diff --git a/test/shaping/hb_test_tools.py b/test/shaping/hb_test_tools.py
index 94207f8..d85c38e 100644
--- a/test/shaping/hb_test_tools.py
+++ b/test/shaping/hb_test_tools.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
import sys, os, re, difflib, unicodedata, errno
+from itertools import *
class Colors:
class Null:
@@ -91,7 +92,7 @@ class FancyDiffer:
@staticmethod
def diff_files (f1, f2, colors=Colors.Null):
try:
- for (l1,l2) in zip (f1, f2):
+ for (l1,l2) in izip (f1, f2):
if l1 == l2:
sys.stdout.writelines ([" ", l1])
continue
@@ -100,7 +101,7 @@ class FancyDiffer:
# print out residues
for l in f1:
sys.stdout.writelines (["-", colors.red, l, colors.end])
- for l in f1:
+ for l in f2:
sys.stdout.writelines (["-", colors.green, l, colors.end])
except IOError as e:
if e.errno != errno.EPIPE:
@@ -114,6 +115,7 @@ class DiffFilters:
def filter_failures (f):
for l in f:
if l[0] in '-+':
+ # TODO retain all lines of the failure
yield l
commit a93e238e05a2f70a6e664e5d04ba25bbd54493dc
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 8 18:55:29 2012 +0200
More tests
diff --git a/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/MANIFEST b/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/MANIFEST
index 29cfb2f..e7eedf6 100644
--- a/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/MANIFEST
+++ b/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/MANIFEST
@@ -1 +1,2 @@
misc.txt
+poem.txt
diff --git a/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/poem.txt b/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/poem.txt
new file mode 100644
index 0000000..14ce2d4
--- /dev/null
+++ b/test/shaping/texts/in-tree/shaper-arabic/script-mongolian/misc/poem.txt
@@ -0,0 +1,4 @@
+á ¥á °á ¬á ¦â¯á ¡á ´á ¡ á °á ¤á ·á ¤á á °á á ¨ á ¦á ¨á ³á ¦á °á ¦á ¨ á ¬á ¡á ¯á ¡
+á ®á á ·á ²á á µá ¤ á ªá £á ¯á £á °á ¢ á ¦á á ¡á ¢ á °á £á ¶á £á ¯
+á ¦á ¬á ¦á ²á ¡á ¯á á ¡ á £á ·á £á °á ¢á ¬á ¤ á ²á ¦á ·á ¦á ¯á ¬á ¢ á ¨á ¤á ²á ¤á
+á °á á ¯á µá ¤ á ªá £á ¯á £á °á ¢ á ¦á á ¡á ¢ á £á ·á £á ¨
diff --git a/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/MANIFEST b/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/MANIFEST
index 29cfb2f..3c2a4fb 100644
--- a/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/MANIFEST
+++ b/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/MANIFEST
@@ -1 +1,2 @@
misc.txt
+reph.txt
diff --git a/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/reph.txt b/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/reph.txt
new file mode 100644
index 0000000..d5d6442
--- /dev/null
+++ b/test/shaping/texts/in-tree/shaper-indic/indic/script-bengali/misc/reph.txt
@@ -0,0 +1,10 @@
+রà§à¦
+রà§à¦à¦¾
+রà§à¦à¦¿
+রà§à¦à§
+রà§à¦à§
+রà§à¦à§
+রà§à¦à§
+রà§à¦à§
+রà§à¦à§
+রà§à¦à§
More information about the HarfBuzz
mailing list