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

mbits-os / quick_dra / 22065571263

16 Feb 2026 01:58PM UTC coverage: 97.467% (+10.5%) from 87.008%
22065571263

Pull #39

github

web-flow
Merge 3b1693b20 into 7d773e4d9
Pull Request #39: testing

62 of 64 new or added lines in 19 files covered. (96.88%)

23 existing lines in 3 files now uncovered.

4386 of 4500 relevant lines covered (97.47%)

1904.32 hits per line

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

98.31
/libs/libpersist/src/parser.cpp
1
// Copyright (c) 2026 midnightBITS
2
// This code is licensed under MIT license (see LICENSE for details)
3

4
#include <fmt/format.h>
5
#include <fmt/std.h>
6
#include <fstream>
7
#include <optional>
8
#include <string>
9
#include <yaml/parser.hpp>
10

11
using namespace std::literals;
12

13
namespace yaml {
14
        namespace {
15
                template <typename ErrorCallback>
16
                std::optional<std::string> open_with(std::filesystem::path const& path,
291✔
17
                                                     ErrorCallback&& on_error) {
1✔
18
                        std::optional<std::string> result{};
1,165✔
19
                        std::ifstream in{path, std::ios::in | std::ios::binary};
1,165✔
20
                        if (!in) {
292✔
21
                                on_error();
13✔
22
                                return result;
13✔
23
                        }
9✔
24

864✔
25
                        std::ostringstream contents;
289✔
26
                        contents << in.rdbuf();
1,153✔
27
                        result = std::move(contents).str();
1,153✔
28

864✔
29
                        return result;
1,153✔
30
                }
1,165✔
31

32
                std::optional<std::string> open(std::filesystem::path const& path,
102✔
33
                                                std::string_view app_name) {
1✔
34
                        return open_with(path, [app_name, &path] {
137✔
35
                                fmt::print("{}: error: cannot find {}\n", app_name, path);
13✔
36
                        });
215✔
37
                }
307✔
38
        }  // namespace
39

40
        base_ctx parser::context(base_ctx const& parent) const {
415✔
41
                auto result = parent;
1,657✔
42
                result.parser = &rapid_parser;
1,657✔
43
                return result;
1,657✔
44
        }
1,243✔
45

46
        ryml::Parser parser::build_rapid_parser() noexcept {
418✔
47
                ryml::Parser p{&evt_handler, ryml::ParserOptions{}.locations(true)};
1,669✔
48
                p.reserve_locations(300);
1,669✔
49
                return p;
1,669✔
50
        }
1,252✔
51

52
        std::optional<ryml::Tree> parser::load(std::filesystem::path const& path,
102✔
53
                                               std::string_view app_name) & {
1✔
54
                auto maybe_contents = open(path, app_name);
409✔
55
                if (!maybe_contents) {
103✔
56
                        return std::nullopt;
13✔
57
                }
9✔
58

297✔
59
                return load_contents(std::move(*maybe_contents), path.string());
100✔
60
        }
409✔
61

62
        std::optional<ryml::Tree> parser::load(
189✔
63
            std::filesystem::path const& path,
64
            std::function<void()> const& on_error) & {
1✔
65
                auto maybe_contents = open_with(path, on_error);
757✔
66
                if (!maybe_contents) {
190✔
NEW
67
                        return std::nullopt;
×
68
                }
69

567✔
70
                return load_contents(std::move(*maybe_contents), path.string());
190✔
71
        }
757✔
72

73
        std::optional<ryml::Tree> parser::load_contents(std::string text,
414✔
74
                                                        std::string const& path) & {
1✔
75
                contents = std::move(text);
1,657✔
76
                path_str = path;
1,657✔
77
                rapid_parser.reserve_locations(300);
1,657✔
78
                auto tree =
1,381✔
79
                    ryml::parse_in_place(&rapid_parser, ryml::to_csubstr(path_str),
1,656✔
80
                                         ryml::to_substr(contents));
2,070✔
81
                tree.resolve();
1,657✔
82
                return std::optional{std::move(tree)};
2,071✔
83
        }
1,657✔
84
}  // namespace yaml
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