static string merge_packages (string olds, string news) { // Extract usepackage commands from news hashmap<string,path> oldp= latex_get_packages (olds); hashmap<string,path> newp= latex_get_packages (news); hashmap<int,string> packs; iterator<string> it= iterate (newp); while (it->busy ()) { string name= it->next (); if (!oldp->contains (name)) { path p= newp [name]; packs (p[0])= news (p[0], p[1]); } } string accum; for (int i=0; i<N(news); i++) if (test (news, i, "\\begin{document}")) break; else if (packs->contains (i)) accum << packs[i] << "\n"; // Insert result into olds, just after last \usepackage{...} int docpos= search_forwards ("\\begin{document}", olds); if (docpos < 0) return olds; int start= search_backwards ("\\usepackage", docpos, olds); if (start < 0) start= search_backwards ("\\documentclass", docpos, olds); if (start < 0) start= search_backwards ("\\documentstyle", docpos, olds); if (start < 0) return olds; skip_line (olds, start); if (start > docpos) return olds; return olds (0, start) * accum * olds (start, N(olds)); }
TEST_F(PacksTests, test_discovery_cache) { auto c = Config(); c.addPack("kernel", "", getPackWithValidDiscovery()); size_t query_count = 0; for (size_t i = 0; i < 5; i++) { c.scheduledQueries( ([&query_count](const std::string& name, const ScheduledQuery& query) { query_count++; })); } EXPECT_EQ(query_count, 5U); size_t pack_count = 0U; c.packs(([&pack_count](Pack& p) { pack_count++; EXPECT_EQ(p.getStats().total, 5); EXPECT_EQ(p.getStats().hits, 4); EXPECT_EQ(p.getStats().misses, 1); })); EXPECT_EQ(pack_count, 1U); }
TEST_F(PacksTests, test_discovery_cache) { auto c = Config(); // This pack and discovery query are valid, expect the SQL to execute. c.addPack("valid_discovery_pack", "", getPackWithValidDiscovery()); size_t query_count = 0U; size_t query_attemts = 5U; for (size_t i = 0; i < query_attemts; i++) { c.scheduledQueries( ([&query_count](const std::string& name, const ScheduledQuery& query) { query_count++; })); } EXPECT_EQ(query_count, query_attemts); size_t pack_count = 0U; c.packs(([&pack_count, query_attemts](Pack& p) { pack_count++; EXPECT_EQ(p.getStats().total, query_attemts); EXPECT_EQ(p.getStats().hits, query_attemts - 1); EXPECT_EQ(p.getStats().misses, 1U); })); EXPECT_EQ(pack_count, 1U); }