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

mbits-os / quick_dra / 22056640617

16 Feb 2026 09:11AM UTC coverage: 96.038% (+9.0%) from 87.008%
22056640617

Pull #39

github

web-flow
Merge 8054498da into 7d773e4d9
Pull Request #39: testing

61 of 65 new or added lines in 22 files covered. (93.85%)

3 existing lines in 3 files now uncovered.

4266 of 4442 relevant lines covered (96.04%)

1602.44 hits per line

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

91.23
/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,
183✔
17
                                                     ErrorCallback&& on_error) {
1✔
18
                        std::optional<std::string> result{};
733✔
19
                        std::ifstream in{path, std::ios::in | std::ios::binary};
733✔
20
                        if (!in) {
184✔
21
                                on_error();
×
22
                                return result;
×
23
                        }
24

549✔
25
                        std::ostringstream contents;
184✔
26
                        contents << in.rdbuf();
733✔
27
                        result = std::move(contents).str();
733✔
28

549✔
29
                        return result;
733✔
30
                }
733✔
31

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

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

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

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

270✔
59
                return load_contents(std::move(*maybe_contents), path.string());
91✔
60
        }
361✔
61

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

279✔
70
                return load_contents(std::move(*maybe_contents), path.string());
94✔
71
        }
373✔
72

73
        std::optional<ryml::Tree> parser::load_contents(std::string text,
306✔
74
                                                        std::string const& path) & {
1✔
75
                contents = std::move(text);
1,225✔
76
                path_str = path;
1,225✔
77
                rapid_parser.reserve_locations(300);
1,225✔
78
                auto tree =
1,021✔
79
                    ryml::parse_in_place(&rapid_parser, ryml::to_csubstr(path_str),
1,224✔
80
                                         ryml::to_substr(contents));
1,530✔
81
                tree.resolve();
1,225✔
82
                return std::optional{std::move(tree)};
1,531✔
83
        }
1,225✔
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