parse.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* parse.cpp - parse testing
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <catch.hpp>
  18. #include <core/util/exceptions.h>
  19. #include <core/time/parse.h>
  20. using namespace rainynite;
  21. using namespace rainynite::core;
  22. TEST_CASE("Parse time", "[time,parse]") {
  23. CHECK(parse_time("0f@12") == Time(0, 12, 0));
  24. CHECK(parse_time("12f@12") == Time(1, 12, 0));
  25. CHECK(parse_time("55f@12") == Time(4, 12, 7));
  26. }
  27. TEST_CASE("Parse time exceptions", "[time,parse]") {
  28. CHECK_THROWS_AS(parse_time("12:15"), ParseError);
  29. CHECK_THROWS_AS(parse_time("5f@"), ParseError);
  30. CHECK_THROWS_AS(parse_time("5.5@12"), ParseError);
  31. }
  32. TEST_CASE("Parse time period", "[time,parse]") {
  33. CHECK(parse_time_period("[0f@12, 2f@12)") == TimePeriod(Time(0, 12, 0), Time(0, 12, 2)));
  34. }
  35. TEST_CASE("Parse time period exceptions", "[time,parse]") {
  36. CHECK_THROWS_AS(parse_time_period("[0f@12, 2f@12"), ParseError);
  37. }