From 52f002c74b50904b65beed885578461ebc3842f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 18 Jul 2019 11:24:04 +0200 Subject: [PATCH] documentation: make the general search tests backend-independent. It stays C++-specific, but since the implementation doesn't care about the language, it's okay. --- CONTRIBUTING.rst | 2 +- documentation/test/__init__.py | 23 ++ documentation/test/_search_test_metadata.py | 46 ++++ .../js-test-data/.gitattributes | 0 .../js-test-data/empty.bin | Bin documentation/test/js-test-data/nested.bin | Bin 0 -> 331 bytes .../js-test-data/searchdata.b85 | 2 +- .../js-test-data/searchdata.bin | Bin 745 -> 674 bytes .../js-test-data/short.bin | 0 .../js-test-data/unicode.bin | Bin 231 -> 160 bytes .../js-test-data/wrong-magic.bin | 0 .../js-test-data/wrong-version.bin | Bin .../populate-js-test-data.py | 3 +- .../{test_doxygen => test}/test-search.js | 12 +- documentation/test/test_search.py | 238 ++++++++++++++++++ .../test_doxygen/js-test-data/nested.bin | Bin 402 -> 0 bytes documentation/test_doxygen/test_search.py | 221 +--------------- package/ci/travis.yml | 6 +- 18 files changed, 322 insertions(+), 231 deletions(-) create mode 100644 documentation/test/__init__.py create mode 100644 documentation/test/_search_test_metadata.py rename documentation/{test_doxygen => test}/js-test-data/.gitattributes (100%) rename documentation/{test_doxygen => test}/js-test-data/empty.bin (100%) create mode 100644 documentation/test/js-test-data/nested.bin rename documentation/{test_doxygen => test}/js-test-data/searchdata.b85 (68%) rename documentation/{test_doxygen => test}/js-test-data/searchdata.bin (77%) rename documentation/{test_doxygen => test}/js-test-data/short.bin (100%) rename documentation/{test_doxygen => test}/js-test-data/unicode.bin (55%) rename documentation/{test_doxygen => test}/js-test-data/wrong-magic.bin (100%) rename documentation/{test_doxygen => test}/js-test-data/wrong-version.bin (100%) rename documentation/{test_doxygen => test}/populate-js-test-data.py (97%) rename documentation/{test_doxygen => test}/test-search.js (97%) create mode 100755 documentation/test/test_search.py delete mode 100644 documentation/test_doxygen/js-test-data/nested.bin diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 32057e93..e26c32b7 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -109,7 +109,7 @@ There is no possibility of getting code coverage for Jinja2 templates, though. # open htmlcov/index.html in your browser cd documentation - node ./node_modules/istanbul/lib/cli.js cover test_doxygen/test-search.js + node ./node_modules/istanbul/lib/cli.js cover test/test-search.js # open coverage/lcov-report/index.html in your browser cd plugins diff --git a/documentation/test/__init__.py b/documentation/test/__init__.py new file mode 100644 index 00000000..e2a942e7 --- /dev/null +++ b/documentation/test/__init__.py @@ -0,0 +1,23 @@ +# +# This file is part of m.css. +# +# Copyright © 2017, 2018, 2019 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# diff --git a/documentation/test/_search_test_metadata.py b/documentation/test/_search_test_metadata.py new file mode 100644 index 00000000..abe6f1a2 --- /dev/null +++ b/documentation/test/_search_test_metadata.py @@ -0,0 +1,46 @@ +# +# This file is part of m.css. +# +# Copyright © 2017, 2018, 2019 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +import enum + +from _search import CssClass + +# Taken from doxygen.py, with stuff that's unused in the generic tests removed. +# It's C++-specific but the implementation doesn't really care, actually ;) + +class EntryType(enum.Enum): + # Order must match the search_type_map below; first value is reserved for + # ResultFlag.ALIAS + PAGE = 1 + NAMESPACE = 2 + CLASS = 3 + FUNC = 4 + +# Order must match the EntryType above +search_type_map = [ + (CssClass.SUCCESS, "page"), + (CssClass.PRIMARY, "namespace"), + (CssClass.PRIMARY, "class"), + (CssClass.INFO, "func") +] diff --git a/documentation/test_doxygen/js-test-data/.gitattributes b/documentation/test/js-test-data/.gitattributes similarity index 100% rename from documentation/test_doxygen/js-test-data/.gitattributes rename to documentation/test/js-test-data/.gitattributes diff --git a/documentation/test_doxygen/js-test-data/empty.bin b/documentation/test/js-test-data/empty.bin similarity index 100% rename from documentation/test_doxygen/js-test-data/empty.bin rename to documentation/test/js-test-data/empty.bin diff --git a/documentation/test/js-test-data/nested.bin b/documentation/test/js-test-data/nested.bin new file mode 100644 index 0000000000000000000000000000000000000000..6a92cb9c3e9ee70e07dc536fc613d6ac4df0dfef GIT binary patch literal 331 zcmX|*Jxc>Y5Qd+*L=cPE1Og(G!a@)tffQj28-szsfhbrBVLdi?MRpVJ15D$8Nb9e4 zZu3#>&d&S3^X#NAAJXLycog{6szt9Zc;pfqqz6G-U2dQt=|g@8HF6JDNYt6Y4w*uU zJV$Q^4p~Ib8*GqIRfLYFzoWNO4zgA{QYwkgNYh`c{wPO(89u?os~!i_y{?toJT#tQ zy{oo1bBBIZ)Ltpq#-z3`SdN$D_7P=aV9eZYysOJyv`)>@#+Y{-a!0ndRdoQK2yKmK X%qCaTlflI;!>!HTd51W+YC`r8y5~i2 literal 0 HcmV?d00001 diff --git a/documentation/test_doxygen/js-test-data/searchdata.b85 b/documentation/test/js-test-data/searchdata.b85 similarity index 68% rename from documentation/test_doxygen/js-test-data/searchdata.b85 rename to documentation/test/js-test-data/searchdata.b85 index 3239298a..1de2e518 100644 --- a/documentation/test_doxygen/js-test-data/searchdata.b85 +++ b/documentation/test/js-test-data/searchdata.b85 @@ -1 +1 @@ -O+!-w2LOZt004pl003kG000310RR921ONaj009U904M+f4gdgd009&L0BHdL0{{R4AOHX<00ATb04M+fDgXd(00A%n0BHaLHUI!^00BGz06GBy0suk)fI0vHNB{tG00B?{0B-;RRsaBW00CS80Am0FVgLYT0RRO600C|Q04V?gasU7*00DRa0B!&QegFVz00D#m0BryPiU0sQ0RaR6kN|)>00EW&0A&CHo&W%600E=`0B!&QssI3C00SBT0BvXh0Cund0CE5Uwg3P+0RaF2!~lRg00GJX0B8UK(f|N-0{{U40{{g800G_r04V?g<^TXF00Ha(0B!&R*Z=@w@&Ev70RRU8009C40A&CH1_1zU009gE0A~OJ5&-~i0RadA7y$rb00ABW0CWHWCIJ9r00OE20AVZv0A&FH1^@s7JOKb@00BS&0A~OJMgag}00B$^0B`^SQUL&B00CG50CfNa_y7QHXaE3qG64W`UI74eC;$K;KL7x!R{#J?djJ5bkpKWlvj70C$p8QlaA9X<0CRO>aA9X00EW&0A&CHo&W%600E=`0B!&QssI3C00SBT0BvXh0Cund0CE5Uwg3P+0RaF2!~lRg00GJX0B8UK(f|N-0{{U40{{g800G_r04V?g<^TXF00Ha(0B!&R*Z=@w@&Ev70RRU8009C40A&CH1_1zU009gE0A~OJ5&-~i0RadA7y$rb00ABW0CWHWCIJ9r00OE20AVZv0A&FH1^@s7JOKb@00BS&0A~OJMgag}00B$^0B`^SQUL&B00CG50CfNa_y7QHXaE3qG64W`UI74eC;$K;KL7wpR{#JydjJ4QkpKWVvj6~1$p8QlaA9X<0CRO>aA9X03uI0J)KH3Ng^L2Rna0UjiY6gat6B!shHZw4+ojix}d72!f5|cKg0i!9SHKPNwJF^$7 zA8Qa}1Vao%3PXB9VtQ&`Vs2`2L1J=hdQpC9L2^!FadB};QE75XXJVtQ&`Vs2`2L1J=ha!z7#aaw6!G62)m3^)J) delta 109 zcmZ3$_?&S +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +import os +import sys +import unittest +from types import SimpleNamespace as Empty + +from ._search_test_metadata import EntryType, search_type_map +from _search import Trie, ResultMap, ResultFlag, serialize_search_data, pretty_print_trie, pretty_print_map, pretty_print, searchdata_filename + +from test_doxygen import IntegrationTestCase + +class TrieSerialization(unittest.TestCase): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.maxDiff = None + + def compare(self, serialized: bytes, expected: str): + pretty = pretty_print_trie(serialized)[0] + #print(pretty) + self.assertEqual(pretty, expected.strip()) + + def test_empty(self): + trie = Trie() + + serialized = trie.serialize() + self.compare(serialized, "") + self.assertEqual(len(serialized), 6) + + def test_single(self): + trie = Trie() + trie.insert("magnum", 1337) + trie.insert("magnum", 21) + + serialized = trie.serialize() + self.compare(serialized, """ +magnum [1337, 21] +""") + self.assertEqual(len(serialized), 46) + + def test_multiple(self): + trie = Trie() + + trie.insert("math", 0) + trie.insert("math::vector", 1, lookahead_barriers=[4]) + trie.insert("vector", 1) + trie.insert("math::range", 2) + trie.insert("range", 2) + + trie.insert("math::min", 3) + trie.insert("min", 3) + trie.insert("math::max", 4) + trie.insert("max", 4) + trie.insert("math::minmax", 5) + trie.insert("minmax", 5) + + trie.insert("math::vector::minmax", 6, lookahead_barriers=[4, 12]) + trie.insert("vector::minmax", 6, lookahead_barriers=[6]) + trie.insert("minmax", 6) + trie.insert("math::vector::min", 7) + trie.insert("vector::min", 7) + trie.insert("min", 7) + trie.insert("math::vector::max", 8) + trie.insert("vector::max", 8) + trie.insert("max", 8) + + trie.insert("math::range::min", 9, lookahead_barriers=[4, 11]) + trie.insert("range::min", 9, lookahead_barriers=[5]) + trie.insert("min", 9) + + trie.insert("math::range::max", 10) + trie.insert("range::max", 10) + trie.insert("max", 10) + + serialized = trie.serialize() + self.compare(serialized, """ +math [0] +||| :$ +||| :vector [1] +||| | :$ +||| | :min [7] +||| | | max [6] +||| | ax [8] +||| range [2] +||| | :$ +||| | :min [9] +||| | ax [10] +||| min [3] +||| || max [5] +||| |ax [4] +||x [4, 8, 10] +|in [3, 7, 9] +|| max [5, 6] +vector [1] +| :$ +| :min [7] +| | max [6] +| ax [8] +range [2] +| :$ +| :min [9] +| ax [10] +""") + self.assertEqual(len(serialized), 340) + + def test_unicode(self): + trie = Trie() + + trie.insert("hýždě", 0) + trie.insert("hárá", 1) + + serialized = trie.serialize() + self.compare(serialized, """ +h0xc3 + 0xbd + 0xc5 + | 0xbe + | d0xc4 + | 0x9b + | [0] + 0xa1 + r0xc3 + | 0xa1 + | [1] +""") + self.assertEqual(len(serialized), 82) + +class MapSerialization(unittest.TestCase): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.maxDiff = None + + def compare(self, serialized: bytes, expected: str): + pretty = pretty_print_map(serialized, entryTypeClass=EntryType) + #print(pretty) + self.assertEqual(pretty, expected.strip()) + + def test_empty(self): + map = ResultMap() + + serialized = map.serialize() + self.compare(serialized, "") + self.assertEqual(len(serialized), 4) + + def test_single(self): + map = ResultMap() + self.assertEqual(map.add("Magnum", "namespaceMagnum.html", suffix_length=11, flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE)), 0) + + serialized = map.serialize() + self.compare(serialized, """ +0: Magnum [suffix_length=11, type=NAMESPACE] -> namespaceMagnum.html +""") + self.assertEqual(len(serialized), 36) + + def test_multiple(self): + map = ResultMap() + + self.assertEqual(map.add("Math", "namespaceMath.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE)), 0) + self.assertEqual(map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)), 1) + self.assertEqual(map.add("Math::Range", "classMath_1_1Range.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)), 2) + self.assertEqual(map.add("Math::min()", "namespaceMath.html#abcdef2875", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.FUNC)), 3) + self.assertEqual(map.add("Math::max(int, int)", "namespaceMath.html#abcdef1234", suffix_length=8, flags=ResultFlag.from_type(ResultFlag.DEPRECATED|ResultFlag.DELETED, EntryType.FUNC)), 4) + self.assertEqual(map.add("Rectangle", "", alias=2), 5) + self.assertEqual(map.add("Rectangle::Rect()", "", suffix_length=2, alias=2), 6) + + serialized = map.serialize() + self.compare(serialized, """ +0: Math [type=NAMESPACE] -> namespaceMath.html +1: ::Vector [prefix=0[:0], type=CLASS] -> classMath_1_1Vector.html +2: ::Range [prefix=0[:0], type=CLASS] -> classMath_1_1Range.html +3: ::min() [prefix=0[:18], type=FUNC] -> #abcdef2875 +4: ::max(int, int) [prefix=0[:18], suffix_length=8, deprecated, deleted, type=FUNC] -> #abcdef1234 +5: Rectangle [alias=2] -> +6: ::Rect() [alias=2, prefix=5[:0], suffix_length=2] -> +""") + self.assertEqual(len(serialized), 203) + +class Serialization(unittest.TestCase): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.maxDiff = None + + def compare(self, serialized: bytes, expected: str): + pretty = pretty_print(serialized, entryTypeClass=EntryType)[0] + #print(pretty) + self.assertEqual(pretty, expected.strip()) + + def test(self): + trie = Trie() + map = ResultMap() + + trie.insert("math", map.add("Math", "namespaceMath.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE))) + index = map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)) + trie.insert("math::vector", index) + trie.insert("vector", index) + index = map.add("Math::Range", "classMath_1_1Range.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)) + trie.insert("math::range", index) + trie.insert("range", index) + + serialized = serialize_search_data(trie, map, search_type_map, 3) + self.compare(serialized, """ +3 symbols +math [0] +| ::vector [1] +| range [2] +vector [1] +range [2] +0: Math [type=NAMESPACE] -> namespaceMath.html +1: ::Vector [prefix=0[:0], type=CLASS] -> classMath_1_1Vector.html +2: ::Range [prefix=0[:0], type=CLASS] -> classMath_1_1Range.html +(EntryType.PAGE, CssClass.SUCCESS, 'page'), +(EntryType.NAMESPACE, CssClass.PRIMARY, 'namespace'), +(EntryType.CLASS, CssClass.PRIMARY, 'class'), +(EntryType.FUNC, CssClass.INFO, 'func') +""") + self.assertEqual(len(serialized), 277) diff --git a/documentation/test_doxygen/js-test-data/nested.bin b/documentation/test_doxygen/js-test-data/nested.bin deleted file mode 100644 index 39d332c92eb788904e29b24c6b0b5093bdbe0c84..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 402 zcmX|+PfNo<5XIjlEqKz4Ab2Q6JP3tqK|vyjpjatHq=I-Tlr@?Bfn*aln_@102d{ow zCtK@bc6Q!-{B}0Hf29F_089w@k}ge-0Z@YWfEKh5XzF!31~PbuKso{}=oC-{Pn=7j z16>0KbnCnafI$n#c>yZWn`{t=r*By+ zRH<%DXjO7ktBAMrG_$2p4uT+5Hp6Q?(sdUPS3e_}Q z;EvFDXS%F6q7!dI7j#88bm!0g#qfE!q<5?kBdt}+|9hpTYHJ5b%mnt2yQ* Y&P|dRoU}TUDc8*MrM|`+Rcw^`1-#T=YybcN diff --git a/documentation/test_doxygen/test_search.py b/documentation/test_doxygen/test_search.py index 707c748e..4ed0a3c4 100755 --- a/documentation/test_doxygen/test_search.py +++ b/documentation/test_doxygen/test_search.py @@ -27,229 +27,12 @@ import argparse import os import sys -import unittest -from types import SimpleNamespace as Empty -from doxygen import EntryType, search_type_map -from _search import Trie, ResultMap, ResultFlag, serialize_search_data, pretty_print_trie, pretty_print_map, pretty_print, searchdata_filename +from doxygen import EntryType +from _search import pretty_print, searchdata_filename from test_doxygen import IntegrationTestCase -class TrieSerialization(unittest.TestCase): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.maxDiff = None - - def compare(self, serialized: bytes, expected: str): - pretty = pretty_print_trie(serialized)[0] - #print(pretty) - self.assertEqual(pretty, expected.strip()) - - def test_empty(self): - trie = Trie() - - serialized = trie.serialize() - self.compare(serialized, "") - self.assertEqual(len(serialized), 6) - - def test_single(self): - trie = Trie() - trie.insert("magnum", 1337) - trie.insert("magnum", 21) - - serialized = trie.serialize() - self.compare(serialized, """ -magnum [1337, 21] -""") - self.assertEqual(len(serialized), 46) - - def test_multiple(self): - trie = Trie() - - trie.insert("math", 0) - trie.insert("math::vector", 1, lookahead_barriers=[4]) - trie.insert("vector", 1) - trie.insert("math::range", 2) - trie.insert("range", 2) - - trie.insert("math::min", 3) - trie.insert("min", 3) - trie.insert("math::max", 4) - trie.insert("max", 4) - trie.insert("math::minmax", 5) - trie.insert("minmax", 5) - - trie.insert("math::vector::minmax", 6, lookahead_barriers=[4, 12]) - trie.insert("vector::minmax", 6, lookahead_barriers=[6]) - trie.insert("minmax", 6) - trie.insert("math::vector::min", 7) - trie.insert("vector::min", 7) - trie.insert("min", 7) - trie.insert("math::vector::max", 8) - trie.insert("vector::max", 8) - trie.insert("max", 8) - - trie.insert("math::range::min", 9, lookahead_barriers=[4, 11]) - trie.insert("range::min", 9, lookahead_barriers=[5]) - trie.insert("min", 9) - - trie.insert("math::range::max", 10) - trie.insert("range::max", 10) - trie.insert("max", 10) - - serialized = trie.serialize() - self.compare(serialized, """ -math [0] -||| :$ -||| :vector [1] -||| | :$ -||| | :min [7] -||| | | max [6] -||| | ax [8] -||| range [2] -||| | :$ -||| | :min [9] -||| | ax [10] -||| min [3] -||| || max [5] -||| |ax [4] -||x [4, 8, 10] -|in [3, 7, 9] -|| max [5, 6] -vector [1] -| :$ -| :min [7] -| | max [6] -| ax [8] -range [2] -| :$ -| :min [9] -| ax [10] -""") - self.assertEqual(len(serialized), 340) - - def test_unicode(self): - trie = Trie() - - trie.insert("hýždě", 0) - trie.insert("hárá", 1) - - serialized = trie.serialize() - self.compare(serialized, """ -h0xc3 - 0xbd - 0xc5 - | 0xbe - | d0xc4 - | 0x9b - | [0] - 0xa1 - r0xc3 - | 0xa1 - | [1] -""") - self.assertEqual(len(serialized), 82) - -class MapSerialization(unittest.TestCase): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.maxDiff = None - - def compare(self, serialized: bytes, expected: str): - pretty = pretty_print_map(serialized, entryTypeClass=EntryType) - #print(pretty) - self.assertEqual(pretty, expected.strip()) - - def test_empty(self): - map = ResultMap() - - serialized = map.serialize() - self.compare(serialized, "") - self.assertEqual(len(serialized), 4) - - def test_single(self): - map = ResultMap() - self.assertEqual(map.add("Magnum", "namespaceMagnum.html", suffix_length=11, flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE)), 0) - - serialized = map.serialize() - self.compare(serialized, """ -0: Magnum [suffix_length=11, type=NAMESPACE] -> namespaceMagnum.html -""") - self.assertEqual(len(serialized), 36) - - def test_multiple(self): - map = ResultMap() - - self.assertEqual(map.add("Math", "namespaceMath.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE)), 0) - self.assertEqual(map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)), 1) - self.assertEqual(map.add("Math::Range", "classMath_1_1Range.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)), 2) - self.assertEqual(map.add("Math::min()", "namespaceMath.html#abcdef2875", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.FUNC)), 3) - self.assertEqual(map.add("Math::max(int, int)", "namespaceMath.html#abcdef1234", suffix_length=8, flags=ResultFlag.from_type(ResultFlag.DEPRECATED|ResultFlag.DELETED, EntryType.FUNC)), 4) - self.assertEqual(map.add("Rectangle", "", alias=2), 5) - self.assertEqual(map.add("Rectangle::Rect()", "", suffix_length=2, alias=2), 6) - - serialized = map.serialize() - self.compare(serialized, """ -0: Math [type=NAMESPACE] -> namespaceMath.html -1: ::Vector [prefix=0[:0], type=CLASS] -> classMath_1_1Vector.html -2: ::Range [prefix=0[:0], type=CLASS] -> classMath_1_1Range.html -3: ::min() [prefix=0[:18], type=FUNC] -> #abcdef2875 -4: ::max(int, int) [prefix=0[:18], suffix_length=8, deprecated, deleted, type=FUNC] -> #abcdef1234 -5: Rectangle [alias=2] -> -6: ::Rect() [alias=2, prefix=5[:0], suffix_length=2] -> -""") - self.assertEqual(len(serialized), 203) - -class Serialization(unittest.TestCase): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.maxDiff = None - - def compare(self, serialized: bytes, expected: str): - pretty = pretty_print(serialized, entryTypeClass=EntryType)[0] - #print(pretty) - self.assertEqual(pretty, expected.strip()) - - def test(self): - trie = Trie() - map = ResultMap() - - trie.insert("math", map.add("Math", "namespaceMath.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE))) - index = map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)) - trie.insert("math::vector", index) - trie.insert("vector", index) - index = map.add("Math::Range", "classMath_1_1Range.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.CLASS)) - trie.insert("math::range", index) - trie.insert("range", index) - - serialized = serialize_search_data(trie, map, search_type_map, 3) - self.compare(serialized, """ -3 symbols -math [0] -| ::vector [1] -| range [2] -vector [1] -range [2] -0: Math [type=NAMESPACE] -> namespaceMath.html -1: ::Vector [prefix=0[:0], type=CLASS] -> classMath_1_1Vector.html -2: ::Range [prefix=0[:0], type=CLASS] -> classMath_1_1Range.html -(EntryType.PAGE, CssClass.SUCCESS, 'page'), -(EntryType.NAMESPACE, CssClass.PRIMARY, 'namespace'), -(EntryType.GROUP, CssClass.SUCCESS, 'group'), -(EntryType.CLASS, CssClass.PRIMARY, 'class'), -(EntryType.STRUCT, CssClass.PRIMARY, 'struct'), -(EntryType.UNION, CssClass.PRIMARY, 'union'), -(EntryType.TYPEDEF, CssClass.PRIMARY, 'typedef'), -(EntryType.DIR, CssClass.WARNING, 'dir'), -(EntryType.FILE, CssClass.WARNING, 'file'), -(EntryType.FUNC, CssClass.INFO, 'func'), -(EntryType.DEFINE, CssClass.INFO, 'define'), -(EntryType.ENUM, CssClass.PRIMARY, 'enum'), -(EntryType.ENUM_VALUE, CssClass.DEFAULT, 'enum val'), -(EntryType.VAR, CssClass.DEFAULT, 'var') -""") - self.assertEqual(len(serialized), 348) - class Search(IntegrationTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, '', *args, **kwargs) diff --git a/package/ci/travis.yml b/package/ci/travis.yml index a7e6d7f7..d0eac53e 100644 --- a/package/ci/travis.yml +++ b/package/ci/travis.yml @@ -79,7 +79,7 @@ script: - if [ "$WITH_DOCUMENTATION" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation && coverage run -m unittest && cp .coverage ../.coverage.doxygen; fi # Test client doxygen JS - - if [ "$WITH_NODE" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation && node ../node_modules/istanbul/lib/cli.js cover test_doxygen/test-search.js; fi + - if [ "$WITH_NODE" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation && node ../node_modules/istanbul/lib/cli.js cover test/test-search.js; fi # Test that compiled CSS is up-to-date. First display the diff, then check # with diff-index which should print what's wrong and return with non-zero @@ -90,8 +90,8 @@ script: # Test that JS search test data are up-to-date as well. Would be best to do # it on the Node.js job but that one has just Python 3.5 which doesn't know # enum.Flag. - - if [ "$WITH_DOCUMENTATION" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation/test_doxygen && ./populate-js-test-data.py && git diff --color=always . | cat; fi - - if [ "$WITH_DOCUMENTATION" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation/test_doxygen/js-test-data && git diff-index --exit-code HEAD -- .; fi + - if [ "$WITH_DOCUMENTATION" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation/test&& ./populate-js-test-data.py && git diff --color=always . | cat; fi + - if [ "$WITH_DOCUMENTATION" == "ON" ]; then cd $TRAVIS_BUILD_DIR/documentation/test/js-test-data && git diff-index --exit-code HEAD -- .; fi # Cache the downloaded doxygen and pybind11 cache: -- 2.30.2