• 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

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

41
////////////////////////////////////////////////////////////////////////////////
42
ColumnProject::ColumnProject() {
5,066✔
43
  _name = "project";
5,066✔
44
  _style = "full";
5,066✔
45
  _label = "Project";
5,066✔
46
  _styles = {"full", "parent", "indented"};
20,264✔
47
  _examples = {"home.garden", "home", "  home.garden"};
20,264✔
48
  _hyphenate = Context::getContext().config.getBoolean("hyphenate");
10,132✔
49
}
30,396✔
50

51
////////////////////////////////////////////////////////////////////////////////
52
// Set the minimum and maximum widths for the value.
53
void ColumnProject::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
1,064✔
54
  minimum = maximum = 0;
1,064✔
55
  if (task.has(_name)) {
1,064✔
56
    std::string project = task.get(_name);
246✔
57

58
    if (_style == "parent") {
246✔
59
      auto period = project.find('.');
33✔
60
      if (period != std::string::npos) project = project.substr(0, period);
33✔
61
    } else if (_style == "indented") {
213✔
62
      project = indentProject(project, "  ", '.');
6✔
63
    }
64

65
    minimum = longestWord(project);
246✔
66
    maximum = utf8_width(project);
246✔
67
  }
246✔
68
}
1,064✔
69

70
////////////////////////////////////////////////////////////////////////////////
71
void ColumnProject::render(std::vector<std::string>& lines, Task& task, int width, Color& color) {
387✔
72
  if (task.has(_name)) {
387✔
73
    std::string project = task.get(_name);
244✔
74
    if (_style == "parent") {
244✔
75
      auto period = project.find('.');
33✔
76
      if (period != std::string::npos) project = project.substr(0, period);
33✔
77
    } else if (_style == "indented") {
211✔
78
      project = indentProject(project, "  ", '.');
6✔
79
    }
80

81
    std::vector<std::string> raw;
244✔
82
    wrapText(raw, project, width, _hyphenate);
244✔
83

84
    for (const auto& i : raw) renderStringLeft(lines, width, color, i);
488✔
85
  }
244✔
86
}
387✔
87

88
////////////////////////////////////////////////////////////////////////////////
89
void ColumnProject::modify(Task& task, const std::string& value) {
246✔
90
  std::string label = "   [1;37;43mMODIFICATION [0m ";
246✔
91

92
  // Only if it's a DOM ref, eval it first.
93
  Lexer lexer(value);
246✔
94
  std::string domRef;
246✔
95
  Lexer::Type type;
96
  if (lexer.token(domRef, type) && type == Lexer::Type::dom) {
246✔
97
    try {
98
      Eval e;
1✔
99
      e.addSource(domSource);
1✔
100

101
      Variant v;
1✔
102
      e.evaluateInfixExpression(value, v);
1✔
103
      task.set(_name, (std::string)v);
1✔
104
      Context::getContext().debug(label + _name + " <-- '" + (std::string)v + "' <-- '" + value +
1✔
105
                                  '\'');
106
    } catch (const std::string& e) {
1✔
107
      // If the expression failed because it didn't look like an expression,
108
      // simply store it as-is.
109
      if (e == "The value is not an expression.") {
×
110
        task.set(_name, value);
×
111
        Context::getContext().debug(label + _name + " <-- '" + value + '\'');
×
112
      } else
113
        throw;
×
UNCOV
114
    }
×
115
  } else {
116
    task.set(_name, value);
245✔
117
    Context::getContext().debug(label + _name + " <-- '" + value + '\'');
245✔
118
  }
119
}
246✔
120

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