exception_test.cxx 950 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // exception_test.cxx
  3. // dice-td
  4. //
  5. // Created by Sam Jaffe on 12/18/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #include "xcode_gtest_helper.h"
  9. #include "dice-roll/die.h"
  10. #include "dice-roll/exception.h"
  11. using namespace ::testing;
  12. TEST(DiceExceptionTest, PointerIsActuallyAtTheRightLocation) {
  13. std::string bad{"6d+1"};
  14. try {
  15. dice::from_string(bad);
  16. FAIL();
  17. } catch (dice::unexpected_token const & e) {
  18. EXPECT_THAT(e.pointer().length(), Eq(2));
  19. }
  20. }
  21. TEST(DiceExceptionTest, ErrorAtEndHasSpecialToken) {
  22. std::string bad{"6d"};
  23. try {
  24. dice::from_string(bad);
  25. FAIL();
  26. } catch (dice::unexpected_token const & e) {
  27. EXPECT_THAT(e.pointer(), Eq("<END>"));
  28. }
  29. }
  30. TEST(DiceExceptionTest, ErrorAtEndCanUseFallback) {
  31. std::string bad{"6d"};
  32. try {
  33. dice::from_string(bad);
  34. FAIL();
  35. } catch (dice::unexpected_token const & e) {
  36. EXPECT_THAT(e.pointer(bad.length()), Eq("~^"));
  37. }
  38. }