Skip to content

Commit

Permalink
Move format loop out of the type specs
Browse files Browse the repository at this point in the history
That makes it easier to identify the problematic decoder.
  • Loading branch information
larskanis committed Aug 11, 2024
1 parent f225e98 commit 0f387c0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions spec/pg/basic_type_map_for_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,40 +93,40 @@
@conn.type_map_for_results = PG::TypeMapAllStrings.new.freeze
end

it "should do boolean type conversions" do
[1, 0].each do |format|
[1, 0].each do |format|
it "should do format #{format} boolean type conversions" do
res = @conn.exec_params( "SELECT true::BOOLEAN, false::BOOLEAN, NULL::BOOLEAN", [], format )
expect( res.values ).to eq( [[true, false, nil]] )
end
end

it "should do binary type conversions" do
[1, 0].each do |format|
[1, 0].each do |format|
it "should do format #{format} binary type conversions" do
res = @conn.exec_params( "SELECT E'\\\\000\\\\377'::BYTEA", [], format )
expect( res.values ).to eq( [[["00ff"].pack("H*")]] )
expect( res.values[0][0].encoding ).to eq( Encoding::ASCII_8BIT )
end
end

it "should do integer type conversions" do
[1, 0].each do |format|
[1, 0].each do |format|
it "should do format #{format} integer type conversions" do
res = @conn.exec_params( "SELECT -8999::INT2, -899999999::INT4, -8999999999999999999::INT8", [], format )
expect( res.values ).to eq( [[-8999, -899999999, -8999999999999999999]] )
end
end

it "should do string type conversions" do
@conn.internal_encoding = 'utf-8'
[1, 0].each do |format|
[1, 0].each do |format|
it "should do format #{format} string type conversions" do
@conn.internal_encoding = 'utf-8'
res = @conn.exec_params( "SELECT 'abcäöü'::TEXT, 'colname'::name", [], format )
expect( res.values ).to eq( [['abcäöü', 'colname']] )
expect( [res.ftype(0), res.ftype(1)] ).to eq( [25, 19] )
expect( res.values[0].map(&:encoding) ).to eq( [Encoding::UTF_8] * 2 )
end
end

it "should do float type conversions" do
[1, 0].each do |format|
[1, 0].each do |format|
it "should do format #{format} float type conversions" do
res = @conn.exec_params( "SELECT -8.999e3::FLOAT4,
8.999e10::FLOAT4,
-8999999999e-99::FLOAT8,
Expand Down Expand Up @@ -253,8 +253,8 @@
end
end

it "should do numeric type conversions", :bigdecimal do
[0].each do |format|
[0].each do |format|
it "should do format #{format} numeric type conversions", :bigdecimal do
small = '123456790123.12'
large = ('123456790'*10) << '.' << ('012345679')
numerics = [
Expand All @@ -274,8 +274,8 @@
end
end

it "should do JSON conversions", :postgresql_94 do
[0].each do |format|
[0].each do |format|
it "should do format #{format} JSON conversions", :postgresql_94 do
['JSON', 'JSONB'].each do |type|
res = @conn.exec_params( "SELECT CAST('123' AS #{type}),
CAST('12.3' AS #{type}),
Expand All @@ -295,8 +295,8 @@
end
end

it "should do array type conversions" do
[0].each do |format|
[0].each do |format|
it "should do format #{format} array type conversions" do
res = @conn.exec_params( "SELECT CAST('{1,2,3}' AS INT2[]), CAST('{{1,2},{3,4}}' AS INT2[][]),
CAST('{1,2,3}' AS INT4[]),
CAST('{1,2,3}' AS INT8[]),
Expand All @@ -316,8 +316,8 @@
end
end

it "should do inet type conversions" do
[0].each do |format|
[0].each do |format|
it "should do format #{format} inet type conversions" do
vals = [
'1.2.3.4',
'0.0.0.0/0',
Expand Down Expand Up @@ -346,8 +346,8 @@
end
end

it "should do cidr type conversions" do
[0].each do |format|
[0].each do |format|
it "should do format #{format} cidr type conversions" do
vals = [
'0.0.0.0/0',
'1.0.0.0/8',
Expand Down

0 comments on commit 0f387c0

Please sign in to comment.