Skip to content

Commit 3f99b78

Browse files
committed
Tests for new set and list operations
1 parent f1cffa2 commit 3f99b78

1 file changed

Lines changed: 257 additions & 0 deletions

File tree

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
"""Tests for WOQL set and list operations."""
2+
import pytest
3+
from terminusdb_client.woqlquery.woql_query import WOQLQuery
4+
5+
6+
class TestWOQLConcatOperations:
7+
"""Test concat operation edge cases."""
8+
9+
def test_concat_args_introspection(self):
10+
"""Test concat returns args list when called with 'args'."""
11+
result = WOQLQuery().concat("args", "v:Result")
12+
13+
assert result == ["list", "concatenated"]
14+
15+
def test_concat_with_string_containing_variables(self):
16+
"""Test concat with string containing v: variables."""
17+
query = WOQLQuery()
18+
# This tests lines 2610-2622 - string parsing with v: variables
19+
result = query.concat("Hello v:Name, welcome!", "v:Result")
20+
21+
assert result is query
22+
assert query._cursor["@type"] == "Concatenate"
23+
24+
def test_concat_with_string_multiple_variables(self):
25+
"""Test concat with string containing multiple v: variables."""
26+
query = WOQLQuery()
27+
# Tests complex string parsing with multiple variables
28+
result = query.concat("v:First v:Second v:Third", "v:Result")
29+
30+
assert result is query
31+
assert query._cursor["@type"] == "Concatenate"
32+
33+
def test_concat_with_string_variable_at_start(self):
34+
"""Test concat with v: variable at the start of string."""
35+
query = WOQLQuery()
36+
# Tests line 2612-2613 - handling when first element exists
37+
result = query.concat("v:Name is here", "v:Result")
38+
39+
assert result is query
40+
assert query._cursor["@type"] == "Concatenate"
41+
42+
def test_concat_with_string_variable_with_special_chars(self):
43+
"""Test concat with v: variable followed by special characters."""
44+
query = WOQLQuery()
45+
# Tests lines 2616-2621 - handling special characters after variables
46+
result = query.concat("Hello v:Name!", "v:Result")
47+
48+
assert result is query
49+
assert query._cursor["@type"] == "Concatenate"
50+
51+
def test_concat_with_list(self):
52+
"""Test concat with list input."""
53+
query = WOQLQuery()
54+
# Tests line 2623 - list handling
55+
result = query.concat(["Hello", "v:Name"], "v:Result")
56+
57+
assert result is query
58+
assert query._cursor["@type"] == "Concatenate"
59+
60+
61+
class TestWOQLJoinOperations:
62+
"""Test join operation edge cases."""
63+
64+
def test_join_args_introspection(self):
65+
"""Test join returns args list when called with 'args'."""
66+
result = WOQLQuery().join("args", ",", "v:Result")
67+
68+
assert result == ["list", "separator", "join"]
69+
70+
def test_join_with_list_and_separator(self):
71+
"""Test join with list and separator."""
72+
query = WOQLQuery()
73+
# Tests lines 2651-2657 - join operation
74+
result = query.join(["v:Item1", "v:Item2"], ", ", "v:Result")
75+
76+
assert result is query
77+
assert query._cursor["@type"] == "Join"
78+
assert "list" in query._cursor
79+
assert "separator" in query._cursor
80+
assert "result" in query._cursor
81+
82+
83+
class TestWOQLSumOperations:
84+
"""Test sum operation edge cases."""
85+
86+
def test_sum_args_introspection(self):
87+
"""Test sum returns args list when called with 'args'."""
88+
result = WOQLQuery().sum("args", "v:Total")
89+
90+
assert result == ["list", "sum"]
91+
92+
def test_sum_with_list_of_numbers(self):
93+
"""Test sum with list of numbers."""
94+
query = WOQLQuery()
95+
# Tests lines 2678-2683 - sum operation
96+
result = query.sum(["v:Num1", "v:Num2", "v:Num3"], "v:Total")
97+
98+
assert result is query
99+
assert query._cursor["@type"] == "Sum"
100+
assert "list" in query._cursor
101+
assert "sum" in query._cursor
102+
103+
104+
class TestWOQLSliceOperations:
105+
"""Test slice operation edge cases."""
106+
107+
def test_slice_args_introspection(self):
108+
"""Test slice returns args list when called with 'args'."""
109+
result = WOQLQuery().slice("args", "v:Result", 0, 5)
110+
111+
assert result == ["list", "result", "start", "end"]
112+
113+
def test_slice_with_start_and_end(self):
114+
"""Test slice with start and end indices."""
115+
query = WOQLQuery()
116+
# Tests lines 2712-2713 and slice operation
117+
result = query.slice(["a", "b", "c", "d"], "v:Result", 1, 3)
118+
119+
assert result is query
120+
assert query._cursor["@type"] == "Slice"
121+
assert "list" in query._cursor
122+
assert "result" in query._cursor
123+
assert "start" in query._cursor
124+
assert "end" in query._cursor
125+
126+
def test_slice_with_only_start(self):
127+
"""Test slice with only start index (no end)."""
128+
query = WOQLQuery()
129+
# Tests slice without end parameter
130+
result = query.slice(["a", "b", "c", "d"], "v:Result", 2)
131+
132+
assert result is query
133+
assert query._cursor["@type"] == "Slice"
134+
assert "start" in query._cursor
135+
136+
def test_slice_with_negative_index(self):
137+
"""Test slice with negative start index."""
138+
query = WOQLQuery()
139+
# Tests negative indexing
140+
result = query.slice(["a", "b", "c", "d"], "v:Result", -2)
141+
142+
assert result is query
143+
assert query._cursor["@type"] == "Slice"
144+
145+
def test_slice_with_variable_indices(self):
146+
"""Test slice with variable indices instead of integers."""
147+
query = WOQLQuery()
148+
# Tests line 2722 - non-integer start handling
149+
result = query.slice(["a", "b", "c"], "v:Result", "v:Start", "v:End")
150+
151+
assert result is query
152+
assert query._cursor["@type"] == "Slice"
153+
154+
155+
class TestWOQLMemberOperations:
156+
"""Test member operation edge cases."""
157+
158+
def test_member_with_list(self):
159+
"""Test member operation with list."""
160+
query = WOQLQuery()
161+
result = query.member("v:Item", ["a", "b", "c"])
162+
163+
assert result is query
164+
assert query._cursor["@type"] == "Member"
165+
166+
def test_member_with_variable_list(self):
167+
"""Test member operation with variable list."""
168+
query = WOQLQuery()
169+
result = query.member("v:Item", "v:List")
170+
171+
assert result is query
172+
assert query._cursor["@type"] == "Member"
173+
174+
175+
class TestWOQLSetDifferenceOperations:
176+
"""Test set_difference operation."""
177+
178+
def test_set_difference_basic(self):
179+
"""Test set_difference with two lists."""
180+
query = WOQLQuery()
181+
result = query.set_difference(
182+
["a", "b", "c"],
183+
["b", "c", "d"],
184+
"v:Result"
185+
)
186+
187+
assert result is query
188+
assert query._cursor["@type"] == "SetDifference"
189+
assert "list_a" in query._cursor
190+
assert "list_b" in query._cursor
191+
assert "result" in query._cursor
192+
193+
194+
class TestWOQLSetIntersectionOperations:
195+
"""Test set_intersection operation."""
196+
197+
def test_set_intersection_basic(self):
198+
"""Test set_intersection with two lists."""
199+
query = WOQLQuery()
200+
result = query.set_intersection(
201+
["a", "b", "c"],
202+
["b", "c", "d"],
203+
"v:Result"
204+
)
205+
206+
assert result is query
207+
assert query._cursor["@type"] == "SetIntersection"
208+
assert "list_a" in query._cursor
209+
assert "list_b" in query._cursor
210+
assert "result" in query._cursor
211+
212+
213+
class TestWOQLSetUnionOperations:
214+
"""Test set_union operation."""
215+
216+
def test_set_union_basic(self):
217+
"""Test set_union with two lists."""
218+
query = WOQLQuery()
219+
result = query.set_union(
220+
["a", "b", "c"],
221+
["b", "c", "d"],
222+
"v:Result"
223+
)
224+
225+
assert result is query
226+
assert query._cursor["@type"] == "SetUnion"
227+
assert "list_a" in query._cursor
228+
assert "list_b" in query._cursor
229+
assert "result" in query._cursor
230+
231+
232+
class TestWOQLSetMemberOperations:
233+
"""Test set_member operation."""
234+
235+
def test_set_member_basic(self):
236+
"""Test set_member operation."""
237+
query = WOQLQuery()
238+
result = query.set_member("v:Element", ["a", "b", "c"])
239+
240+
assert result is query
241+
assert query._cursor["@type"] == "SetMember"
242+
assert "element" in query._cursor
243+
assert "set" in query._cursor
244+
245+
246+
class TestWOQLListToSetOperations:
247+
"""Test list_to_set operation."""
248+
249+
def test_list_to_set_basic(self):
250+
"""Test list_to_set operation."""
251+
query = WOQLQuery()
252+
result = query.list_to_set(["a", "b", "b", "c"], "v:UniqueSet")
253+
254+
assert result is query
255+
assert query._cursor["@type"] == "ListToSet"
256+
assert "list" in query._cursor
257+
assert "set" in query._cursor

0 commit comments

Comments
 (0)