| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // prompt_test.cxx
- // cli-test
- //
- // Created by Sam Jaffe on 10/10/20.
- // Copyright © 2020 Sam Jaffe. All rights reserved.
- //
- #include "cli/prompt.h"
- #include <gmock/gmock.h>
- #include <gtest/gtest.h>
- #if XCODE_UNIT_TEST
- // This is a hack to allow XCode to properly display failures when running
- // unit tests.
- #undef EXPECT_THAT
- #define EXPECT_THAT ASSERT_THAT
- #undef EXPECT_TRUE
- #define EXPECT_TRUE ASSERT_TRUE
- #undef EXPECT_FALSE
- #define EXPECT_FALSE ASSERT_FALSE
- #endif
- TEST(PromptTest, WillOutputEverythingInMessageWithNoSpaces) {
- std::stringstream out;
- auto msg = cli::make_message("Example", 1, true);
- msg->print(out);
- EXPECT_THAT(out.str(), "Example1true");
- }
- TEST(PromptTest, WillRepollIfBadDataProvided) {
- std::stringstream in{"cake\n1"};
- cli::prompt prompt;
-
- int i = prompt.read<int>(in);
- EXPECT_THAT(i, 1);
- }
- TEST(PromptTest, WillDiscardEntireLineOnFailedParse) {
- std::stringstream in{"cake 2\n1"};
- cli::prompt prompt;
-
- int i = prompt.read<int>(in);
- EXPECT_THAT(i, 1);
- }
|