Skip to content

Commit be22408

Browse files
committed
added more tests
1 parent 02de40f commit be22408

5 files changed

Lines changed: 102 additions & 52 deletions

File tree

src/code_instead.jl

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ end
107107

108108
@code_instead abs SourceCode
109109

110-
@code_instead chop SourceCode
111-
112-
@code_instead chop SourceCode
113-
114110
@code_instead coalesce SourceCode Vararg{Any}
115111

116112
@code_instead QueryOperators.drop SourceCode Integer
@@ -127,9 +123,8 @@ end
127123
@code_instead if_else SourceCode SourceCode Any
128124
@code_instead if_else SourceCode SourceCode SourceCode
129125

126+
# TODO: add more methods
130127
@code_instead in SourceCode Any
131-
@code_instead in Any SourceCode
132-
@code_instead in SourceCode SourceCode
133128

134129
@code_instead isequal SourceCode Any
135130
@code_instead isequal Any SourceCode
@@ -144,13 +139,13 @@ end
144139
@code_instead QueryOperators.join SourceCode SourceCode Any Expr Any Expr Any Expr
145140

146141
@code_instead max SourceCode Vararg{Any}
142+
147143
@code_instead min SourceCode Vararg{Any}
148144

149145
@code_instead length SourceCode
150146

151147
@code_instead QueryOperators.map SourceCode Any Expr
152148

153-
@code_instead occursin AbstractString SourceCode
154149
@code_instead occursin Regex SourceCode
155150

156151
@code_instead QueryOperators.orderby SourceCode Any Expr
@@ -159,20 +154,45 @@ end
159154

160155
@code_instead secondary SourceCode
161156

162-
@code_instead startswith SourceCode Any
163-
@code_instead startswith Any SourceCode
164-
@code_instead startswith SourceCode SourceCode
165-
166-
@code_instead string SourceCode Any
167-
@code_instead string Any SourceCode
168-
@code_instead string SourceCode SourceCode
169-
170157
@code_instead QueryOperators.take SourceCode Any
171158

172159
@code_instead QueryOperators.thenby SourceCode Any Expr
173160

174161
@code_instead QueryOperators.thenby_descending SourceCode Any Expr
175162

163+
# TODO: add more methods
176164
@code_instead QueryOperators.unique SourceCode Any Expr
177165

178166
@code_instead uppercase SourceCode
167+
168+
# TODO: add
169+
# char
170+
# glob
171+
# hex
172+
# ifnull
173+
# instr
174+
# like
175+
# lower
176+
# ltrim
177+
# nullif
178+
# printf
179+
# quote
180+
# random
181+
# randomblob
182+
# replace
183+
# round
184+
# substr
185+
# trim
186+
# typeof
187+
# unicode
188+
# upper
189+
# zeroblob
190+
# avg
191+
# group_concat
192+
# sum
193+
# total
194+
# date
195+
# time
196+
# datetime
197+
# julianday
198+
# strftime

src/show.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ function case(io, call, arguments...)
7979
print(io, call)
8080
print(io, ' ')
8181
when_then_else(io, arguments...)
82+
print(io, ' ')
83+
print(io, "END")
8284
end
8385

8486
# Use the call to determine the syntax pattern

src/translate.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,13 @@ end
157157

158158
@translate_default ::typeof(min) :min
159159

160-
translate_call(::typeof(occursin), needle::AbstractString, haystack; primary = true) =
161-
SQLExpression(
162-
:LIKE,
163-
translate(haystack; primary = primary),
164-
string('%', needle, '%')
165-
)
166160
translate_call(::typeof(occursin), needle::Regex, haystack; primary = true) =
167161
SQLExpression(
168162
:LIKE,
169163
translate(haystack; primary = primary),
170164
# * => %, . => _
171-
replace(replace(needle.pattern, r"(?<!\\)\.\*" => "%"), r"(?<!\\)\." => "_")
165+
string('"', replace(replace(needle.pattern, r"(?<!\\)\.\*" => "%"), r"(?<!\\)\." => "_"), '"')
172166
)
173-
@translate_default ::typeof(occursin) :LIKE
174167

175168
function translate_call(::typeof(QueryOperators.orderby), unordered, key_function, key_function_expression; primary = true)
176169
SQLExpression(Symbol("ORDER BY"),
@@ -188,13 +181,6 @@ function translate_call(::typeof(QueryOperators.orderby_descending), unordered,
188181
)
189182
end
190183

191-
translate_call(::typeof(startswith), full, prefix::AbstractString; primary = primary) =
192-
SQLExpression(
193-
:LIKE,
194-
translate(full),
195-
string(prefix, '%')
196-
)
197-
198184
@translate_default ::typeof(string) :||
199185

200186
@translate_default ::typeof(QueryOperators.take) :LIMIT

test/runtests.jl

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ database2 = Database(DB(filename))
4747
end
4848
).Bytes) == 1059546140
4949

