Skip to content

Commit 8b89a33

Browse files
committed
More tests for @scalarfunc
1 parent 9dd47a9 commit 8b89a33

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test/runtests.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,29 @@ if VERSION > v"0.4.0-"
104104
@test drop(db,"temp") == EMPTY_RESULTSET
105105
end
106106

107-
r = query(db, sr"SELECT LastName FROM Employee WHERE BirthDate REGEXP '^\d{4}-08'")
107+
r = query(db, sr"SELECT LastName FROM Employee WHERE BirthDate REGEXP '^\d{4}-08'")
108108
@test r.values[1][1] == "Peacock"
109109

110+
@scalarfunc function triple(x)
111+
x * 3
112+
end
113+
@test_throws ErrorException registerfunc(db, 186, triple)
114+
@test_throws ErrorException registerfunc(db, -2, triple)
115+
registerfunc(db, 1, triple)
116+
r = query(db, "SELECT triple(Total) FROM Invoice ORDER BY InvoiceId LIMIT 5")
117+
s = query(db, "SELECT Total FROM Invoice ORDER BY InvoiceId LIMIT 5")
118+
for (i, j) in zip(r.values[1], s.values[1])
119+
@test_approx_eq i j*3
120+
end
121+
122+
@scalarfunc mult (*)
123+
registerfunc(db, -1, mult)
124+
r = query(db, "SELECT Milliseconds, Bytes FROM Track")
125+
s = query(db, "SELECT mult(Milliseconds, Bytes) FROM Track")
126+
@test r[1].*r[2] == s[1]
127+
t = query(db, "SELECT mult(Milliseconds, Bytes, 3, 4) FROM Track")
128+
@test r[1].*r[2]*3*4 == t[1]
129+
110130
@test size(tables(db)) == (11,1)
111131

112132
close(db)

0 commit comments

Comments
 (0)