Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/unary_operators.cc

overpass_api/statements/unary_operators.cc

22 of 25 instrumented lines run by the suite (88.0%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include "../data/tag_store.h"
20#include "../data/utils.h"
21#include "unary_operators.h"
24Evaluator_Prefix_Operator::Evaluator_Prefix_Operator(int line_number_)
2516834 q : Evaluator_Unary_Function(line_number_) {}
28void Evaluator_Prefix_Operator::add_substatements(Statement* result, const std::string& operator_name,
29 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
30 Statement::Factory& stmt_factory, Error_Output* error_output)
3116834 q{
3216834 q if (result)
3316834 q {
3416834 q Statement* rhs = stmt_factory.create_evaluator(
3516834 q tree_it.rhs(), tree_context, Statement::Single_Return_Type_Checker(Statement::string));
3616834 q if (rhs)
3716834 q result->add_statement(rhs, "");
380 else if (error_output)
390 error_output->add_parse_error(std::string("Operator \"") + operator_name
400 + "\" needs a right-hand-side argument", tree_it->line_col.first);
4116834 q }
4216834 q}
45//-----------------------------------------------------------------------------
48Operator_Stmt_Maker< Evaluator_Not > Evaluator_Not::statement_maker;
49Operator_Eval_Maker< Evaluator_Not > Evaluator_Not::evaluator_maker;
52std::string Evaluator_Not::process(const std::string& rhs_s) const
534362614 q{
544362614 q return string_represents_boolean_true(rhs_s) ? "0" : "1";
554362614 q}
58//-----------------------------------------------------------------------------
61Operator_Stmt_Maker< Evaluator_Negate > Evaluator_Negate::statement_maker;
62Operator_Eval_Maker< Evaluator_Negate > Evaluator_Negate::evaluator_maker;
65std::string Evaluator_Negate::process(const std::string& rhs_s) const
661081317 q{
671081317 q int64 rhs_l = 0;
681081317 q if (try_int64(rhs_s, rhs_l))
691079711 q return to_string(-rhs_l);
71167 q double rhs_d = 0;
72167 q if (try_double(rhs_s, rhs_d))
73157 q return to_string(-rhs_d);
7511 q return "NaN";