Skip to content

Commit

Permalink
Spec setup_regexp_function=cached option in sqlite adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
paddor committed Jan 5, 2024
1 parent e22d633 commit 439c7c3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions spec/adapters/sqlite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,44 @@
@db.get(ja.valid).must_equal 1
end
end if DB.sqlite_version >= 33800


describe 'Regexp support' do
before do
@db = DB

@db.create_table(:names) do
primary_key :id
String :name
end

@db[:names].insert(name: 'Adam')
@db[:names].insert(name: 'Jane')
@db[:names].insert(name: 'John')
@db[:names].insert(name: 'Leo')
@db[:names].insert(name: 'Tim')
@db[:names].insert(name: 'Tom')
end
after do
@db.drop_table?(:names)
end

it "should support regexp" do
@db.must_be :allow_regexp?
end

it "should find by regexp" do
names = @db[:names].where(name: /^J/).map { |row| row[:name] }
names.must_include 'Jane'
names.must_include 'John'
names.wont_include 'Adam'
end

it "caches regexp" do
before = ObjectSpace.count_objects[:T_REGEXP]
@db[:names].where(name: /^J/).map { |row| row[:name] }
after = ObjectSpace.count_objects[:T_REGEXP]
diff = after - before
diff.must_equal 1
end if [:cached, "cached"].include? DB.opts[:setup_regexp_function]
end if DB.adapter_scheme == :sqlite && DB.opts[:setup_regexp_function]

0 comments on commit 439c7c3

Please sign in to comment.