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_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)
def test(self): trie = Trie() map = ResultMap() trie.insert("math", map.add("Math", "namespaceMath.html", flags=ResultFlag.NAMESPACE)) index = map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.CLASS) trie.insert("math::vector", index) trie.insert("vector", index) index = map.add("Math::Range", "classMath_1_1Range.html", flags=ResultFlag.CLASS) trie.insert("math::range", index) trie.insert("range", index) serialized = serialize_search_data(trie, 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 """) self.assertEqual(len(serialized), 241)
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_empty(self): trie = Trie() serialized = trie.serialize() self.compare(serialized, "") self.assertEqual(len(serialized), 6)
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) from dox2html5 import Trie, ResultMap, ResultFlag, serialize_search_data basedir = pathlib.Path(os.path.dirname( os.path.realpath(__file__))) / 'js-test-data' with open(basedir / 'short.bin', 'wb') as f: f.write(b'') with open(basedir / 'wrong-magic.bin', 'wb') as f: f.write(b'MOS\0 ') with open(basedir / 'wrong-version.bin', 'wb') as f: f.write(b'MCS\1 ') with open(basedir / 'empty.bin', 'wb') as f: f.write(serialize_search_data(Trie(), ResultMap(), 0)) trie = Trie() map = ResultMap() trie.insert("math", map.add("Math", "namespaceMath.html", flags=ResultFlag.NAMESPACE)) index = map.add("Math::min(int, int)", "namespaceMath.html#min", suffix_length=8, flags=ResultFlag.FUNC) trie.insert("math::min()", index, lookahead_barriers=[4]) trie.insert("min()", index) index = map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.CLASS | ResultFlag.DEPRECATED)
action='store_true') parser.add_argument('--no-lookahead-barriers', help="don't insert search lookahead barriers", action='store_true') parser.add_argument('--no-prefix-merging', help="don't merge search result prefixes", action='store_true') parser.add_argument('--map', help="print the map instead", action='store_true') parser.add_argument('--unicode', help="print the unicode trie instead", action='store_true') args = parser.parse_args() trie = Trie() trie.insert("magnum", 0) trie.insert("magnum::math", 1, lookahead_barriers=[] if args.no_lookahead_barriers else [6]) trie.insert( "magnum::math::vector", 2, lookahead_barriers=[] if args.no_lookahead_barriers else [6, 12]) trie.insert( "magnum::math::vector::min", 3, lookahead_barriers=[] if args.no_lookahead_barriers else [6, 12, 20]) trie.insert( "magnum::math::range", 4,