From 0cd73bb7aa6dd5fc1867ef99e01386a96c02a42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Grie=C3=9Fhammer?= Date: Thu, 14 Sep 2023 19:58:52 +0200 Subject: [PATCH] add tests --- tests/ad_hoc_group_test.fea | 7 +++ tests/catchall_test.fea | 15 +++++ tests/enum_test.fea | 5 ++ tests/group_group_test.fea | 4 ++ .../ad_hoc_group_test.kerndump | 53 +++++++++++++++++ .../kerndumps_expected/catchall_test.kerndump | 34 +++++++++++ tests/kerndumps_expected/enum_test.kerndump | 16 +++++ tests/kerndumps_expected/fea_test.kerndump | 34 +++++++++++ .../group_group_test.kerndump | 25 ++++++++ .../nested_group_test.kerndump | 32 ++++++++++ tests/nested_group_test.fea | 5 ++ tests/test_getKerningPairsFromFEA.py | 59 +++++++++++++++++++ 12 files changed, 289 insertions(+) create mode 100644 tests/ad_hoc_group_test.fea create mode 100644 tests/catchall_test.fea create mode 100644 tests/enum_test.fea create mode 100644 tests/group_group_test.fea create mode 100644 tests/kerndumps_expected/ad_hoc_group_test.kerndump create mode 100644 tests/kerndumps_expected/catchall_test.kerndump create mode 100644 tests/kerndumps_expected/enum_test.kerndump create mode 100644 tests/kerndumps_expected/fea_test.kerndump create mode 100644 tests/kerndumps_expected/group_group_test.kerndump create mode 100644 tests/kerndumps_expected/nested_group_test.kerndump create mode 100644 tests/nested_group_test.fea create mode 100644 tests/test_getKerningPairsFromFEA.py diff --git a/tests/ad_hoc_group_test.fea b/tests/ad_hoc_group_test.fea new file mode 100644 index 0000000..2832c04 --- /dev/null +++ b/tests/ad_hoc_group_test.fea @@ -0,0 +1,7 @@ +@GROUP = [ f g h ]; + +pos [ a b c d e ] [ a b c d e ] -42; # 25 +pos x [ a b c d e ] -42; # 5 +pos [ a b c d e ] x -42; # 5 +pos [ a b c ] @GROUP -42; # 9 +pos @GROUP [ a b c ] -42; # 9 diff --git a/tests/catchall_test.fea b/tests/catchall_test.fea new file mode 100644 index 0000000..bd23d0f --- /dev/null +++ b/tests/catchall_test.fea @@ -0,0 +1,15 @@ +# comment + # comment + +asd # invalid line +@GROUP = [ grouped_1 grouped_2 ]; # comment + +pos A [four.dnom] -42; +pos [ a b c ] A -42; +pos [ a b c ] @GROUP -42; +pos @GROUP @GROUP -42; +subtable; +pos [ a b c ] [four.dnom] -42; +pos [fraction divisionslash] [four.dnom] -42; +pos [fraction divisionslash] [a b c] -42; +pos [x y z] [x y z] 42; diff --git a/tests/enum_test.fea b/tests/enum_test.fea new file mode 100644 index 0000000..3868df4 --- /dev/null +++ b/tests/enum_test.fea @@ -0,0 +1,5 @@ +@GROUP = [ x y z ]; + +enum pos [ a b c ] d -42; # 3 +enum pos [ d e f ] [ g h i ] -42; # 9 +enum pos j [ k @GROUP ] -42; # 4 diff --git a/tests/group_group_test.fea b/tests/group_group_test.fea new file mode 100644 index 0000000..c214048 --- /dev/null +++ b/tests/group_group_test.fea @@ -0,0 +1,4 @@ +@GROUP_1 = [ a b c d e ]; +@GROUP_2 = [ a b c d e ]; + +pos @GROUP_1 @GROUP_2 -42; diff --git a/tests/kerndumps_expected/ad_hoc_group_test.kerndump b/tests/kerndumps_expected/ad_hoc_group_test.kerndump new file mode 100644 index 0000000..4d7a010 --- /dev/null +++ b/tests/kerndumps_expected/ad_hoc_group_test.kerndump @@ -0,0 +1,53 @@ +a a -42 +a b -42 +a c -42 +a d -42 +a e -42 +a f -42 +a g -42 +a h -42 +a x -42 +b a -42 +b b -42 +b c -42 +b d -42 +b e -42 +b f -42 +b g -42 +b h -42 +b x -42 +c a -42 +c b -42 +c c -42 +c d -42 +c e -42 +c f -42 +c g -42 +c h -42 +c x -42 +d a -42 +d b -42 +d c -42 +d d -42 +d e -42 +d x -42 +e a -42 +e b -42 +e c -42 +e d -42 +e e -42 +e x -42 +f a -42 +f b -42 +f c -42 +g a -42 +g b -42 +g c -42 +h a -42 +h b -42 +h c -42 +x a -42 +x b -42 +x c -42 +x d -42 +x e -42 \ No newline at end of file diff --git a/tests/kerndumps_expected/catchall_test.kerndump b/tests/kerndumps_expected/catchall_test.kerndump new file mode 100644 index 0000000..e2f6c2d --- /dev/null +++ b/tests/kerndumps_expected/catchall_test.kerndump @@ -0,0 +1,34 @@ +A four.dnom -42 +a A -42 +a four.dnom -42 +a grouped_1 -42 +a grouped_2 -42 +b A -42 +b four.dnom -42 +b grouped_1 -42 +b grouped_2 -42 +c A -42 +c four.dnom -42 +c grouped_1 -42 +c grouped_2 -42 +divisionslash a -42 +divisionslash b -42 +divisionslash c -42 +divisionslash four.dnom -42 +fraction a -42 +fraction b -42 +fraction c -42 +fraction four.dnom -42 +grouped_1 grouped_1 -42 +grouped_1 grouped_2 -42 +grouped_2 grouped_1 -42 +grouped_2 grouped_2 -42 +x x 42 +x y 42 +x z 42 +y x 42 +y y 42 +y z 42 +z x 42 +z y 42 +z z 42 \ No newline at end of file diff --git a/tests/kerndumps_expected/enum_test.kerndump b/tests/kerndumps_expected/enum_test.kerndump new file mode 100644 index 0000000..6df8dfd --- /dev/null +++ b/tests/kerndumps_expected/enum_test.kerndump @@ -0,0 +1,16 @@ +a d -42 +b d -42 +c d -42 +d g -42 +d h -42 +d i -42 +e g -42 +e h -42 +e i -42 +f g -42 +f h -42 +f i -42 +j k -42 +j x -42 +j y -42 +j z -42 \ No newline at end of file diff --git a/tests/kerndumps_expected/fea_test.kerndump b/tests/kerndumps_expected/fea_test.kerndump new file mode 100644 index 0000000..e2f6c2d --- /dev/null +++ b/tests/kerndumps_expected/fea_test.kerndump @@ -0,0 +1,34 @@ +A four.dnom -42 +a A -42 +a four.dnom -42 +a grouped_1 -42 +a grouped_2 -42 +b A -42 +b four.dnom -42 +b grouped_1 -42 +b grouped_2 -42 +c A -42 +c four.dnom -42 +c grouped_1 -42 +c grouped_2 -42 +divisionslash a -42 +divisionslash b -42 +divisionslash c -42 +divisionslash four.dnom -42 +fraction a -42 +fraction b -42 +fraction c -42 +fraction four.dnom -42 +grouped_1 grouped_1 -42 +grouped_1 grouped_2 -42 +grouped_2 grouped_1 -42 +grouped_2 grouped_2 -42 +x x 42 +x y 42 +x z 42 +y x 42 +y y 42 +y z 42 +z x 42 +z y 42 +z z 42 \ No newline at end of file diff --git a/tests/kerndumps_expected/group_group_test.kerndump b/tests/kerndumps_expected/group_group_test.kerndump new file mode 100644 index 0000000..fc57329 --- /dev/null +++ b/tests/kerndumps_expected/group_group_test.kerndump @@ -0,0 +1,25 @@ +a a -42 +a b -42 +a c -42 +a d -42 +a e -42 +b a -42 +b b -42 +b c -42 +b d -42 +b e -42 +c a -42 +c b -42 +c c -42 +c d -42 +c e -42 +d a -42 +d b -42 +d c -42 +d d -42 +d e -42 +e a -42 +e b -42 +e c -42 +e d -42 +e e -42 \ No newline at end of file diff --git a/tests/kerndumps_expected/nested_group_test.kerndump b/tests/kerndumps_expected/nested_group_test.kerndump new file mode 100644 index 0000000..56dd904 --- /dev/null +++ b/tests/kerndumps_expected/nested_group_test.kerndump @@ -0,0 +1,32 @@ +f_l c -42 +f_l cacute -42 +f_l ccaron -42 +f_l ccedilla -42 +ffl c -42 +ffl cacute -42 +ffl ccaron -42 +ffl ccedilla -42 +fl c -42 +fl cacute -42 +fl ccaron -42 +fl ccedilla -42 +l c -42 +l cacute -42 +l ccaron -42 +l ccedilla -42 +lacute c -42 +lacute cacute -42 +lacute ccaron -42 +lacute ccedilla -42 +lcaron c -42 +lcaron cacute -42 +lcaron ccaron -42 +lcaron ccedilla -42 +lcommaaccent c -42 +lcommaaccent cacute -42 +lcommaaccent ccaron -42 +lcommaaccent ccedilla -42 +lslash c -42 +lslash cacute -42 +lslash ccaron -42 +lslash ccedilla -42 \ No newline at end of file diff --git a/tests/nested_group_test.fea b/tests/nested_group_test.fea new file mode 100644 index 0000000..a5916e6 --- /dev/null +++ b/tests/nested_group_test.fea @@ -0,0 +1,5 @@ +@C_LC = [c ccedilla cacute ccaron]; +@L_LC = [l lslash lacute lcaron lcommaaccent]; +@L_LC_LEFT = [@L_LC ffl fl f_l]; + +pos @L_LC_LEFT @C_LC -42; # 32 diff --git a/tests/test_getKerningPairsFromFEA.py b/tests/test_getKerningPairsFromFEA.py new file mode 100644 index 0000000..7325455 --- /dev/null +++ b/tests/test_getKerningPairsFromFEA.py @@ -0,0 +1,59 @@ +import sys +from pathlib import Path + +if '..' not in sys.path: + sys.path.append('..') # https://stackoverflow.com/a/16985066 + +import getKerningPairsFromFEA as gkp + +TEST_DIR = Path(__file__).parent +REFERENCE_DIR = TEST_DIR / 'kerndumps_expected' + + +def read_file(path): + ''' + Read a file, return the data + ''' + + with open(path, 'r', encoding='utf-8') as f: + data = f.read() + return data + + +def test_group_group(): + input_file = TEST_DIR / 'group_group_test.fea' + dump_file = REFERENCE_DIR / input_file.with_suffix('.kerndump').name + kfr = gkp.FEAKernReader(input_file) + assert('\n'.join(kfr.output) == read_file(dump_file)) + assert len(kfr.output) == 5 * 5 + + +def test_ad_hoc_groups(): + input_file = TEST_DIR / 'ad_hoc_group_test.fea' + dump_file = REFERENCE_DIR / input_file.with_suffix('.kerndump').name + kfr = gkp.FEAKernReader(input_file) + assert('\n'.join(kfr.output) == read_file(dump_file)) + assert len(kfr.output) == 53 + + +def test_enum(): + input_file = TEST_DIR / 'enum_test.fea' + dump_file = REFERENCE_DIR / input_file.with_suffix('.kerndump').name + kfr = gkp.FEAKernReader(input_file) + assert('\n'.join(kfr.output) == read_file(dump_file)) + assert len(kfr.output) == 16 + + +def test_nested_groups(): + input_file = TEST_DIR / 'nested_group_test.fea' + dump_file = REFERENCE_DIR / input_file.with_suffix('.kerndump').name + kfr = gkp.FEAKernReader(input_file) + assert('\n'.join(kfr.output) == read_file(dump_file)) + assert len(kfr.output) == 32 + + +def test_catchall(): + input_file = TEST_DIR / 'catchall_test.fea' + dump_file = REFERENCE_DIR / input_file.with_suffix('.kerndump').name + kfr = gkp.FEAKernReader(input_file) + assert('\n'.join(kfr.output) == read_file(dump_file))