• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 11335495770

14 Oct 2024 09:47PM UTC coverage: 84.223% (-0.6%) from 84.776%
11335495770

push

github

web-flow
[pre-commit.ci] pre-commit autoupdate (#3650)

updates:
- [github.com/psf/black: 24.8.0 → 24.10.0](https://github.com/psf/black/compare/24.8.0...24.10.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

19005 of 22565 relevant lines covered (84.22%)

23473.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.96
/src/columns/ColTypeNumeric.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <ColTypeNumeric.h>
31
#include <Context.h>
32
#include <Eval.h>
33
#include <Filter.h>
34
#include <Variant.h>
35
#include <format.h>
36

37
////////////////////////////////////////////////////////////////////////////////
38
ColumnTypeNumeric::ColumnTypeNumeric() { _type = "numeric"; }
19,199✔
39

40
////////////////////////////////////////////////////////////////////////////////
41
bool ColumnTypeNumeric::validate(const std::string& input) const {
×
42
  return input.length() ? true : false;
×
43
}
44

45
////////////////////////////////////////////////////////////////////////////////
46
void ColumnTypeNumeric::modify(Task& task, const std::string& value) {
17✔
47
  // Try to evaluate 'value'.  It might work.
48
  Variant evaluatedValue;
17✔
49
  try {
50
    Eval e;
17✔
51
    e.addSource(domSource);
17✔
52
    e.evaluateInfixExpression(value, evaluatedValue);
17✔
53
  }
17✔
54

55
  catch (...) {
×
56
    evaluatedValue = Variant(value);
×
57
  }
×
58

59
  std::string label = "   [1;37;43mMODIFICATION [0m ";
17✔
60
  Context::getContext().debug(label + _name + " <-- '" + evaluatedValue.get_string() + "' <-- '" +
51✔
61
                              value + '\'');
34✔
62

63
  // Convert the value of the expression to the correct type if needed
64
  switch (evaluatedValue.type()) {
17✔
65
    // Expected variants - no conversion
66
    case Variant::type_integer:
16✔
67
    case Variant::type_real:
68
      break;
16✔
69
    // Convertible variants - convert to int
70
    case Variant::type_date:
×
71
    case Variant::type_duration:
72
      evaluatedValue.cast(Variant::type_integer);
×
73
      break;
×
74
    // Non-convertible variants
75
    case Variant::type_string:
1✔
76
      throw format("The value '{1}' is not a valid numeric value.", evaluatedValue.get_string());
3✔
77
    default:
×
78
      throw format("Unexpected variant type: '{1}'", evaluatedValue.type());
×
79
  }
80

81
  task.set(_name, evaluatedValue);
16✔
82
}
18✔
83

84
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc