def allow(self, node_stack) -> bool: location = self.accessor(node_stack).file if path_handler.includes_directory(self.target_file): # If the target_file contains directory separators then # match against the same length at the end of the location # location_match = location[-len(self.target_file) :] return location_match == self.target_file else: # If there are no separators, match against the whole filename # at the end of the location # # This is to prevent "Util.cpp" matching "PathUtil.cpp" # location_basename = os.path.basename(location) return location_basename == self.target_file
def test_path_handler(self): self.assertEqual(path_handler.includes_directory("directory/file.h"), True) self.assertEqual(path_handler.includes_directory("directory\\file.h"), True) self.assertEqual(path_handler.includes_directory("file.h"), False)