prompt_test.cxx 732 B

12345678910111213141516171819202122232425262728293031323334
  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 "xcode_gtest_helper.h"
  10. TEST(PromptTest, WillOutputEverythingInMessageWithNoSpaces) {
  11. std::stringstream out;
  12. auto msg = cli::make_message("Example", 1, true);
  13. msg->print(out);
  14. EXPECT_THAT(out.str(), "Example1true");
  15. }
  16. TEST(PromptTest, WillRepollIfBadDataProvided) {
  17. std::stringstream in{"cake\n1"};
  18. cli::prompt prompt;
  19. int i = prompt.read<int>(in);
  20. EXPECT_THAT(i, 1);
  21. }
  22. TEST(PromptTest, WillDiscardEntireLineOnFailedParse) {
  23. std::stringstream in{"cake 2\n1"};
  24. cli::prompt prompt;
  25. int i = prompt.read<int>(in);
  26. EXPECT_THAT(i, 1);
  27. }