• 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

65.85
/src/columns/ColUDA.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 <ColUDA.h>
31
#include <Context.h>
32
#include <Datetime.h>
33
#include <Duration.h>
34
#include <format.h>
35
#include <shared.h>
36
#include <stdlib.h>
37
#include <utf8.h>
38

39
////////////////////////////////////////////////////////////////////////////////
40
ColumnUDAString::ColumnUDAString() {
5,216✔
41
  _name = "<uda>";  // Gets overwritten at runtime.
5,216✔
42
  _style = "default";
5,216✔
43
  _label = "";
5,216✔
44
  _modifiable = true;
5,216✔
45
  _uda = true;
5,216✔
46
  _hyphenate = true;
5,216✔
47
  _styles = {_style, "indicator"};
15,648✔
48
}
15,648✔
49

50
////////////////////////////////////////////////////////////////////////////////
51
bool ColumnUDAString::validate(const std::string& value) const {
101✔
52
  // No restrictions.
53
  if (_values.size() == 0) return true;
101✔
54

55
  // Look for exact match value.
56
  for (auto& i : _values)
133✔
57
    if (i == value) return true;
131✔
58

59
  // Fail if not found.
60
  return false;
2✔
61
}
62

63
////////////////////////////////////////////////////////////////////////////////
64
// Set the minimum and maximum widths for the value.
65
//
66
void ColumnUDAString::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
823✔
67
  minimum = maximum = 0;
823✔
68
  if (task.has(_name)) {
823✔
69
    if (_style == "default") {
110✔
70
      std::string value = task.get(_name);
109✔
71
      if (value != "") {
109✔
72
        auto stripped = Color::strip(value);
109✔
73
        maximum = longestLine(stripped);
109✔
74
        minimum = longestWord(stripped);
109✔
75
      }
109✔
76
    } else if (_style == "indicator") {
110✔
77
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
1✔
78
      if (indicator == "") indicator = "U";
1✔
79

80
      minimum = maximum = utf8_width(indicator);
1✔
81
    }
1✔
82
  }
83
}
823✔
84

85
////////////////////////////////////////////////////////////////////////////////
86
void ColumnUDAString::render(std::vector<std::string>& lines, Task& task, int width, Color& color) {
244✔
87
  if (task.has(_name)) {
244✔
88
    if (_style == "default") {
110✔
89
      std::string value = task.get(_name);
109✔
90
      std::vector<std::string> raw;
109✔
91
      wrapText(raw, value, width, _hyphenate);
109✔
92

93
      for (auto& i : raw) renderStringLeft(lines, width, color, i);
218✔
94
    } else if (_style == "indicator") {
110✔
95
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
1✔
96
      if (indicator == "") indicator = "U";
1✔
97

98
      renderStringRight(lines, width, color, indicator);
1✔
99
    }
1✔
100
  }
101
}
244✔
102

103
////////////////////////////////////////////////////////////////////////////////
104
ColumnUDANumeric::ColumnUDANumeric() {
214✔
105
  _name = "<uda>";
214✔
106
  _type = "numeric";
214✔
107
  _style = "default";
214✔
108
  _label = "";
214✔
109
  _uda = true;
214✔
110
  _styles = {_style, "indicator"};
642✔
111
}
642✔
112

113
////////////////////////////////////////////////////////////////////////////////
114
bool ColumnUDANumeric::validate(const std::string& value) const {
×
115
  // No restrictions.
116
  if (_values.size() == 0) return true;
×
117

118
  // Look for exact match value.
119
  for (auto& i : _values)
×
120
    if (i == value) return true;
×
121

122
  // Fail if not found.
123
  return false;
×
124
}
125

126
////////////////////////////////////////////////////////////////////////////////
127
// Set the minimum and maximum widths for the value.
128
//
129
void ColumnUDANumeric::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
13✔
130
  minimum = maximum = 0;
13✔
131
  if (task.has(_name)) {
13✔
132
    if (_style == "default") {
10✔
133
      auto value = task.get(_name);
10✔
134
      if (value != "") minimum = maximum = value.length();
10✔
135
    } else if (_style == "indicator") {
10✔
136
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
×
137
      if (indicator == "") indicator = "U";
×
138

139
      minimum = maximum = utf8_width(indicator);
×
UNCOV
140
    }
×
141
  }
142
}
13✔
143

144
////////////////////////////////////////////////////////////////////////////////
145
void ColumnUDANumeric::render(std::vector<std::string>& lines, Task& task, int width,
11✔
146
                              Color& color) {
147
  if (task.has(_name)) {
11✔
148
    if (_style == "default") {
10✔
149
      auto value = task.get(_name);
10✔
150
      renderStringRight(lines, width, color, value);
10✔
151
    } else if (_style == "indicator") {
10✔
152
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
×
153
      if (indicator == "") indicator = "U";
×
154

155
      renderStringRight(lines, width, color, indicator);
×
UNCOV
156
    }
×
157
  }
158
}
11✔
159

160
////////////////////////////////////////////////////////////////////////////////
161
ColumnUDADate::ColumnUDADate() {
125✔
162
  _name = "<uda>";
125✔
163
  _type = "date";
125✔
164
  _style = "default";
125✔
165
  _label = "";
125✔
166
  _uda = true;
125✔
167
  _styles = {_style, "indicator"};
375✔
168
}
375✔
169

