1 // Copyright 2015, Tobias Hermann and the FunctionalPlus contributors. 2 // https://github.com/Dobiasd/FunctionalPlus 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <doctest/doctest.h> 8 #include <fplus/fplus.hpp> 9 #include <vector> 10 11 TEST_CASE("read_test - read_value") 12 { 13 using namespace fplus; 14 REQUIRE_EQ(read_value<std::size_t>("42"), just<std::size_t>(42)); 15 REQUIRE_EQ(read_value<std::string>("foo"), just<std::string>("foo")); 16 REQUIRE_EQ(read_value<unsigned long>("42"), just<unsigned long>(42)); 17 REQUIRE_EQ(read_value<unsigned long long>("42"), just<unsigned long long>(42)); 18 REQUIRE_EQ(read_value<int>("42"), just<int>(42)); 19 REQUIRE_EQ(read_value<long>("42"), just<long>(42)); 20 REQUIRE_EQ(read_value<long long>("42"), just<long long>(42)); 21 REQUIRE_EQ(read_value<int>("-3"), just<int>(-3)); 22 REQUIRE_EQ(read_value<int>("twenty"), nothing<int>()); 23 REQUIRE_EQ(read_value<int>("3 thousand"), nothing<int>()); 24 REQUIRE_EQ(read_value_with_default<int>(3, "42"), 42); 25 REQUIRE_EQ(read_value_with_default<int>(3, "foo"), 3); 26 REQUIRE_EQ(read_value_with_default<int>(3, ""), 3); 27 REQUIRE_EQ(read_value_unsafe<int>("42"), 42); 28 29 REQUIRE(is_in_interval(-42.4f, -42.2f, unsafe_get_just(read_value<float>("-42.3")))); 30 REQUIRE(is_in_interval(-42.4 , -42.2, unsafe_get_just(read_value<double>("-42.3")))); 31 REQUIRE(is_in_interval(-42.4L, -42.2L, unsafe_get_just(read_value<long double>("-42.3")))); 32 } 33 34 TEST_CASE("read_test - read_value_result") 35 { 36 using namespace fplus; 37 REQUIRE_EQ(read_value_result<int>("42"), (ok<int, std::string>(42))); 38 REQUIRE_EQ(read_value_result<int>("-3"), (ok<int, std::string>(-3))); 39 REQUIRE(is_error(read_value_result<int>("twenty"))); 40 REQUIRE(is_error(read_value_result<int>("3 thousand"))); 41 } 42