variable_tests.cpp 674 B

12345678910111213141516171819202122232425262728293031
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include <catch.hpp>
  8. #include <rpl/rpl.h>
  9. #include <string>
  10. using namespace rpl;
  11. TEST_CASE("basic variable tests", "[rpl::variable]") {
  12. SECTION("simple test") {
  13. auto sum = std::make_shared<int>(0);
  14. {
  15. auto var = variable<int>(1);
  16. auto lifeftime = var.value()
  17. | start_with_next([=](int value) {
  18. *sum += value;
  19. });
  20. var = 1;
  21. var = 11;
  22. var = 111;
  23. var = 111;
  24. }
  25. REQUIRE(*sum == 1 + 11 + 111);
  26. }
  27. }