/* Copyright 2016-2021 Michele Santullo * This file is part of "duckhandy". * * "duckhandy" is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * "duckhandy" is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with "duckhandy". If not, see . */ #include "catch2/catch.hpp" #include "duckhandy/version_bt.hpp" TEST_CASE ("Version class tests", "[version][bt]") { using dhandy::Version; { constexpr Version<1> ver{"102"}; static_assert(ver.major() == 102, "Version error"); static_assert(ver.count == 1, "Version error"); CHECK(ver[0] == 102); CHECK_THROWS(ver[1]); CHECK_THROWS(ver[2]); CHECK_THROWS(ver[3]); CHECK_THROWS(ver[4]); } { constexpr Version<3> ver{".aheud15,a.ud22,cu.sh81,.nuad.h44"}; static_assert(ver.count == 3, "Version error"); static_assert(ver.major() == 15, "Version error"); static_assert(ver.minor() == 22, "Version error"); static_assert(ver.revision() == 81, "Version error"); CHECK(ver[0] == 15); CHECK(ver[1] == 22); CHECK(ver[2] == 81); CHECK_THROWS(ver[3]); CHECK_THROWS(ver[4]); } { constexpr Version<10> ver{"1.2.3.44.55.66.777.888.999.101010"}; static_assert(ver.count == 10, "Version error"); static_assert(ver.major() == 1, "Version error"); static_assert(ver.minor() == 2, "Version error"); static_assert(ver.revision() == 3, "Version error"); CHECK(ver[0] == 1); CHECK(ver[1] == 2); CHECK(ver[2] == 3); CHECK(ver[3] == 44); CHECK(ver[4] == 55); CHECK(ver[5] == 66); CHECK(ver[6] == 777); CHECK(ver[7] == 888); CHECK(ver[8] == 999); CHECK(ver[9] == 101010); CHECK_THROWS(ver[10]); } { constexpr Version<4> ver{"1.2.3.", true}; static_assert(ver.count == 4, "Version error"); static_assert(ver.major() == 1, "Version error"); static_assert(ver.minor() == 2, "Version error"); static_assert(ver.revision() == 3, "Version error"); CHECK(ver[0] == 1); CHECK(ver[1] == 2); CHECK(ver[2] == 3); CHECK(ver[3] == 0); CHECK_THROWS(ver[10]); } { constexpr Version<4> ver{"6.7.2-r1"}; static_assert(ver.count == 4, "Version error"); static_assert(ver.major() == 6, "Version error"); static_assert(ver.minor() == 7, "Version error"); static_assert(ver.revision() == 2, "Version error"); CHECK(ver[0] == 6); CHECK(ver[1] == 7); CHECK(ver[2] == 2); CHECK(ver[3] == 1); CHECK_THROWS(ver[10]); } CHECK_THROWS(Version<4>{"4.5"}); }