Skip to content

Commit

Permalink
test: add tests for pragma optimize.
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Oct 31, 2024
1 parent 0d31845 commit d975892
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/test_pragmas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@

module SQLite3
class TestPragmas < SQLite3::TestCase
class DatabaseTracker < SQLite3::Database
attr_reader :test_statements

def initialize(...)
@test_statements = []
super
end

def execute(sql, bind_vars = [], &block)
@test_statements << sql
super
end
end

def setup
super
@db = SQLite3::Database.new(":memory:")
@db = DatabaseTracker.new(":memory:")
end

def teardown
@db.close
end

def test_pragma_errors
Expand Down Expand Up @@ -32,5 +50,28 @@ def test_set_boolean_pragma
ensure
@db.set_boolean_pragma("read_uncommitted", 0)
end

def test_optimize_with_no_args
@db.optimize

assert_equal(["PRAGMA optimize"], @db.test_statements)
end

def test_optimize_with_args
@db.optimize(Constants::Optimize::DEFAULT)
@db.optimize(Constants::Optimize::ANALYZE_TABLES | Constants::Optimize::LIMIT_ANALYZE)
@db.optimize(Constants::Optimize::ANALYZE_TABLES | Constants::Optimize::DEBUG)
@db.optimize(Constants::Optimize::DEFAULT | Constants::Optimize::CHECK_ALL_TABLES)

assert_equal(
[
"PRAGMA optimize=18",
"PRAGMA optimize=18",
"PRAGMA optimize=3",
"PRAGMA optimize=65554"
],
@db.test_statements
)
end
end
end

0 comments on commit d975892

Please sign in to comment.