2017-03-10 16:00:57 +00:00
|
|
|
from fontTools.varLib.builder import buildVarData
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"region_indices, items, expected_num_shorts",
|
|
|
|
[
|
|
|
|
([], [], 0),
|
|
|
|
([0], [[1]], 0),
|
|
|
|
([0], [[128]], 1),
|
|
|
|
([0, 1, 2], [[128, 1, 2], [3, -129, 5], [6, 7, 8]], 2),
|
|
|
|
([0, 1, 2], [[0, 128, 2], [3, 4, 5], [6, 7, -129]], 3),
|
2021-05-04 14:41:01 +02:00
|
|
|
([0], [[32768]], 0x8001),
|
|
|
|
([0, 1, 2], [[32768, 1, 2], [3, -129, 5], [6, 7, 8]], 0x8001),
|
|
|
|
([0, 1, 2], [[32768, 1, 2], [3, -32769, 5], [6, 7, 8]], 0x8002),
|
|
|
|
([0, 1, 2], [[0, 32768, 2], [3, 4, 5], [6, 7, -32769]], 0x8003),
|
2017-03-10 16:00:57 +00:00
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
"0_regions_0_deltas",
|
|
|
|
"1_region_1_uint8",
|
|
|
|
"1_region_1_short",
|
|
|
|
"3_regions_2_shorts_ordered",
|
|
|
|
"3_regions_2_shorts_unordered",
|
2021-05-04 14:41:01 +02:00
|
|
|
"1_region_1_long",
|
|
|
|
"3_regions_1_long_ordered",
|
|
|
|
"3_regions_2_longs_ordered",
|
|
|
|
"3_regions_2_longs_unordered",
|
2017-03-10 16:00:57 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_buildVarData_no_optimize(region_indices, items, expected_num_shorts):
|
|
|
|
data = buildVarData(region_indices, items, optimize=False)
|
|
|
|
|
|
|
|
assert data.ItemCount == len(items)
|
|
|
|
assert data.NumShorts == expected_num_shorts
|
|
|
|
assert data.VarRegionCount == len(region_indices)
|
|
|
|
assert data.VarRegionIndex == region_indices
|
|
|
|
assert data.Item == items
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
[
|
|
|
|
"region_indices",
|
|
|
|
"items",
|
|
|
|
"expected_num_shorts",
|
|
|
|
"expected_regions",
|
|
|
|
"expected_items",
|
|
|
|
],
|
|
|
|
[
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 2], [3, 4, 5], [6, 7, 8]],
|
|
|
|
0,
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 2], [3, 4, 5], [6, 7, 8]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 128, 2], [3, 4, 5], [6, 7, 8]],
|
|
|
|
1,
|
|
|
|
[1, 0, 2],
|
|
|
|
[[128, 0, 2], [4, 3, 5], [7, 6, 8]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 128], [3, 4, 5], [6, -129, 8]],
|
|
|
|
2,
|
|
|
|
[1, 2, 0],
|
|
|
|
[[1, 128, 0], [4, 5, 3], [-129, 8, 6]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[128, 1, -129], [3, 4, 5], [6, 7, 8]],
|
|
|
|
2,
|
|
|
|
[0, 2, 1],
|
|
|
|
[[128, -129, 1], [3, 5, 4], [6, 8, 7]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 128], [3, -129, 5], [256, 7, 8]],
|
2022-12-13 11:26:36 +00:00
|
|
|
3,
|
2017-03-10 16:00:57 +00:00
|
|
|
[0, 1, 2],
|
2018-02-20 20:49:00 -08:00
|
|
|
[[0, 1, 128], [3, -129, 5], [256, 7, 8]],
|
2022-12-13 11:26:36 +00:00
|
|
|
),
|
2018-02-20 20:49:00 -08:00
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 128, 2], [0, 4, 5], [0, 7, 8]],
|
2022-12-13 11:26:36 +00:00
|
|
|
1,
|
2018-02-20 20:49:00 -08:00
|
|
|
[1, 2],
|
|
|
|
[[128, 2], [4, 5], [7, 8]],
|
2021-05-04 14:49:12 +02:00
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 32768, 2], [3, 4, 5], [6, 7, 8]],
|
|
|
|
0x8001,
|
|
|
|
[1, 0, 2],
|
|
|
|
[[32768, 0, 2], [4, 3, 5], [7, 6, 8]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 32768], [3, 4, 5], [6, -32769, 8]],
|
|
|
|
0x8002,
|
|
|
|
[1, 2, 0],
|
|
|
|
[[1, 32768, 0], [4, 5, 3], [-32769, 8, 6]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[32768, 1, -32769], [3, 4, 5], [6, 7, 8]],
|
|
|
|
0x8002,
|
|
|
|
[0, 2, 1],
|
|
|
|
[[32768, -32769, 1], [3, 5, 4], [6, 8, 7]],
|
|
|
|
),
|
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 32768], [3, -32769, 5], [65536, 7, 8]],
|
|
|
|
0x8003,
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 1, 32768], [3, -32769, 5], [65536, 7, 8]],
|
2022-12-13 11:26:36 +00:00
|
|
|
),
|
2021-05-04 14:49:12 +02:00
|
|
|
(
|
|
|
|
[0, 1, 2],
|
|
|
|
[[0, 32768, 2], [0, 4, 5], [0, 7, 8]],
|
|
|
|
0x8001,
|
|
|
|
[1, 2],
|
|
|
|
[[32768, 2], [4, 5], [7, 8]],
|
|
|
|
),
|
2017-03-10 16:00:57 +00:00
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
"0/3_shorts_no_reorder",
|
|
|
|
"1/3_shorts_reorder",
|
|
|
|
"2/3_shorts_reorder",
|
|
|
|
"2/3_shorts_same_row_reorder",
|
|
|
|
"3/3_shorts_no_reorder",
|
2018-02-20 20:49:00 -08:00
|
|
|
"1/3_shorts_1/3_zeroes",
|
2021-05-04 14:49:12 +02:00
|
|
|
"1/3_longs_reorder",
|
|
|
|
"2/3_longs_reorder",
|
|
|
|
"2/3_longs_same_row_reorder",
|
|
|
|
"3/3_longs_no_reorder",
|
|
|
|
"1/3_longs_1/3_zeroes",
|
2017-03-10 16:00:57 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_buildVarData_optimize(
|
|
|
|
region_indices, items, expected_num_shorts, expected_regions, expected_items
|
|
|
|
):
|
|
|
|
data = buildVarData(region_indices, items, optimize=True)
|
|
|
|
|
|
|
|
assert data.ItemCount == len(items)
|
|
|
|
assert data.NumShorts == expected_num_shorts
|
2018-02-20 20:49:00 -08:00
|
|
|
assert data.VarRegionCount == len(expected_regions)
|
2017-03-10 16:00:57 +00:00
|
|
|
assert data.VarRegionIndex == expected_regions
|
|
|
|
assert data.Item == expected_items
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2017-03-10 16:00:57 +00:00
|
|
|
sys.exit(pytest.main(sys.argv))
|