From c03eb11f8fa370460cb8f74b80117d9568a4ca8b Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Wed, 27 Jan 2021 12:21:15 +0100 Subject: add some tests for boolean and float columns --- test/it_dbi.t | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/it_dbi.t b/test/it_dbi.t index 13708e2..b35c97d 100755 --- a/test/it_dbi.t +++ b/test/it_dbi.t @@ -26,7 +26,9 @@ $primarykey = $dbi->escape_name('ID'); $dbi->query("create temporary table it_dbi_test ( $autoid, x int, + y float, foo varchar(42), + flag boolean, $dyncols, primary key($primarykey) );"); @@ -42,9 +44,9 @@ try { is(it::match('syntax', $e->getMessage()), 'syntax', "Syntax error triggers error"); } -$record->insert(['x' => 42, 'foo' => null]); -$record->insert(['foo' => "bar"]); -$record->insert(['x' => 64738, 'foo' => "q'uux"]); +$record->insert(['x' => 42, 'y' => 0.0001, 'foo' => null, 'flag' => 1]); +$record->insert(['foo' => "bar", 'y' => 1e-10, 'flag' => 0]); +$record->insert(['x' => 64738, 'y' => 1, 'foo' => "q'uux"]); is( $record->ID, @@ -60,10 +62,13 @@ try { $record->read(1); is( - [$record->_key, $record->x, $record->foo], - [1, 42, null], + [$record->_key, $record->x, $record->y, $record->foo], + [1, 42, 0.0001, null], "read" ); +ok(!!$record->flag, "read true boolean"); +$record->read(2); +ok(!$record->flag, "read false boolean"); is( $record->select(), @@ -477,17 +482,17 @@ static function _write_preprocess($data) $record = new my_dbi_test; $record->delete(['WHERE TRUE' ]); -$record->upsert(['ID' => 1, 'x' => 42, 'foo' => ['value' => "a"]]); +$record->upsert(['ID' => 1, 'x' => 42, 'y' => 2.5, 'foo' => ['value' => "a"], 'flag' => 0]); $record->read(1); is($record->x, 42, 'value of x after reading with _read_postprocess'); -is($record->_data, ["ID" => 1, "x" => 42, 'foo' => '{"value":"a"}'], 'data after reading with _read_postprocess'); +is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'foo' => '{"value":"a"}', 'flag' => 0], 'data after reading with _read_postprocess'); is($record->foo, ['value' => "a"], 'field after reading with _read_postprocess'); $record2 = new it_dbi_test; $record2->read(1); is($record2->x, 43, 'raw value of x after writing with _write_preprocess'); -is($record2->_data, ["ID" => 1, "x" => 43, 'foo' => '{"value":"a"}'], 'raw data after writing with _write_preprocess'); +is($record2->_data, ["ID" => 1, "x" => 43, 'y' => 2.5, 'foo' => '{"value":"a"}', 'flag' => 0], 'raw data after writing with _write_preprocess'); $record->update(['foo' => ['value' => "b"]]); -is($record->_data, ["ID" => 1, "x" => 42, 'foo' => '{"value":"b"}'], 'raw data after updating with _write_preprocess'); +is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'foo' => '{"value":"b"}', 'flag' => 0], 'raw data after updating with _write_preprocess'); is($record->foo, ['value' => "b"], 'field data after updating with _write_preprocess'); -- cgit v1.2.3