From e637098b1bb502941fed3c62f9ec71ca4c84334f Mon Sep 17 00:00:00 2001 From: sairajat Date: Tue, 7 Feb 2017 16:14:58 -0500 Subject: [PATCH] Fixed bug in Patterns::Selection --- source/base/parameter_handler.cc | 2 +- .../parameter_handler_3_with_space.cc | 80 +++++++++++++++++++ .../parameter_handler_3_with_space.output | 13 +++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/parameter_handler/parameter_handler_3_with_space.cc create mode 100644 tests/parameter_handler/parameter_handler_3_with_space.output diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index 128e2410b3..a0d6c22ead 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -469,7 +469,7 @@ namespace Patterns std::string tmp(sequence); // remove whitespace at beginning while ((tmp.length() != 0) && (std::isspace (tmp[0]))) - tmp.erase (0,1); + tmp.erase (0,1); // check the different possibilities while (tmp.find('|') != std::string::npos) diff --git a/tests/parameter_handler/parameter_handler_3_with_space.cc b/tests/parameter_handler/parameter_handler_3_with_space.cc new file mode 100644 index 0000000000..ebff780d54 --- /dev/null +++ b/tests/parameter_handler/parameter_handler_3_with_space.cc @@ -0,0 +1,80 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2003 - 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// test the output generated by ParameterHandler::print_parameters(Text) + +#include "../tests.h" +#include +#include +#include +#include + + +int main () +{ + try + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + ParameterHandler prm; + prm.enter_subsection ("Testing"); + prm.declare_entry ("string list", + "a", + Patterns::List(Patterns::Selection(" a|b|c|d|e|f|g|h")), + "docs 1"); + prm.declare_entry ("int", + "1", + Patterns::Integer()); + prm.declare_entry ("double", + "3.1415926", + Patterns::Double(), + "docs 3"); + prm.leave_subsection (); + + // read and then write parameters + prm.read_input(SOURCE_DIR "/prm/parameter_handler_3.prm"); + prm.print_parameters (logfile, ParameterHandler::Text); + } + catch (std::exception &exc) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; + + return 0; +} diff --git a/tests/parameter_handler/parameter_handler_3_with_space.output b/tests/parameter_handler/parameter_handler_3_with_space.output new file mode 100644 index 0000000000..cf97eae312 --- /dev/null +++ b/tests/parameter_handler/parameter_handler_3_with_space.output @@ -0,0 +1,13 @@ + +# Listing of Parameters +# --------------------- +subsection Testing + # docs 3 + set double = 3.1415926 + set int = 3 # default: 1 + + # docs 1 + set string list = a, b, c # default: a +end + + -- 2.39.5