Line data Source code
1 : /* 2 : * Copyright (c) 2017 Sebastian Weber, Henri Menke. All rights reserved. 3 : * 4 : * This file is part of the pairinteraction library. 5 : * 6 : * The pairinteraction library is free software: you can redistribute it and/or modify 7 : * it under the terms of the GNU Lesser General Public License as published by 8 : * the Free Software Foundation, either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * The pairinteraction library is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU Lesser General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU Lesser General Public License 17 : * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : #include "ConfParser.hpp" 21 : 22 : #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 23 : #include <doctest/doctest.h> 24 : 25 : #include <iostream> 26 : 27 1 : TEST_CASE("conf_parser_test") // NOLINT 28 : { 29 2 : Configuration c; 30 : 31 : // Test subscript setter 32 1 : c["first"] << 2; 33 1 : c["second"] << 1.2; 34 1 : c["third"] << "Hello World!"; 35 1 : c["fourth"] << c["first"]; 36 1 : c["third"] >> c["fifth"]; 37 : 38 : // Test subscript getter and str() conversion 39 1 : CHECK(c["first"].str() == "2"); 40 1 : CHECK(c["second"].str() == "1.2"); 41 1 : CHECK(c["third"].str() == "Hello World!"); 42 1 : CHECK(c["fourth"].str() == "2"); 43 1 : CHECK(c["fifth"].str() == "Hello World!"); 44 1 : CHECK(c.count("first") == 1); 45 : 46 : // Test subscript getter and type deduction 47 : int i; 48 : double d; 49 2 : std::string s; 50 1 : c["first"] >> i; 51 1 : c["second"] >> d; 52 1 : c["third"] >> s; 53 1 : CHECK(i == 2); 54 1 : CHECK(d == 1.2); 55 1 : CHECK(s == "Hello World!"); 56 : 57 : // Test const methods 58 2 : Configuration const cc(c); 59 1 : CHECK(cc["first"].str() == "2"); 60 1 : CHECK(cc["second"].str() == "1.2"); 61 1 : CHECK(cc["third"].str() == "Hello World!"); 62 1 : CHECK(cc["fourth"].str() == "2"); 63 1 : CHECK(cc["fifth"].str() == "Hello World!"); 64 3 : CHECK_THROWS_AS(cc["nonexistent"], std::out_of_range); 65 1 : CHECK(cc.count("first") == 1); 66 : 67 : // Test comparison 68 1 : CHECK(c == cc); 69 : 70 : // finder 71 1 : auto it = c.find("first"); 72 1 : CHECK(it->first == "first"); 73 1 : CHECK(it->second.str() == "2"); 74 : 75 1 : auto cit = cc.find("first"); 76 1 : CHECK(cit->first == "first"); 77 1 : CHECK(cit->second.str() == "2"); 78 : 79 : // iterate 80 6 : for (auto it : c) { 81 : static_cast<void>(it); 82 : } 83 6 : for (auto cit : cc) { 84 : static_cast<void>(cit); 85 : } 86 : 87 : // Test fusion 88 1 : c += cc; 89 1 : }