SQLon test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 54 / 0 / 54
Functions: 100.0% 15 / 0 / 15
Branches: 92.3% 24 / 0 / 26

src/relation.cpp
Line Branch Exec Source
1 /******************************************************************************
2 **
3 ** Copyright (C) 2026 Ivan Pinezhaninov <ivan.pinezhaninov@gmail.com>
4 **
5 ** This file is part of the SQLon - which can be found at
6 ** https://github.com/IvanPinezhaninov/sqlon/.
7 **
8 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
11 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
12 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
13 ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
14 ** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 **
16 ******************************************************************************/
17
18 #include <sqlon/relation.h>
19
20 #include <memory>
21 #include <utility>
22
23 namespace sqlon {
24
25 163 qualified_name::qualified_name(std::initializer_list<std::string> parts)
26
1/1
✓ Branch 1 taken 163 times.
326 : m_parts(parts)
27 {
28
3/3
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 162 times.
✓ Branch 5 taken 1 time.
163 if (m_parts.empty()) throw invalid_query{"a qualified name requires at least one component"};
29
2/2
✓ Branch 5 taken 166 times.
✓ Branch 6 taken 160 times.
326 for (const std::string& part : m_parts)
30
3/3
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 164 times.
✓ Branch 5 taken 2 times.
166 if (part.empty()) throw invalid_query{"qualified name components cannot be empty"};
31 163 }
32
33 978 const std::vector<std::string>& qualified_name::parts() const noexcept
34 {
35 978 return m_parts;
36 }
37
38 203 relation::relation(detail::relation_ptr node)
39 203 : m_node(std::move(node))
40 203 {}
41
42 194 const detail::relation_ptr& detail::relation_access::node(const relation& value) noexcept
43 {
44 194 return value.m_node;
45 }
46
47 16 relation detail::relation_access::make(detail::relation_ptr node)
48 {
49 16 return relation{std::move(node)};
50 }
51
52 156 table::table(std::string name)
53
5/5
✓ Branch 1 taken 155 times.
✓ Branch 4 taken 155 times.
✓ Branch 5 taken 155 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 1 time.
313 : table(qualified_name{std::move(name)})
54 312 {}
55
56 2 table::table(std::string name, std::string alias)
57
3/5
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
6 : table(qualified_name{std::move(name)}, std::move(alias))
58 4 {}
59
60 157 table::table(qualified_name name)
61
1/1
✓ Branch 4 taken 157 times.
157 : table(std::move(name), {})
62 157 {}
63
64 172 table::table(qualified_name name, std::string alias)
65 172 : relation(make_node(name, alias))
66 172 , m_identifier(std::move(name))
67
1/1
✓ Branch 1 taken 172 times.
344 , m_alias(std::move(alias))
68 172 {}
69
70 1 const std::string& table::name() const noexcept
71 {
72 1 return m_identifier.parts().back();
73 }
74
75 473 const qualified_name& table::identifier() const noexcept
76 {
77 473 return m_identifier;
78 }
79
80 543 const std::string& table::alias_name() const noexcept
81 {
82 543 return m_alias;
83 }
84
85 172 detail::relation_ptr table::make_node(const qualified_name& name, const std::string& alias)
86 {
87
1/1
✓ Branch 1 taken 172 times.
172 std::shared_ptr<detail::relation_node> node = std::make_shared<detail::relation_node>();
88 172 node->kind = detail::relation_kind::table;
89
1/1
✓ Branch 4 taken 172 times.
172 node->name = name.parts().back();
90
1/1
✓ Branch 7 taken 172 times.
172 node->qualifiers.assign(name.parts().begin(), name.parts().end() - 1);
91
1/1
✓ Branch 2 taken 172 times.
172 node->alias = alias;
92 344 return node;
93 172 }
94
95 194 detail::relation_ptr detail::to_relation(const relation& value)
96 {
97 194 return relation_access::node(value);
98 }
99
100 namespace detail {
101
102 16 relation make_join(detail::join_kind kind, detail::relation_ptr left, detail::relation_ptr right,
103 detail::expression_ptr condition)
104 {
105
1/1
✓ Branch 1 taken 16 times.
16 std::shared_ptr<detail::relation_node> node = std::make_shared<detail::relation_node>();
106 16 node->kind = detail::relation_kind::join;
107 16 node->join_type = kind;
108 16 node->left = std::move(left);
109 16 node->right = std::move(right);
110 16 node->condition = std::move(condition);
111 32 return relation_access::make(std::move(node));
112 16 }
113
114 } // namespace detail
115 } // namespace sqlon
116