Skip to content

Commit

Permalink
Add test all converted
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Dec 16, 2024
1 parent 7191ae4 commit 00895af
Show file tree
Hide file tree
Showing 13 changed files with 9,040 additions and 15 deletions.
4 changes: 3 additions & 1 deletion contrib/try_convert/check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
lines = f.read().split('\n')

needed_types = [
'bool',

'int2',
'int4',
'int8',
Expand Down Expand Up @@ -40,7 +42,7 @@
ans = []
is_prining = False
for word in words:
if word not in ['select', 'from',
if word not in ['select', 'from', 'count',
'try_convert', 'try_convert_by_sql', 'try_convert_by_sql_text', 'try_convert_by_sql_with_len_out',
'NULL', 'v', 'v1', 'v2', 'where', 'is', 'not', 'distinct', 'as', 't', '']:
ans += [word]
Expand Down
2 changes: 1 addition & 1 deletion contrib/try_convert/data/tt_bpchar.data
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The return value may differ significantly from what std::cout prints by default,
std::to_string relies on the current C locale for formatting purposes, and therefore concurrent calls to std::to_string from multiple threads may result in partial serialization of calls.
The results of overloads for integer types do not rely on the current C locale, and thus implementations generally avoid access to the current C locale in these overloads for both correctness and performance. However, such avoidance is not guaranteed by the standard.
(until C++26)
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
2 changes: 1 addition & 1 deletion contrib/try_convert/data/tt_char.data
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The return value may differ significantly from what std::cout prints by default,
std::to_string relies on the current C locale for formatting purposes, and therefore concurrent calls to std::to_string from multiple threads may result in partial serialization of calls.
The results of overloads for integer types do not rely on the current C locale, and thus implementations generally avoid access to the current C locale in these overloads for both correctness and performance. However, such avoidance is not guaranteed by the standard.
(until C++26)
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
2 changes: 1 addition & 1 deletion contrib/try_convert/data/tt_citext.data
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The return value may differ significantly from what std::cout prints by default,
std::to_string relies on the current C locale for formatting purposes, and therefore concurrent calls to std::to_string from multiple threads may result in partial serialization of calls.
The results of overloads for integer types do not rely on the current C locale, and thus implementations generally avoid access to the current C locale in these overloads for both correctness and performance. However, such avoidance is not guaranteed by the standard.
(until C++26)
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
6 changes: 6 additions & 0 deletions contrib/try_convert/data/tt_macaddr.data
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
08002b:010203
08002b-010203
0800.2b01.0203
08002b010203
08:00:2b:01:02:03
08-00-2b-01-02-03
08002b:010203
08002b-010203
0800.2b01.0203
08002b010203
8 changes: 8 additions & 0 deletions contrib/try_convert/data/tt_money.data
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ $9
$1,000,000,000,000,000.00
0
$555555555
1,656,343
10
0.01
10.03
$9
$1,000,000,000,000,000.00
0
$555555555
1,656,343
2 changes: 1 addition & 1 deletion contrib/try_convert/data/tt_text.data
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The return value may differ significantly from what std::cout prints by default,
std::to_string relies on the current C locale for formatting purposes, and therefore concurrent calls to std::to_string from multiple threads may result in partial serialization of calls.
The results of overloads for integer types do not rely on the current C locale, and thus implementations generally avoid access to the current C locale in these overloads for both correctness and performance. However, such avoidance is not guaranteed by the standard.
(until C++26)
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
6 changes: 6 additions & 0 deletions contrib/try_convert/data/tt_uuid.data
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11
{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}
a0eebc999c0b4ef8bb6d6bb9bd380a11
a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11
{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11
{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}
a0eebc999c0b4ef8bb6d6bb9bd380a11
a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11
{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}
2 changes: 1 addition & 1 deletion contrib/try_convert/data/tt_varchar.data
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ The return value may differ significantly from what std::cout prints by default,
std::to_string relies on the current C locale for formatting purposes, and therefore concurrent calls to std::to_string from multiple threads may result in partial serialization of calls.
The results of overloads for integer types do not rely on the current C locale, and thus implementations generally avoid access to the current C locale in these overloads for both correctness and performance. However, such avoidance is not guaranteed by the standard.
(until C++26)
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
C++17 provides std::to_chars as a higher-performance locale-independent alternative.
5 changes: 5 additions & 0 deletions contrib/try_convert/data/tt_xml.data
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
<widget> <debug>on</debug> <window title="Sample Konfabulator Widget"> <name>main_window</name> <width>500</width> <height>500</height> </window> <image src="Images/Sun.png" name="sun1"> <hOffset>250</hOffset> <vOffset>250</vOffset> <alignment>center</alignment> </image> <text data="Click Here" size="36" style="bold"> <name>text1</name> <hOffset>250</hOffset> <vOffset>100</vOffset> <alignment>center</alignment> <onMouseUp>sun1.opacity = (sun1.opacity / 100) * 90;</onMouseUp> </text> </widget>
<?xml version="1.0" encoding="UTF-8"?> <book> <name>A Song of Ice and Fire</name> <author>George R. R. Martin</author> <language>English</language> <genre>Epic fantasy</genre> </book>
<students> <student> <name>Rick Grimes</name> <age>35</age> <subject>Maths</subject> <gender>Male</gender> </student> <student> <name>Daryl Dixon </name> <age>33</age> <subject>Science</subject> <gender>Male</gender> </student> <student> <name>Maggie</name> <age>36</age> <subject>Arts</subject> <gender>Female</gender> </student> </students>
<menu> <header>Adobe SVG Viewer</header> <item action="Open" id="Open">Open</item> <item action="OpenNew" id="OpenNew">Open New</item> <separator/> <item action="ZoomIn" id="ZoomIn">Zoom In</item> <item action="ZoomOut" id="ZoomOut">Zoom Out</item> <item action="OriginalView" id="OriginalView">Original View</item> <separator/> <item action="Quality" id="Quality">Quality</item> <item action="Pause" id="Pause">Pause</item> <item action="Mute" id="Mute">Mute</item> <separator/> <item action="Find" id="Find">Find...</item> <item action="FindAgain" id="FindAgain">Find Again</item> <item action="Copy" id="Copy">Copy</item> <item action="CopyAgain" id="CopyAgain">Copy Again</item> <item action="CopySVG" id="CopySVG">Copy SVG</item> <item action="ViewSVG" id="ViewSVG">View SVG</item> <item action="ViewSource" id="ViewSource">View Source</item> <item action="SaveAs" id="SaveAs">Save As</item> <separator/> <item action="Help" id="Help">Help</item> <item action="About" id="About">About Adobe CVG Viewer...</item> </menu>
<menu id="file" value="File"> <popup> <menuitem value="New" onclick="CreateNewDoc()" /> <menuitem value="Open" onclick="OpenDoc()" /> <menuitem value="Close" onclick="CloseDoc()" /> </popup> </menu>
<widget> <debug>on</debug> <window title="Sample Konfabulator Widget"> <name>main_window</name> <width>500</width> <height>500</height> </window> <image src="Images/Sun.png" name="sun1"> <hOffset>250</hOffset> <vOffset>250</vOffset> <alignment>center</alignment> </image> <text data="Click Here" size="36" style="bold"> <name>text1</name> <hOffset>250</hOffset> <vOffset>100</vOffset> <alignment>center</alignment> <onMouseUp>sun1.opacity = (sun1.opacity / 100) * 90;</onMouseUp> </text> </widget>
<?xml version="1.0" encoding="UTF-8"?> <book> <name>A Song of Ice and Fire</name> <author>George R. R. Martin</author> <language>English</language> <genre>Epic fantasy</genre> </book>
<students> <student> <name>Rick Grimes</name> <age>35</age> <subject>Maths</subject> <gender>Male</gender> </student> <student> <name>Daryl Dixon </name> <age>33</age> <subject>Science</subject> <gender>Male</gender> </student> <student> <name>Maggie</name> <age>36</age> <subject>Arts</subject> <gender>Female</gender> </student> </students>
<menu> <header>Adobe SVG Viewer</header> <item action="Open" id="Open">Open</item> <item action="OpenNew" id="OpenNew">Open New</item> <separator/> <item action="ZoomIn" id="ZoomIn">Zoom In</item> <item action="ZoomOut" id="ZoomOut">Zoom Out</item> <item action="OriginalView" id="OriginalView">Original View</item> <separator/> <item action="Quality" id="Quality">Quality</item> <item action="Pause" id="Pause">Pause</item> <item action="Mute" id="Mute">Mute</item> <separator/> <item action="Find" id="Find">Find...</item> <item action="FindAgain" id="FindAgain">Find Again</item> <item action="Copy" id="Copy">Copy</item> <item action="CopyAgain" id="CopyAgain">Copy Again</item> <item action="CopySVG" id="CopySVG">Copy SVG</item> <item action="ViewSVG" id="ViewSVG">View SVG</item> <item action="ViewSource" id="ViewSource">View Source</item> <item action="SaveAs" id="SaveAs">Save As</item> <separator/> <item action="Help" id="Help">Help</item> <item action="About" id="About">About Adobe CVG Viewer...</item> </menu>
56 changes: 47 additions & 9 deletions contrib/try_convert/generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def get_data(type_name):
return type_tables[type_name]

def get_len_from_data(type_name):
f = open(f'data/tt_{type_name}')
f = open(f'data/tt_{type_name}.data')
return(len(f.read().split('\n')))

def get_from_data(type_name, i = None):
Expand All @@ -402,9 +402,10 @@ def get_from_data(type_name, i = None):

## TEST

def create_test(source_name, target_name, test_data, default='NULL', source_varlen=None, target_varlen=None):
def create_test(source_name, target_name, test_data, default='NULL', source_varlen=None, target_varlen=None, source_count=0):

test_filter = 'v1 is distinct from v2' if target_name not in uncomparable_types else 'v1::text is distinct from v2::text'
test_filter_not = 'v1 is not distinct from v2' if target_name not in uncomparable_types else 'v1::text is not distinct from v2::text'

try_convert_sql = f'try_convert_by_sql(v, {default}::{target_name})'

Expand Down Expand Up @@ -432,10 +433,23 @@ def create_test(source_name, target_name, test_data, default='NULL', source_varl
result = \
' v1 | v2 \n' \
'----+----\n' \
'(0 rows)\n' \
'(0 rows)\n'

input_source = query
output_source = remove_empty_lines(query) + '\n' + result
query_not = \
f'select count(*) from (' \
f'select ' \
f'try_convert(v, {default}::{target_name_1}) as v1, ' \
f'{try_convert_sql} as v2' \
f' from {test_data}' \
f') as t(v1, v2) where {test_filter_not};'
result_not = \
' count \n' \
'-------\n' \
f' {source_count}\n' \
'(1 row)\n'

input_source = query + '\n' + query_not
output_source = remove_empty_lines(query) + '\n' + result + '\n' + remove_empty_lines(query_not) + '\n' + result_not

return input_source, output_source

Expand Down Expand Up @@ -463,9 +477,26 @@ def create_test(source_name, target_name, test_data, default='NULL', source_varl

test_corrupted_text_data = f'(select (\'!@#%^&*\' || v || \'!@#%^&*\') from {text_type_table}) as t(v)'

to_text_in, to_text_out = create_test(type_name, string_type, test_type_table, default_value, type_varlen, string_varlen)
from_text_in, from_text_out = create_test(string_type, type_name, text_type_table, default_value, string_varlen, type_varlen)
from_corrupted_text_in, from_corrupted_text_out = create_test(string_type, type_name, test_corrupted_text_data, default_value, string_varlen, type_varlen)
data_count = get_len_from_data(type_name)

to_text_in, to_text_out = create_test(
type_name, string_type,
test_type_table, default_value,
type_varlen, string_varlen,
data_count
)
from_text_in, from_text_out = create_test(
string_type, type_name,
text_type_table, default_value,
string_varlen, type_varlen,
data_count
)
from_corrupted_text_in, from_corrupted_text_out = create_test(
string_type, type_name,
test_corrupted_text_data, default_value,
string_varlen, type_varlen,
data_count
)

text_tests_in += [to_text_in, from_text_in]
text_tests_out += [to_text_out, from_text_out]
Expand Down Expand Up @@ -503,8 +534,15 @@ def create_test(source_name, target_name, test_data, default='NULL', source_varl
for target_varlen in typmod_lens:
if target_varlen is not None and target_name not in typmod_types:
continue

data_count = get_len_from_data(source_name)

test_in, test_out = create_test(source_name, target_name, test_table, default, source_varlen, target_varlen)
test_in, test_out = create_test(
source_name, target_name,
test_table, default,
source_varlen, target_varlen,
data_count
)

function_tests_in += [test_in]
function_tests_out += [test_out]
Expand Down
Loading

0 comments on commit 00895af

Please sign in to comment.