50+
@test first((
51+
@from i in database.Track begin
52+
@orderby i.Bytes, descending(i.Name)
53+
@select {i.TrackId, i.Name, i.Bytes}
54+
@collect DataTable
55+
end
56+
).Bytes) == 38747
57+
5058
@test database.Artist |>
5159
@join(database.Album, _.ArtistId, _.ArtistId, {_.ArtistId, __.AlbumId}) |>
5260
DataTable |>
@@ -58,6 +66,12 @@ database2 = Database(DB(filename))
5866
collect |>
5967
first).Count == 10
6068

69+
@test (database.Track |>
70+
@map({_.Name, _.Milliseconds, _.Bytes, _.AlbumId}) |>
71+
@filter(_.AlbumId == 1) |>
72+
collect |>
73+
first).Name == "For Those About To Rock (We Salute You)"
74+
6175
end
6276

6377
@testset "Systematic tests" begin
@@ -69,39 +83,67 @@ execute!(Stmt(connection, """
6983
CREATE TABLE test (
7084
a Int,
7185
b Int,
72-
c Int
86+
c Int,
87+
d Text,
88+
e Int
7389
)"""))
7490
execute!(Stmt(connection, """
75-
INSERT INTO test VALUES(0, 1, -1)
91+
INSERT INTO test VALUES(0, 1, -1, "ab", NULL)
7692
"""))
7793
database = Database(connection)
7894
result =
7995
database.test |>
8096
@map({
81-
c = _.a == _.b,
82-
d = _.a != _.b,
83-
e = !(_.a),
84-
f = _.a & _.b,
85-
g = _.a | _.b,
86-
h = _.a * _.b,
87-
i = _.a + _.b,
88-
j = _.a % _.b,
89-
k = abs(_.c),
90-
l = _.a in (0, 1)
97+
equals_test = _.a == _.b,
98+
not_equals_test = _.a != _.b,
99+
not_test = !(_.a),
100+
and_test = _.a & _.b,
101+
or_test = _.a | _.b,
102+
times_test = _.a * _.b,
103+
plus_test = _.a + _.b,
104+
mod_test = _.a % _.b,
105+
abs_test = abs(_.c),
106+
in_test = _.a in (0, 1),
107+
coalesce_test = coalesce(_.e, _.a),
108+
if_else_test_1 = if_else(_.b, 1, 0),
109+
if_else_test_2 = if_else(1, _.b, 0),
110+
if_else_test_3 = if_else(0, 1, _.a),
111+
if_else_test_4 = if_else(0, _.b, _.a),
112+
if_else_test_5 = if_else(_.a, 1, _.a),
113+
if_else_test_6 = if_else(_.b, _.b, 0),
114+
if_else_test_7 = if_else(_.b, _.b, _.a),
115+
ismissing_test = ismissing(_.e),
116+
max_test = max(_.b, 0),
117+
min_test = min(_.a, 1),
118+
occursin_test = occursin(r"a.*", _.d),
119+
uppercase_test = uppercase(_.d)
91120
}) |>
92121
collect |>
93122
first
94123

95-
@test result.c == 0
96-
@test result.d == 1
97-
@test result.e == 1
98-
@test result.f == 0
99-
@test result.g == 1
100-
@test result.h == 0
101-
@test result.i == 1
102-
@test result.j == 0
103-
@test result.k == 1
104-
@test result.l == 1
124+
@test result.equals_test == 0
125+
@test result.not_equals_test == 1
126+
@test result.not_test == 1
127+
@test result.and_test == 0
128+
@test result.or_test == 1
129+
@test result.times_test == 0
130+
@test result.plus_test == 1
131+
@test result.mod_test == 0
132+
@test result.abs_test == 1
133+
@test result.in_test == 1
134+
@test result.coalesce_test == 0
135+
@test result.if_else_test_1 == 1
136+
@test result.if_else_test_2 == 1
137+
@test result.if_else_test_3 == 0
138+
@test result.if_else_test_4 == 0
139+
@test result.if_else_test_5 == 0
140+
@test result.if_else_test_6 == 1
141+
@test result.if_else_test_7 == 1
142+
@test result.ismissing_test == 1
143+
@test result.max_test == 1
144+
@test result.min_test == 0
145+
@test result.occursin_test == 1
146+
@test result.uppercase_test == "AB"
105147

106148
drop!(connection, "test")
107149

test/test.sqlite

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)