prompt_test.cxx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // prompt_test.cxx
  3. // cli-test
  4. //
  5. // Created by Sam Jaffe on 10/10/20.
  6. // Copyright © 2020 Sam Jaffe. All rights reserved.
  7. //
  8. #include "cli/prompt.h"
  9. #include <gmock/gmock.h>
  10. #include <gtest/gtest.h>
  11. #if XCODE_UNIT_TEST
  12. // This is a hack to allow XCode to properly display failures when running
  13. // unit tests.
  14. #undef EXPECT_THAT
  15. #define EXPECT_THAT ASSERT_THAT
  16. #undef EXPECT_TRUE
  17. #define EXPECT_TRUE ASSERT_TRUE
  18. #undef EXPECT_FALSE
  19. #define EXPECT_FALSE ASSERT_FALSE
  20. #endif
  21. TEST(PromptTest, WillOutputEverythingInMessageWithNoSpaces) {
  22. std::stringstream out;
  23. auto msg = cli::make_message("Example", 1, true);
  24. msg->print(out);
  25. EXPECT_THAT(out.str(), "Example1true");
  26. }
  27. TEST(PromptTest, WillRepollIfBadDataProvided) {
  28. std::stringstream in{"cake\n1"};
  29. cli::prompt prompt;
  30. int i = prompt.read<int>(in);
  31. EXPECT_THAT(i, 1);
  32. }
  33. TEST(PromptTest, WillDiscardEntireLineOnFailedParse) {
  34. std::stringstream in{"cake 2\n1"};
  35. cli::prompt prompt;
  36. int i = prompt.read<int>(in);
  37. EXPECT_THAT(i, 1);
  38. }