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

GothenburgBitFactory / taskwarrior / 12343201393

15 Dec 2024 11:30PM UTC coverage: 84.419% (-1.1%) from 85.522%
12343201393

Pull #3724

github

web-flow
Merge 532931b9f into ddae5c4ba
Pull Request #3724: Support importing Taskwarrior v2.x data files

15 of 145 new or added lines in 4 files covered. (10.34%)

183 existing lines in 48 files now uncovered.

19289 of 22849 relevant lines covered (84.42%)

23168.82 hits per line

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

93.33
/src/columns/ColRecur.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 <ColRecur.h>
31
#include <Context.h>
32
#include <Duration.h>
33
#include <Eval.h>
34
#include <Filter.h>
35
#include <Lexer.h>
36
#include <Variant.h>
37
#include <format.h>
38
#include <shared.h>
39
#include <utf8.h>
40

41
////////////////////////////////////////////////////////////////////////////////
42
ColumnRecur::ColumnRecur() {
5,059✔
43
  _name = "recur";
5,059✔
44
  _style = "duration";
5,059✔
45
  _label = "Recur";
5,059✔
46
  _modifiable = true;
5,059✔
47
  _styles = {"duration", "indicator"};
15,177✔
48
  _examples = {"weekly", Context::getContext().config.get("recurrence.indicator")};
15,177✔
49
}
25,295✔
50

51
////////////////////////////////////////////////////////////////////////////////
52
// Overriden so that style <----> label are linked.
53
// Note that you can not determine which gets called first.
54
void ColumnRecur::setStyle(const std::string& value) {
564✔
55
  Column::setStyle(value);
564✔
56

57
  if (_style == "indicator" && _label == "Recur")
563✔
58
    _label = _label.substr(0, Context::getContext().config.get("recurrence.indicator").length());
1,458✔
59
}
563✔
60

61
////////////////////////////////////////////////////////////////////////////////
62
// Set the minimum and maximum widths for the value.
63
void ColumnRecur::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
1,045✔
64
  minimum = maximum = 0;
1,045✔
65
  if (task.has(_name)) {
1,045✔
66
    if (_style == "default" || _style == "duration") {
160✔
67
      minimum = maximum = Duration(task.get(_name)).formatISO().length();
23✔
68
    } else if (_style == "indicator") {
137✔
69
      minimum = maximum = utf8_width(Context::getContext().config.get("recurrence.indicator"));
411✔
70
    }
71
  }
72
}
1,045✔
73

74
////////////////////////////////////////////////////////////////////////////////
75
void ColumnRecur::render(std::vector<std::string>& lines, Task& task, int width, Color& color) {
300✔
76
  if (task.has(_name)) {
300✔
77
    if (_style == "default" || _style == "duration")
160✔
78
      renderStringRight(lines, width, color, Duration(task.get(_name)).formatISO());
23✔
79

80
    else if (_style == "indicator")
137✔
81
      renderStringRight(lines, width, color,
137✔
82
                        Context::getContext().config.get("recurrence.indicator"));
548✔
83
  }
84
}
300✔
85

86
////////////////////////////////////////////////////////////////////////////////
87
// The duration is stored in raw form, but it must still be valid,
88
// and therefore is parsed first.
89
void ColumnRecur::modify(Task& task, const std::string& value) {
75✔
90
  // Try to evaluate 'value'.  It might work.
91
  Variant evaluatedValue;
75✔
92
  try {
93
    Eval e;
75✔
94
    e.addSource(domSource);
75✔
95
    e.evaluateInfixExpression(value, evaluatedValue);
75✔
96
  }
75✔
97

98
  catch (...) {
×
99
    evaluatedValue = Variant(value);
×
UNCOV
100
  }
×
101

102
  if (evaluatedValue.type() == Variant::type_duration) {
75✔
103
    // Store the raw value, for 'recur'.
104
    std::string label = "   [1;37;43mMODIFICATION [0m ";
74✔
105
    Context::getContext().debug(label + _name + " <-- '" + value + '\'');
74✔
106
    task.set(_name, value);
74✔
107
  } else
74✔
108
    throw format("The duration value '{1}' is not supported.", value);
3✔
109
}
75✔
110

111
////////////////////////////////////////////////////////////////////////////////
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