MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestFunctionsString

Function TestFunctionsString

tests/integration/functions_test.go:8–86  ·  view source on GitHub ↗

TestFunctionsString tests string functions

(t *testing.T)

Source from the content-addressed store, hash-verified

6
7// TestFunctionsString tests string functions
8func TestFunctionsString(t *testing.T) {
9 tests := []QueryTest{
10 // Length functions
11 {Name: "length", Query: "SELECT length('hello')"},
12 {Name: "char_length", Query: "SELECT char_length('hello')"},
13 {Name: "character_length", Query: "SELECT character_length('hello')"},
14 {Name: "octet_length", Query: "SELECT octet_length('hello')"},
15 {Name: "bit_length", Query: "SELECT bit_length('hello')"},
16
17 // Case conversion
18 {Name: "lower", Query: "SELECT lower('HELLO')"},
19 {Name: "upper", Query: "SELECT upper('hello')"},
20 {Name: "initcap", Query: "SELECT initcap('hello world')"},
21
22 // Trimming
23 {Name: "trim_both", Query: "SELECT trim(' hello ')"},
24 {Name: "ltrim", Query: "SELECT ltrim(' hello')"},
25 {Name: "rtrim", Query: "SELECT rtrim('hello ')"},
26 {Name: "btrim", Query: "SELECT btrim('xxhelloxx', 'x')"},
27 {Name: "trim_leading", Query: "SELECT trim(leading 'x' from 'xxxhello')"},
28 {Name: "trim_trailing", Query: "SELECT trim(trailing 'x' from 'helloxxx')"},
29 {Name: "trim_both_char", Query: "SELECT trim(both 'x' from 'xxxhelloxxx')"},
30
31 // Padding
32 {Name: "lpad_space", Query: "SELECT lpad('hello', 10)"},
33 {Name: "lpad_char", Query: "SELECT lpad('hello', 10, 'xy')"},
34 {Name: "rpad_space", Query: "SELECT rpad('hello', 10)"},
35 {Name: "rpad_char", Query: "SELECT rpad('hello', 10, 'xy')"},
36
37 // Substring
38 {Name: "substring_from_for", Query: "SELECT substring('hello world' from 1 for 5)"},
39 {Name: "substring_positional", Query: "SELECT substring('hello world', 1, 5)"},
40 {Name: "substr", Query: "SELECT substr('hello world', 1, 5)"},
41 {Name: "left", Query: "SELECT left('hello', 3)"},
42 {Name: "right", Query: "SELECT right('hello', 3)"},
43
44 // Position/Search
45 {Name: "position", Query: "SELECT position('lo' in 'hello')"},
46 {Name: "strpos", Query: "SELECT strpos('hello', 'lo')"},
47
48 // Replace
49 {Name: "replace", Query: "SELECT replace('hello world', 'world', 'there')"},
50 {Name: "overlay", Query: "SELECT overlay('hello' placing 'XX' from 2 for 3)"},
51 {Name: "translate", Query: "SELECT translate('hello', 'el', 'ip')"},
52
53 // Concatenation
54 {Name: "concat", Query: "SELECT concat('hello', ' ', 'world')"},
55 {Name: "concat_ws", Query: "SELECT concat_ws(', ', 'a', 'b', 'c')"},
56 {Name: "concat_operator", Query: "SELECT 'hello' || ' ' || 'world'"},
57
58 // Split/Join
59 {Name: "string_to_array", Query: "SELECT string_to_array('a,b,c', ',')"},
60 {Name: "array_to_string", Query: "SELECT array_to_string(ARRAY['a', 'b', 'c'], ',')"},
61 {Name: "split_part", Query: "SELECT split_part('a,b,c', ',', 2)"},
62
63 // Formatting
64 {Name: "format_s", Query: "SELECT format('Hello %s', 'world')"},
65 {Name: "format_I", Query: "SELECT format('Column: %I', 'my_column')"},

Callers

nothing calls this directly

Calls 1

runQueryTestsFunction · 0.85

Tested by

no test coverage detected