170
////////////////////////////////////////////////////////////////////////////////
171
bool ColumnUDADate::validate(const std::string& value) const {
×
172
  // No restrictions.
173
  if (_values.size() == 0) return true;
×
174

175
  // Look for exact match value.
176
  for (auto& i : _values)
×
177
    if (i == value) return true;
×
178

179
  // Fail if not found.
180
  return false;
×
181
}
182

183
////////////////////////////////////////////////////////////////////////////////
184
// Set the minimum and maximum widths for the value.
185
//
186
void ColumnUDADate::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
2✔
187
  minimum = maximum = 0;
2✔
188
  if (task.has(_name)) {
2✔
189
    if (_style == "default") {
1✔
190
      auto value = task.get(_name);
1✔
191
      if (value != "") {
1✔
192
        // Determine the output date format, which uses a hierarchy of definitions.
193
        //   rc.report.<report>.dateformat
194
        //   rc.dateformat.report
195
        //   rc.dateformat
196
        Datetime date(strtoll(value.c_str(), nullptr, 10));
1✔
197
        auto format = Context::getContext().config.get("report." + _report + ".dateformat");
1✔
198
        if (format == "") format = Context::getContext().config.get("dateformat.report");
3✔
199
        if (format == "") format = Context::getContext().config.get("dateformat");
3✔
200

201
        minimum = maximum = Datetime::length(format);
1✔
202
      }
1✔
203
    } else if (_style == "indicator") {
1✔
204
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
×
205
      if (indicator == "") indicator = "U";
×
206

207
      minimum = maximum = utf8_width(indicator);
×
UNCOV
208
    }
×
209
  }
210
}
2✔
211

212
////////////////////////////////////////////////////////////////////////////////
213
void ColumnUDADate::render(std::vector<std::string>& lines, Task& task, int width, Color& color) {
2✔
214
  if (task.has(_name)) {
2✔
215
    if (_style == "default") {
1✔
216
      auto value = task.get(_name);
1✔
217

218
      // Determine the output date format, which uses a hierarchy of definitions.
219
      //   rc.report.<report>.dateformat
220
      //   rc.dateformat.report
221
      //   rc.dateformat.
222
      auto format = Context::getContext().config.get("report." + _report + ".dateformat");
1✔
223
      if (format == "") {
1✔
224
        format = Context::getContext().config.get("dateformat.report");
2✔
225
        if (format == "") format = Context::getContext().config.get("dateformat");
3✔
226
      }
227

228
      renderStringLeft(lines, width, color,
1✔
229
                       Datetime(strtoll(value.c_str(), nullptr, 10)).toString(format));
2✔
230
    } else if (_style == "indicator") {
1✔
231
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
×
232
      if (indicator == "") indicator = "U";
×
233

234
      renderStringRight(lines, width, color, indicator);
×
UNCOV
235
    }
×
236
  }
237
}
2✔
238

239
////////////////////////////////////////////////////////////////////////////////
240
ColumnUDADuration::ColumnUDADuration() {
119✔
241
  _name = "<uda>";
119✔
242
  _type = "duration";
119✔
243
  _style = "default";
119✔
244
  _label = "";
119✔
245
  _uda = true;
119✔
246
  _styles = {_style, "indicator"};
357✔
247
}
357✔
248

249
////////////////////////////////////////////////////////////////////////////////
250
bool ColumnUDADuration::validate(const std::string& value) const {
×
251
  // No restrictions.
252
  if (_values.size() == 0) return true;
×
253

254
  // Look for exact match value.
255
  for (auto& i : _values)
×
256
    if (i == value) return true;
×
257

258
  // Fail if not found.
259
  return false;
×
260
}
261

262
////////////////////////////////////////////////////////////////////////////////
263
// Set the minimum and maximum widths for the value.
264
//
265
void ColumnUDADuration::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
×
266
  minimum = maximum = 0;
×
267
  if (task.has(_name)) {
×
268
    if (_style == "default") {
×
269
      auto value = task.get(_name);
×
270
      if (value != "") minimum = maximum = Duration(value).formatISO().length();
×
271
    } else if (_style == "indicator") {
×
272
      if (task.has(_name)) {
×
273
        auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
×
274
        if (indicator == "") indicator = "U";
×
275

276
        minimum = maximum = utf8_width(indicator);
×
277
      } else
×
278
        minimum = maximum = 0;
×
279
    }
280
  }
UNCOV
281
}
×
282

283
////////////////////////////////////////////////////////////////////////////////
284
void ColumnUDADuration::render(std::vector<std::string>& lines, Task& task, int width,
×
285
                               Color& color) {
286
  if (task.has(_name)) {
×
287
    if (_style == "default") {
×
288
      auto value = task.get(_name);
×
289
      renderStringRight(lines, width, color, Duration(value).formatISO());
×
290
    } else if (_style == "indicator") {
×
291
      auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
×
292
      if (indicator == "") indicator = "U";
×
293

294
      renderStringRight(lines, width, color, indicator);
×
UNCOV
295
    }
×
296
  }
UNCOV
297
}
×
298

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