Skip to content

Commit d137639

Browse files
committed
tests: add extract_extension function
1 parent 56a7503 commit d137639

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

test/sql/extract_extension.test

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# name: test/sql/extract_extension.test
2+
# description: Test netquack extension extract_extension function
3+
# group: [netquack]
4+
5+
require netquack
6+
7+
statement ok
8+
CREATE TABLE test_files(path VARCHAR);
9+
10+
statement ok
11+
INSERT INTO test_files VALUES
12+
('/images/photo.jpg'),
13+
('/documents/report.pdf'),
14+
('/archives/data.tar.gz'),
15+
('https://example.com/page.html'),
16+
('https://site.com/download.exe?source=official'),
17+
('/config/settings.json#main'),
18+
('/files/data.v2.csv'),
19+
('/invalid/path..jpg'),
20+
('/no_extension/file'),
21+
('/hidden/.gitignore'),
22+
('/path.with.dots/file'),
23+
('http://domain.com/no_ext'),
24+
('/tmp/file.');
25+
26+
# Basic valid extensions
27+
query I
28+
SELECT extract_extension('/images/photo.jpg');
29+
----
30+
jpg
31+
32+
query I
33+
SELECT extract_extension('/documents/report.pdf');
34+
----
35+
pdf
36+
37+
# Double extensions (should return last valid extension)
38+
query I
39+
SELECT extract_extension('/archives/data.tar.gz');
40+
----
41+
gz
42+
43+
# URLs with extensions
44+
query I
45+
SELECT extract_extension('https://example.com/page.html');
46+
----
47+
html
48+
49+
# With query parameters
50+
query I
51+
SELECT extract_extension('https://site.com/download.exe?source=official');
52+
----
53+
exe
54+
55+
# With fragments
56+
query I
57+
SELECT extract_extension('/config/settings.json#main');
58+
----
59+
json
60+
61+
# Versioned extensions
62+
query I
63+
SELECT extract_extension('/files/data.v2.csv');
64+
----
65+
csv
66+
67+
# Invalid cases (should return NULL)
68+
query I
69+
SELECT extract_extension('/invalid/path..jpg');
70+
----
71+
(empty)
72+
73+
query I
74+
SELECT extract_extension('/no_extension/file');
75+
----
76+
(empty)
77+
78+
query I
79+
SELECT extract_extension('/hidden/.gitignore');
80+
----
81+
(empty)
82+
83+
query I
84+
SELECT extract_extension('/path.with.dots/file');
85+
----
86+
(empty)
87+
88+
query I
89+
SELECT extract_extension('http://domain.com/no_ext');
90+
----
91+
(empty)
92+
93+
query I
94+
SELECT extract_extension('/tmp/file.');
95+
----
96+
(empty)
97+
98+
# Test with table data
99+
query III
100+
SELECT path,
101+
extract_extension(path),
102+
CASE WHEN unicode(extract_extension(path)) == -1 THEN 'INVALID' ELSE 'VALID' END AS status
103+
FROM test_files ORDER BY path;
104+
----
105+
/archives/data.tar.gz gz VALID
106+
/config/settings.json#main json VALID
107+
/documents/report.pdf pdf VALID
108+
/files/data.v2.csv csv VALID
109+
/hidden/.gitignore (empty) INVALID
110+
/images/photo.jpg jpg VALID
111+
/invalid/path..jpg (empty) INVALID
112+
/no_extension/file (empty) INVALID
113+
/path.with.dots/file (empty) INVALID
114+
/tmp/file. (empty) INVALID
115+
http://domain.com/no_ext (empty) INVALID
116+
https://example.com/page.html html VALID
117+
https://site.com/download.exe?source=official exe VALID

0 commit comments

Comments
 (0)