Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
91540a7d
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
大约 1 年 前同步成功
通知
0
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
91540a7d
编写于
1月 20, 2012
作者:
B
Behdad Esfahbod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move most testing logic into hb_test_tools.py
The actual utils are one-liners now.
上级
66aa0800
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
197 addition
and
179 deletion
+197
-179
test/shaping/hb-diff
test/shaping/hb-diff
+8
-69
test/shaping/hb-diff-filter-failures
test/shaping/hb-diff-filter-failures
+2
-25
test/shaping/hb-unicode-decode
test/shaping/hb-unicode-decode
+2
-16
test/shaping/hb-unicode-encode
test/shaping/hb-unicode-encode
+2
-19
test/shaping/hb-unicode-prettyname
test/shaping/hb-unicode-prettyname
+3
-50
test/shaping/hb_test_tools.py
test/shaping/hb_test_tools.py
+180
-0
未找到文件。
test/shaping/hb-diff
浏览文件 @
91540a7d
#!/usr/bin/python
import
sys
,
re
,
difflib
,
os
from
hb_test_tools
import
*
import
sys
,
os
red_color
=
green_color
=
end_color
=
""
if
"--color"
in
sys
.
argv
or
os
.
isatty
(
sys
.
stdout
.
fileno
()):
if
"--color"
in
sys
.
argv
:
sys
.
argv
.
remove
(
"--color"
)
red_color
=
'
\033
[41;37;1m'
green_color
=
'
\033
[42;37;1m'
end_color
=
'
\033
[m'
if
len
(
sys
.
argv
)
!=
3
:
print
"usage: %s [--color] file1 file2"
%
sys
.
argv
[
0
]
sys
.
exit
(
1
)
def
fancy_diff_lines
(
l1
,
l2
):
colors
=
Colors
.
Auto
(
sys
.
argv
)
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
=
[
""
,
""
]
st
=
[
False
,
False
]
for
l
in
difflib
.
Differ
().
compare
(
*
ss
):
if
l
[
0
]
==
'?'
:
continue
if
l
[
0
]
==
' '
:
for
i
in
range
(
2
):
if
st
[
i
]:
oo
[
i
]
+=
end_color
st
[
i
]
=
False
oo
=
[
o
+
l
[
2
:]
for
o
in
oo
]
continue
if
l
[
0
]
==
'-'
:
if
not
st
[
0
]:
oo
[
0
]
+=
red_color
st
[
0
]
=
True
oo
[
0
]
+=
l
[
2
:]
continue
if
l
[
0
]
==
'+'
:
if
not
st
[
1
]:
oo
[
1
]
+=
green_color
st
[
1
]
=
True
oo
[
1
]
+=
l
[
2
:]
for
i
in
range
(
2
):
if
st
[
i
]:
oo
[
i
]
+=
end_color
st
[
i
]
=
0
oo
=
[
o
.
replace
(
'
\n
'
,
''
)
for
o
in
oo
]
if
oo
[
0
]
==
oo
[
1
]:
return
[
' '
,
oo
[
0
],
'
\n
'
]
return
[
'-'
,
oo
[
0
],
'
\n
'
,
'+'
,
oo
[
1
],
'
\n
'
]
f1
,
f2
=
(
open_file_or_stdin
(
f
)
for
f
in
sys
.
argv
[
1
:
3
])
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
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
!=
3
:
print
"Usage: %s [--color] FILE1 FILE2"
%
sys
.
argv
[
0
]
sys
.
exit
(
1
)
f1
,
f2
=
(
open_file
(
f
)
for
f
in
sys
.
argv
[
1
:
3
])
fancy_diff_files
(
f1
,
f2
)
FancyDiffer
.
diff_files
(
f1
,
f2
,
colors
=
colors
)
test/shaping/hb-diff-filter-failures
浏览文件 @
91540a7d
#!/usr/bin/python
import
sys
from
hb_test_tools
import
*
red_color
=
'
\033
[41;37;1m'
green_color
=
'
\033
[42;37;1m'
end_color
=
'
\033
[m'
def
filter_failures
(
f
):
for
l
in
f
:
if
l
[
0
]
in
'-+'
:
sys
.
stdout
.
writelines
(
l
)
continue
def
open_file
(
f
):
if
f
==
'-'
:
return
sys
.
stdin
return
file
(
f
)
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
==
1
:
print
"Usage: %s FILE..."
%
sys
.
argv
[
0
]
sys
.
exit
(
1
)
for
s
in
sys
.
argv
[
1
:]:
filter_failures
(
open_file
(
s
))
UtilMains
.
process_multiple_files
(
DiffFilters
.
filter_failures
)
test/shaping/hb-unicode-decode
浏览文件 @
91540a7d
#!/usr/bin/python
import
sys
from
hb_test_tools
import
*
def
decode
(
s
):
return
'<'
+
','
.
join
(
"U+%04X"
%
ord
(
u
)
for
u
in
unicode
(
s
,
'utf8'
))
+
'>'
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
==
1
or
(
'--stdin'
in
sys
.
argv
and
len
(
sys
.
argv
)
!=
2
):
print
"Usage:
\n
%s UNICODE_STRING...
\n
or:
\n
%s --stdin"
%
(
sys
.
argv
[
0
],
sys
.
argv
[
0
])
sys
.
exit
(
1
)
if
'--stdin'
in
sys
.
argv
:
sys
.
argv
.
remove
(
'--stdin'
)
for
line
in
sys
.
stdin
.
readlines
():
print
decode
(
line
)
else
:
print
' '
.
join
(
decode
(
x
)
for
x
in
(
sys
.
argv
[
1
:]))
UtilMains
.
filter_multiple_strings_or_stdin
(
Unicode
.
decode
,
"UNICODE_STRING"
)
test/shaping/hb-unicode-encode
浏览文件 @
91540a7d
#!/usr/bin/python
import
sys
import
re
from
hb_test_tools
import
*
def
encode
(
s
):
s
=
re
.
sub
(
r
"[<+>\\uU]"
,
" "
,
s
)
s
=
re
.
sub
(
r
"0[xX]"
,
" "
,
s
)
return
u
''
.
join
(
unichr
(
int
(
x
,
16
))
for
x
in
re
.
split
(
'[,
\n
]'
,
s
)
if
len
(
x
))
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
==
1
or
(
'--stdin'
in
sys
.
argv
and
len
(
sys
.
argv
)
!=
2
):
print
"Usage:
\n
%s UNICODE_CODEPOINTS...
\n
or:
\n
%s --stdin"
%
(
sys
.
argv
[
0
],
sys
.
argv
[
0
])
sys
.
exit
(
1
)
if
'--stdin'
in
sys
.
argv
:
sys
.
argv
.
remove
(
'--stdin'
)
for
line
in
sys
.
stdin
.
readlines
():
print
encode
(
line
)
else
:
print
encode
(
','
.
join
(
sys
.
argv
[
1
:]))
UtilMains
.
filter_multiple_strings_or_stdin
(
Unicode
.
encode
,
"UNICODE_STRING"
,
''
)
test/shaping/hb-unicode-prettyname
浏览文件 @
91540a7d
#!/usr/bin/python
import
sys
import
re
import
unicodedata
from
hb_test_tools
import
*
shorthands
=
{
"ZERO WIDTH NON-JOINER"
:
"ZWNJ"
,
"ZERO WIDTH JOINER"
:
"ZWJ"
,
"NARROW NO-BREAK SPACE"
:
"NNBSP"
,
"COMBINING GRAPHEME JOINER"
:
"CGJ"
,
"LEFT-TO-RIGHT MARK"
:
"LRM"
,
"RIGHT-TO-LEFT MARK"
:
"RLM"
,
"LEFT-TO-RIGHT EMBEDDING"
:
"LRE"
,
"RIGHT-TO-LEFT EMBEDDING"
:
"RLE"
,
"POP DIRECTIONAL FORMATTING"
:
"PDF"
,
"LEFT-TO-RIGHT OVERRIDE"
:
"LRO"
,
"RIGHT-TO-LEFT OVERRIDE"
:
"RLO"
,
}
def
pretty_name
(
x
):
try
:
s
=
unicodedata
.
name
(
x
)
except
ValueError
:
return
"XXX"
s
=
re
.
sub
(
".* LETTER "
,
""
,
s
)
s
=
re
.
sub
(
".* VOWEL SIGN (.*)"
,
r
"\1-MATRA"
,
s
)
s
=
re
.
sub
(
".* SIGN "
,
""
,
s
)
s
=
re
.
sub
(
".* COMBINING "
,
""
,
s
)
if
re
.
match
(
".* VIRAMA"
,
s
):
s
=
"HALANT"
if
s
in
shorthands
:
s
=
shorthands
[
s
]
return
s
def
pretty_names
(
s
):
s
=
re
.
sub
(
r
"[<+>\\uU]"
,
" "
,
s
)
s
=
re
.
sub
(
r
"0[xX]"
,
" "
,
s
)
s
=
[
unichr
(
int
(
x
,
16
))
for
x
in
re
.
split
(
'[,
\n
]'
,
s
)
if
len
(
x
)]
return
' + '
.
join
(
pretty_name
(
x
)
for
x
in
s
)
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
==
1
or
(
'--stdin'
in
sys
.
argv
and
len
(
sys
.
argv
)
!=
2
):
print
"Usage:
\n
%s UNICODE_CODEPOINTS...
\n
or:
\n
%s --stdin"
%
(
sys
.
argv
[
0
],
sys
.
argv
[
0
])
sys
.
exit
(
1
)
if
'--stdin'
in
sys
.
argv
:
sys
.
argv
.
remove
(
'--stdin'
)
for
line
in
sys
.
stdin
.
readlines
():
print
pretty_names
(
line
)
else
:
print
pretty_names
(
','
.
join
(
sys
.
argv
[
1
:]))
UtilMains
.
filter_multiple_strings_or_stdin
(
Unicode
.
pretty_names
,
"UNICODE_CODEPOINTS"
,
\
concat_separator
=
' '
)
test/shaping/hb_test_tools.py
0 → 100644
浏览文件 @
91540a7d
#!/usr/bin/python
import
sys
,
os
,
re
,
difflib
,
unicodedata
class
Colors
:
class
Null
:
red
=
''
green
=
''
end
=
''
class
ANSI
:
red
=
'
\033
[41;37;1m'
green
=
'
\033
[42;37;1m'
end
=
'
\033
[m'
class
HTML
:
red
=
'<span style="color:red">'
green
=
'<span style="color:green">'
end
=
'</span>'
@
staticmethod
def
Auto
(
argv
=
[],
out
=
sys
.
stdout
):
if
"--color"
in
argv
or
os
.
isatty
(
out
.
fileno
()):
if
"--color"
in
sys
.
argv
[
1
:]:
argv
.
remove
(
"--color"
)
return
Colors
.
ANSI
else
:
return
Colors
.
Null
class
FancyDiffer
:
diff_regex
=
re
.
compile
(
'([a-za-z0-9_]*)([^a-za-z0-9_]?)'
)
@
staticmethod
def
diff_lines
(
l1
,
l2
,
colors
=
Colors
.
Null
):
ss
=
[
FancyDiffer
.
diff_regex
.
sub
(
r
'\1\n\2\n'
,
l
).
splitlines
(
True
)
for
l
in
(
l1
,
l2
)]
oo
=
[
""
,
""
]
st
=
[
False
,
False
]
for
l
in
difflib
.
Differ
().
compare
(
*
ss
):
if
l
[
0
]
==
'?'
:
continue
if
l
[
0
]
==
' '
:
for
i
in
range
(
2
):
if
st
[
i
]:
oo
[
i
]
+=
colors
.
end
st
[
i
]
=
False
oo
=
[
o
+
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
:]
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
=
[
o
.
replace
(
'
\n
'
,
''
)
for
o
in
oo
]
if
oo
[
0
]
==
oo
[
1
]:
return
[
' '
,
oo
[
0
],
'
\n
'
]
return
[
'-'
,
oo
[
0
],
'
\n
'
,
'+'
,
oo
[
1
],
'
\n
'
]
@
staticmethod
def
diff_files
(
f1
,
f2
,
colors
=
Colors
.
Null
):
for
(
l1
,
l2
)
in
zip
(
f1
,
f2
):
if
l1
==
l2
:
sys
.
stdout
.
writelines
([
" "
,
l1
])
continue
sys
.
stdout
.
writelines
(
FancyDiffer
.
diff_lines
(
l1
,
l2
,
colors
))
# print out residues
for
l
in
f1
:
sys
.
stdout
.
writelines
([
"-"
,
colors
.
red
,
l1
,
colors
.
end
])
for
l
in
f1
:
sys
.
stdout
.
writelines
([
"-"
,
colors
.
green
,
l1
,
colors
.
end
])
class
DiffFilters
:
@
staticmethod
def
filter_failures
(
f
):
for
l
in
f
:
if
l
[
0
]
in
'-+'
:
sys
.
stdout
.
writelines
(
l
)
class
UtilMains
:
@
staticmethod
def
process_multiple_files
(
callback
):
if
len
(
sys
.
argv
)
==
1
:
print
"Usage: %s FILE..."
%
sys
.
argv
[
0
]
sys
.
exit
(
1
)
for
s
in
sys
.
argv
[
1
:]:
callback
(
open_file_or_stdin
(
s
))
@
staticmethod
def
filter_multiple_strings_or_stdin
(
callback
,
string_mnemonic
,
\
separator
=
" "
,
\
concat_separator
=
False
):
if
len
(
sys
.
argv
)
==
1
or
(
'--stdin'
in
sys
.
argv
and
len
(
sys
.
argv
)
!=
2
):
print
"Usage:
\n
%s %s...
\n
or:
\n
%s --stdin"
\
%
(
sys
.
argv
[
0
],
string_mnemonic
,
sys
.
argv
[
0
])
sys
.
exit
(
1
)
if
'--stdin'
in
sys
.
argv
:
sys
.
argv
.
remove
(
'--stdin'
)
for
line
in
sys
.
stdin
.
readlines
():
print
callback
(
line
)
else
:
args
=
sys
.
argv
[
1
:]
if
concat_separator
!=
False
:
args
=
[
concat_separator
.
join
(
args
)]
print
separator
.
join
(
callback
(
x
)
for
x
in
(
args
))
class
Unicode
:
@
staticmethod
def
decode
(
s
):
return
'<'
+
','
.
join
(
"U+%04X"
%
ord
(
u
)
for
u
in
unicode
(
s
,
'utf8'
))
+
'>'
@
staticmethod
def
encode
(
s
):
s
=
re
.
sub
(
r
"[<+>\\uU]"
,
" "
,
s
)
s
=
re
.
sub
(
r
"0[xX]"
,
" "
,
s
)
return
u
''
.
join
(
unichr
(
int
(
x
,
16
))
for
x
in
re
.
split
(
'[,
\n
]'
,
s
)
if
len
(
x
))
shorthands
=
{
"ZERO WIDTH NON-JOINER"
:
"ZWNJ"
,
"ZERO WIDTH JOINER"
:
"ZWJ"
,
"NARROW NO-BREAK SPACE"
:
"NNBSP"
,
"COMBINING GRAPHEME JOINER"
:
"CGJ"
,
"LEFT-TO-RIGHT MARK"
:
"LRM"
,
"RIGHT-TO-LEFT MARK"
:
"RLM"
,
"LEFT-TO-RIGHT EMBEDDING"
:
"LRE"
,
"RIGHT-TO-LEFT EMBEDDING"
:
"RLE"
,
"POP DIRECTIONAL FORMATTING"
:
"PDF"
,
"LEFT-TO-RIGHT OVERRIDE"
:
"LRO"
,
"RIGHT-TO-LEFT OVERRIDE"
:
"RLO"
,
}
@
staticmethod
def
pretty_name
(
u
):
try
:
s
=
unicodedata
.
name
(
u
)
except
ValueError
:
return
"XXX"
s
=
re
.
sub
(
".* LETTER "
,
""
,
s
)
s
=
re
.
sub
(
".* VOWEL SIGN (.*)"
,
r
"\1-MATRA"
,
s
)
s
=
re
.
sub
(
".* SIGN "
,
""
,
s
)
s
=
re
.
sub
(
".* COMBINING "
,
""
,
s
)
if
re
.
match
(
".* VIRAMA"
,
s
):
s
=
"HALANT"
if
s
in
Unicode
.
shorthands
:
s
=
Unicode
.
shorthands
[
s
]
return
s
@
staticmethod
def
pretty_names
(
s
):
s
=
re
.
sub
(
r
"[<+>\\uU]"
,
" "
,
s
)
s
=
re
.
sub
(
r
"0[xX]"
,
" "
,
s
)
s
=
[
unichr
(
int
(
x
,
16
))
for
x
in
re
.
split
(
'[,
\n
]'
,
s
)
if
len
(
x
)]
return
' + '
.
join
(
Unicode
.
pretty_name
(
x
)
for
x
in
s
)
def
open_file_or_stdin
(
f
):
if
f
==
'-'
:
return
sys
.
stdin
return
file
(
f
)
if
__name__
==
'__main__'
:
pass
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录