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

mbits-os / quick_dra / 22038263728

15 Feb 2026 03:31PM UTC coverage: 93.378% (+6.4%) from 87.008%
22038263728

Pull #39

github

web-flow
Merge 74a89bbd4 into 7d773e4d9
Pull Request #39: testing

58 of 67 new or added lines in 23 files covered. (86.57%)

75 existing lines in 12 files now uncovered.

4033 of 4319 relevant lines covered (93.38%)

1107.01 hits per line

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

92.86
/libs/liblex/src/lex/validators.cpp
1
// Copyright (c) 2026 midnightBITS
2
// This code is licensed under MIT license (see LICENSE for details)
3

4
#include <array>
5
#include <cctype>
6
#include <quick_dra/lex/validators.hpp>
7
#include "validate/actions.hpp"
8

9
namespace quick_dra::detail {
10
        namespace {
11
                constexpr auto tax_id_checker =
12
                    checker::mask<"000000000?">.with<6, 5, 7, 2, 3, 4, 5, 6, 7, 0>().postproc(
13
                        [](auto sum) {
37✔
14
                                auto const result = sum % 11;
145✔
15
                                if (result > 9) {
37✔
16
                                        return kInvalidChecksum;
25✔
17
                                }
18✔
18

90✔
19
                                return static_cast<unsigned short>(result);
31✔
20
                        });
109✔
21

22
                constexpr auto social_id_checker =
23
                    checker::mask<"0000000000?">.with<1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 0>().postproc(
24
                        [](auto sum) { return (10 - (sum % 10)) % 10; });
58✔
25

26
                constexpr auto id_card_checker =
27
                    checker::mask<"AAA?00000">.with<7, 3, 1, 0, 7, 3, 1, 7, 3>().postproc(
28
                        [](auto sum) { return sum % 10; });
73✔
29

30
                constexpr auto pl_passport_checker =
31
                    checker::mask<"AA?000000">.with<7, 3, 0, 1, 7, 3, 1, 7, 3>().postproc(
32
                        [](auto sum) { return sum % 10; });
64✔
33

34
                template <std::integral T = int>
35
                T int_parse(std::string_view number) noexcept {
217✔
36
                        T result{};
865✔
37
                        auto const begin = number.data();
865✔
38
                        auto const end = begin + number.size();
865✔
39
                        auto const [ptr, ec] = std::from_chars(begin, end, result);
865✔
40
                        if (ptr != end || ec != std::errc{}) {
217✔
41
                                return 0;
×
42
                        }
43
                        return result;
217✔
44
                }
649✔
45

46
                static constexpr auto const centuries =
47
                    std::array{1900, 2000, 2100, 2200, 1800};
48
        };  // namespace
49

50
        unsigned short tax_id::checksum(std::string_view id) noexcept {
49✔
51
                return tax_id_checker.checksum(id);
193✔
52
        }
145✔
53

54
        unsigned short social_id::checksum(std::string_view id) noexcept {
76✔
55
                return social_id_checker.checksum(id);
301✔
56
        }
226✔
57

58
        std::chrono::year_month_day social_id::get_birthday(
72✔
59
            std::string_view social_id) noexcept {
1✔
60
                if (social_id.length() != 11) {
73✔
61
                        return {};
×
62
                }
63

216✔
64
                auto const in_century = int_parse(social_id.substr(0, 2));
73✔
65
                auto const month_and_century =
217✔
66
                    int_parse<unsigned>(social_id.substr(2, 2));
288✔
67
                auto const day = int_parse(social_id.substr(4, 2));
289✔
68

216✔
69
                auto const month = static_cast<int>(month_and_century % 20);
289✔
70
                auto const century_code = month_and_century / 20u;
289✔
71
                auto const century =
217✔
72
                    century_code >= centuries.size() ? 1900 : centuries[century_code];
144✔
73

216✔
74
                return std::chrono::year{century + in_century} / month / day;
289✔
75
        }
217✔
76

77
        unsigned short id_card::checksum(std::string_view id) noexcept {
97✔
78
                return id_card_checker.checksum(id);
385✔
79
        }
289✔
80

81
        unsigned short pl_passport::checksum(std::string_view id) noexcept {
88✔
82
                return pl_passport_checker.checksum(id);
349✔
83
        }
262✔
84

85
        bool checksum_digit_is_valid(unsigned short checksum,
177✔
86
                                     char tested) noexcept {
1✔
87
                auto const ch = checksum + '0';
709✔
88
                return tested == static_cast<char>(ch);
709✔
89
        }
532✔
90

91
        bool fix_checksum_digit(unsigned short checksum, char& fixed) noexcept {
UNCOV
92
                fixed = static_cast<char>(checksum + '0');
×
UNCOV
93
                return true;
×
94
        }
95
}  // namespace quick_dra::detail
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