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) for i in type_sizes: with self.subTest(**i): serialized = serialize_search_data(Serializer(**i), 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') """) # Verify just the smallest and largest size, everything else # should fit in between if i['file_offset_bytes'] == 3 and i[ 'result_id_bytes'] == 2 and i['name_size_bytes'] == 1: self.assertEqual(len(serialized), 282) elif i['file_offset_bytes'] == 4 and i[ 'result_id_bytes'] == 4 and i['name_size_bytes'] == 2: self.assertEqual(len(serialized), 317) else: self.assertGreater(len(serialized), 282) self.assertLess(len(serialized), 317)
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)
from _search_test_metadata import EntryType, search_type_map, type_sizes from _search import Trie, ResultMap, ResultFlag, serialize_search_data, Serializer basedir = pathlib.Path(os.path.dirname( os.path.realpath(__file__))) / 'js-test-data' def type_size_suffix(*, name_size_bytes, result_id_bytes, file_offset_bytes): return f'ns{name_size_bytes}-ri{result_id_bytes}-fo{file_offset_bytes}' # Basic error handling min_size = len( serialize_search_data( Serializer(name_size_bytes=1, result_id_bytes=2, file_offset_bytes=3), Trie(), ResultMap(), [], 0)) with open(basedir / 'short.bin', 'wb') as f: f.write(b'#' * (min_size - 1)) with open(basedir / 'wrong-magic.bin', 'wb') as f: f.write(b'MOS\2') f.write(b'\0' * (min_size - 4)) with open(basedir / 'wrong-version.bin', 'wb') as f: f.write(b'MCS\1') f.write(b'\0' * (min_size - 4)) with open(basedir / 'wrong-result-id-bytes.bin', 'wb') as f: f.write(Serializer.header_struct.pack(b'MCS', 2, 3 << 1, 0, 0, 0)) f.write(b'\0' * (min_size - Serializer.header_struct.size)) # Empty file, in all possible type size combinations
from _search_test_metadata import EntryType, search_type_map from _search import Trie, ResultMap, ResultFlag, serialize_search_data, search_data_header_struct basedir = pathlib.Path(os.path.dirname(os.path.realpath(__file__)))/'js-test-data' # Basic error handling with open(basedir/'short.bin', 'wb') as f: f.write(b'#'*(search_data_header_struct.size - 1)) with open(basedir/'wrong-magic.bin', 'wb') as f: f.write(b'MOS\1 ') with open(basedir/'wrong-version.bin', 'wb') as f: f.write(b'MCS\0 ') with open(basedir/'empty.bin', 'wb') as f: f.write(serialize_search_data(Trie(), ResultMap(), [], 0)) # General test trie = Trie() map = ResultMap() trie.insert("math", map.add("Math", "namespaceMath.html", flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.NAMESPACE))) index = map.add("Math::min(int, int)", "namespaceMath.html#min", suffix_length=8, flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.FUNC)) trie.insert("math::min()", index, lookahead_barriers=[4]) trie.insert("min()", index) index = map.add("Math::Vector", "classMath_1_1Vector.html", flags=ResultFlag.from_type(ResultFlag.DEPRECATED, EntryType.CLASS)) trie.insert("math::vector", index) trie.insert("vector", index) index = map.add("Math::Vector::min() const", "classMath_1_1Vector.html#min", suffix_length=6, flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.FUNC)) trie.insert("math::vector::min()", index, lookahead_barriers=[4, 12])