test.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. function _iostreams(package, snippets)
  2. if not package:config("iostreams") then
  3. return
  4. end
  5. if package:config("zstd") then
  6. table.insert(snippets,
  7. [[
  8. #include <boost/iostreams/filter/zstd.hpp>
  9. #include <boost/iostreams/filtering_stream.hpp>
  10. void test() {
  11. boost::iostreams::filtering_ostream out;
  12. out.push(boost::iostreams::zstd_compressor());
  13. }
  14. ]]
  15. )
  16. end
  17. if package:config("lzma") then
  18. table.insert(snippets,
  19. [[
  20. #include <boost/iostreams/filter/lzma.hpp>
  21. #include <boost/iostreams/filtering_stream.hpp>
  22. void test() {
  23. boost::iostreams::filtering_ostream out;
  24. out.push(boost::iostreams::lzma_compressor());
  25. }
  26. ]]
  27. )
  28. end
  29. end
  30. function _filesystem(package, snippets)
  31. if package:config("filesystem") then
  32. table.insert(snippets,
  33. [[
  34. #include <boost/filesystem.hpp>
  35. #include <iostream>
  36. void test() {
  37. boost::filesystem::path path("/path/to/directory");
  38. if (boost::filesystem::exists(path)) {
  39. std::cout << "Directory exists" << std::endl;
  40. } else {
  41. std::cout << "Directory does not exist" << std::endl;
  42. }
  43. }
  44. ]]
  45. )
  46. end
  47. end
  48. function _date_time(package, snippets)
  49. if package:config("date_time") then
  50. table.insert(snippets,
  51. [[
  52. #include <boost/date_time/gregorian/gregorian.hpp>
  53. void test() {
  54. boost::gregorian::date d(2010, 1, 30);
  55. }
  56. ]]
  57. )
  58. end
  59. end
  60. function _header_only(package, snippets)
  61. table.insert(snippets,
  62. [[
  63. #include <boost/algorithm/string.hpp>
  64. #include <string>
  65. #include <vector>
  66. void test() {
  67. std::string str("a,b");
  68. std::vector<std::string> vec;
  69. boost::algorithm::split(vec, str, boost::algorithm::is_any_of(","));
  70. }
  71. ]]
  72. )
  73. table.insert(snippets,
  74. [[
  75. #include <boost/unordered_map.hpp>
  76. void test() {
  77. boost::unordered_map<std::string, int> map;
  78. map["2"] = 2;
  79. }
  80. ]]
  81. )
  82. end
  83. function main(package)
  84. local snippets = {}
  85. if package:config("header_only") then
  86. _header_only(package, snippets)
  87. else
  88. if not package:config("cmake") then
  89. _header_only(package, snippets)
  90. end
  91. _iostreams(package, snippets)
  92. _filesystem(package, snippets)
  93. _date_time(package, snippets)
  94. end
  95. local opt = {configs = {languages = "c++14"}}
  96. for _, snippet in ipairs(snippets) do
  97. assert(package:check_cxxsnippets({test = snippet}, opt))
  98. end
  99. end