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

ArkScript-lang / Ark / 21146409233

19 Jan 2026 05:26PM UTC coverage: 93.417% (+0.7%) from 92.743%
21146409233

push

github

SuperFola
feat(tests, debugger): testing the debugger triggering on errors

5 of 5 new or added lines in 2 files covered. (100.0%)

125 existing lines in 4 files now uncovered.

8813 of 9434 relevant lines covered (93.42%)

273848.42 hits per line

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

92.17
/src/arkscript/REPL/Utils.cpp
1
#include <CLI/REPL/Utils.hpp>
2

3
#include <regex>
4
#include <algorithm>
5
#include <numeric>
6
#include <ranges>
7

8
#include <Ark/Builtins/Builtins.hpp>
9
#include <Ark/Compiler/Common.hpp>
10

11
namespace Ark::internal
12
{
13
    std::vector<std::string> getAllKeywords()
1✔
14
    {
1✔
15
        std::vector<std::string> output;
1✔
16
        output.reserve(keywords.size() + Language::listInstructions.size() + Language::operators.size() + Builtins::builtins.size() + 2);
1✔
17

18
        std::ranges::transform(keywords, std::back_inserter(output), [](const auto& string_view) {
10✔
19
            return std::string(string_view);
9✔
UNCOV
20
        });
×
21
        std::ranges::transform(Language::listInstructions, std::back_inserter(output), [](const auto& string_view) {
10✔
22
            return std::string(string_view);
9✔
UNCOV
23
        });
×
24
        std::ranges::transform(Language::operators, std::back_inserter(output), [](const auto& string_view) {
25✔
25
            return std::string(string_view);
24✔
UNCOV
26
        });
×
27
        std::ranges::transform(std::ranges::views::keys(Builtins::builtins), std::back_inserter(output), [](const auto& string) {
69✔
28
            return string;
68✔
29
        });
30

31
        output.emplace_back("and");
1✔
32
        output.emplace_back("or");
1✔
33

34
        return output;
1✔
35
    }
1✔
36

37
    std::vector<std::pair<std::string, replxx::Replxx::Color>> getColorPerKeyword()
1✔
38
    {
1✔
39
        using namespace replxx;
40
        using K = std::string;
41
        using V = Replxx::Color;
42

43
        std::vector<std::pair<K, V>> output;
1✔
44
        output.reserve(keywords.size() + Language::listInstructions.size() + Language::operators.size() + Builtins::builtins.size() + 4);
1✔
45

46
        std::ranges::transform(keywords, std::back_inserter(output), [](const auto& string_view) {
10✔
47
            return std::make_pair(std::string(string_view), Replxx::Color::BRIGHTRED);
9✔
UNCOV
48
        });
×
49
        std::ranges::transform(Language::listInstructions, std::back_inserter(output), [](const auto& string_view) {
10✔
50
            return std::make_pair(std::string(string_view), Replxx::Color::GREEN);
9✔
UNCOV
51
        });
×
52
        std::ranges::transform(Language::operators, std::back_inserter(output), [](const auto& string_view) {
25✔
53
            auto safe_op = std::string(string_view);
24✔
54
            if (const auto it = safe_op.find_first_of(R"(-+=/*<>[]()?")"); it != std::string::npos)
36✔
55
                safe_op.insert(it, "\\");
12✔
56
            return std::make_pair(safe_op, Replxx::Color::BRIGHTBLUE);
24✔
57
        });
24✔
58
        std::ranges::transform(std::ranges::views::keys(Builtins::builtins), std::back_inserter(output), [](const auto& string) {
69✔
59
            return std::make_pair(string, Replxx::Color::GREEN);
68✔
60
        });
61

62
        output.emplace_back("and", Replxx::Color::BRIGHTBLUE);
1✔
63
        output.emplace_back("or", Replxx::Color::BRIGHTBLUE);
1✔
64
        output.emplace_back("[\\-|+]?[0-9]+(\\.[0-9]+)?", Replxx::Color::YELLOW);
1✔
65
        output.emplace_back("\".*\"", Replxx::Color::MAGENTA);
1✔
66

67
        return output;
1✔
68
    }
1✔
69

70
    std::size_t codepointLength(const std::string& str)
4✔
71
    {
4✔
72
        return std::accumulate(
4✔
73
            str.begin(),
4✔
74
            str.end(),
4✔
75
            std::size_t { 0 },
76
            [](const std::size_t acc, const char c) {
16✔
77
                return acc + ((c & 0xc0) != 0x80);
16✔
78
            });
79
    }
80

81
    std::size_t contextLen(const std::string& prefix)
2✔
82
    {
2✔
83
        const std::string word_break = " \t\n\r\v\f=+*&^%$#@!,./?<>;`~'\"[]{}()\\|";
2✔
84
        std::size_t count = 0;
2✔
85

86
        for (const auto c : std::ranges::views::reverse(prefix))
12✔
87
        {
88
            if (word_break.find(c) != std::string::npos)
10✔
UNCOV
89
                break;
×
90
            ++count;
10✔
91
        }
10✔
92

93
        return count;
2✔
94
    }
2✔
95

96
    replxx::Replxx::completions_t hookCompletion(const std::vector<std::string>& words, const std::string& context, int& length)
1✔
97
    {
1✔
98
        replxx::Replxx::completions_t completions;
1✔
99
        std::size_t utf8_context_len = contextLen(context);
1✔
100
        std::size_t prefix_len = context.size() - utf8_context_len;
1✔
101

102
        if (prefix_len > 0 && context[prefix_len - 1] == '\\')
1✔
103
        {
104
            --prefix_len;
×
UNCOV
105
            ++utf8_context_len;
×
UNCOV
106
        }
×
107

108
        length = static_cast<int>(codepointLength(context.substr(prefix_len, utf8_context_len)));
1✔
109

110
        const std::string prefix = context.substr(prefix_len);
1✔
111
        for (const auto& e : words)
113✔
112
        {
113
            if (e.starts_with(prefix))
112✔
114
                completions.emplace_back(e.c_str());
2✔
115
        }
112✔
116

117
        return completions;
1✔
118
    }
1✔
119

120
    void hookColor(const std::vector<std::pair<std::string, replxx::Replxx::Color>>& words_colors, const std::string& context, replxx::Replxx::colors_t& colors)
1✔
121
    {
1✔
122
        // highlight matching regex sequences
123
        for (const auto& [regex, color] : words_colors)
236✔
124
        {
125
            std::size_t pos = 0;
114✔
126
            std::string str = context;
114✔
127
            std::smatch match;
114✔
128

129
            while (std::regex_search(str, match, std::regex(regex)))
115✔
130
            {
131
                std::string c = match[0];
1✔
132
                std::string prefix = match.prefix().str();
1✔
133
                const std::size_t len = codepointLength(c);
1✔
134

135
                pos += codepointLength(prefix);
1✔
136
                for (std::size_t i = 0; i < len; ++i)
7✔
137
                {
138
                    if (colors.at(pos + i) == replxx::Replxx::Color::DEFAULT)
6✔
139
                        colors.at(pos + i) = color;
6✔
140
                }
6✔
141

142
                pos += len;
1✔
143
                str = match.suffix();
1✔
144
            }
1✔
145
        }
114✔
146
    }
1✔
147

148
    replxx::Replxx::hints_t hookHint(const std::vector<std::string>& words, const std::string& context, int& length, replxx::Replxx::Color& color)
1✔
149
    {
1✔
150
        replxx::Replxx::hints_t hints;
1✔
151
        // only show hint if prefix is at least 'n' chars long
152
        // or if prefix begins with a specific character
153
        const std::size_t utf8_context_len = contextLen(context);
1✔
154
        const std::size_t prefix_len = context.size() - utf8_context_len;
1✔
155
        length = static_cast<int>(codepointLength(context.substr(prefix_len, utf8_context_len)));
1✔
156
        const std::string prefix = context.substr(prefix_len);
1✔
157

158
        if (prefix.size() >= 2 || (!prefix.empty() && prefix.at(0) == '.'))
1✔
159
        {
160
            for (const auto& e : words)
113✔
161
            {
162
                if (e.compare(0, prefix.size(), prefix) == 0)
112✔
163
                    hints.emplace_back(e.c_str());
1✔
164
            }
112✔
165
        }
1✔
166

167
        if (hints.size() == 1)
1✔
168
            color = replxx::Replxx::Color::GREEN;
1✔
169

170
        return hints;
1✔
171
    }
1✔
172
}
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

© 2026 Coveralls, Inc