2
0

test.lua 4.0 KB

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