Skip to content

Commit 36e3e9a

Browse files
committed
add FontBitFlagModel tests
1 parent b97fdf6 commit 36e3e9a

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

tests/test_models_fontbitflag.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
from slice.models import FontBitFlagModel
2+
3+
#
4+
# Utilities
5+
#
6+
7+
8+
def get_os2_default_dict():
9+
return {
10+
"bit0": False,
11+
"bit5": False,
12+
"bit6": False,
13+
"bit8": False,
14+
}
15+
16+
17+
def get_os2_default_dict_true():
18+
return {
19+
"bit0": True,
20+
"bit5": True,
21+
"bit6": True,
22+
"bit8": True,
23+
}
24+
25+
26+
def get_head_default_dict():
27+
return {
28+
"bit0": False,
29+
"bit1": False,
30+
}
31+
32+
33+
def get_head_default_dict_true():
34+
return {
35+
"bit0": True,
36+
"bit1": True,
37+
}
38+
39+
40+
# ~~~~~~~~~~~~~~~
41+
#
42+
# Tests
43+
#
44+
# ~~~~~~~~~~~~~~~
45+
46+
47+
def test_bitflag_model_default():
48+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
49+
assert fm._os2_dict == get_os2_default_dict()
50+
assert fm._head_dict == get_head_default_dict()
51+
52+
53+
def test_bitflag_model_set_bit():
54+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
55+
assert fm._set_bit(0, 0) == 1
56+
57+
58+
def test_bitflag_model_clear_bit():
59+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
60+
assert fm._clear_bit(1, 0) == 0
61+
62+
63+
def test_bitflag_model_get_offset_from_key():
64+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
65+
assert fm._get_bit_offset_from_key("bit0") == 0
66+
assert fm._get_bit_offset_from_key("bit1") == 1
67+
assert fm._get_bit_offset_from_key("bit10") == 10
68+
69+
70+
def test_bitflag_model_get_os2_instance_data():
71+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
72+
assert fm.get_os2_instance_data() == get_os2_default_dict()
73+
74+
75+
def test_bitflag_model_get_head_instance_data():
76+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
77+
assert fm.get_head_instance_data() == get_head_default_dict()
78+
79+
80+
def test_bitflag_model_edit_os2_fsselection_bits():
81+
# set all bits that will be cleared
82+
test_int = 353
83+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
84+
# confirm that they are all cleared
85+
assert fm.edit_os2_fsselection_bits(test_int) == 0
86+
87+
# clear all bits that will be set
88+
test_int2 = 0
89+
fm2 = FontBitFlagModel(get_os2_default_dict_true(), get_head_default_dict())
90+
# confirm that they are all set
91+
assert fm2.edit_os2_fsselection_bits(test_int2) == 353
92+
93+
94+
def test_bitflag_model_edit_head_macstyle_bits():
95+
# set all bits that will be cleared
96+
test_int = 3
97+
fm = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict())
98+
# confirm that they are all cleared
99+
assert fm.edit_head_macstyle_bits(test_int) == 0
100+
101+
# clear all bits that will be set
102+
test_int2 = 0
103+
fm2 = FontBitFlagModel(get_os2_default_dict(), get_head_default_dict_true())
104+
# confirm that they are all set
105+
assert fm2.edit_head_macstyle_bits(test_int2) == 3

0 commit comments

Comments
 (0)