Sha256: 8b153407ac646ce202b2ac52b0c7ce58d4cf9c00c89fc8f08336b321ce2c5821

Contents?: true

Size: 1.05 KB

Versions: 82

Compression:

Stored size: 1.05 KB

Contents

require "helper"

class TestCssCache < Nokogiri::TestCase

  def setup
    super
    @css = "a1 > b2 > c3"
    @parse_result = Nokogiri::CSS.parse(@css)
    @to_xpath_result = @parse_result.map(&:to_xpath)
    Nokogiri::CSS::Parser.class_eval do
      class << @cache
        alias :old_bracket :[]
        attr_reader :count
        def [](key)
          @count ||= 0
          @count += 1
          old_bracket(key)
        end
      end
    end
    assert Nokogiri::CSS::Parser.cache_on?
  end

  def teardown
    Nokogiri::CSS::Parser.clear_cache
    Nokogiri::CSS::Parser.set_cache true
  end

  [ false, true ].each do |cache_setting|
    define_method "test_css_cache_#{cache_setting ? "true" : "false"}" do
      times = cache_setting ? 4 : nil

      Nokogiri::CSS::Parser.set_cache cache_setting

      Nokogiri::CSS.xpath_for(@css)
      Nokogiri::CSS.xpath_for(@css)
      Nokogiri::CSS::Parser.new.xpath_for(@css)
      Nokogiri::CSS::Parser.new.xpath_for(@css)

      assert_equal(times, Nokogiri::CSS::Parser.class_eval { @cache.count })
    end
  end


end

Version data entries

82 entries across 78 versions & 9 rubygems

Version Path
daslabs-0.12.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.11.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
tdiary-5.0.9 vendor/bundle/gems/nokogiri-1.8.2/test/test_css_cache.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/nokogiri-1.8.1/test/test_css_cache.rb
tdiary-5.0.8 vendor/bundle/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.10.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.9.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.8.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.7.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.6.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.5.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
daslabs-0.4.0 vendor/cache/ruby/2.5.0/gems/nokogiri-1.8.2/test/test_css_cache.rb
nokogiri-1.8.2 test/test_css_cache.rb
nokogiri-1.8.2-x86-mingw32 test/test_css_cache.rb
nokogiri-1.8.2-x64-mingw32 test/test_css_cache.rb
nokogiri-1.8.2-java test/test_css_cache.rb
tdiary-5.0.7 vendor/bundle/gems/nokogiri-1.8.1/test/test_css_cache.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/nokogiri-1.8.1/test/test_css_cache.rb
tdiary-5.0.6 vendor/bundle/gems/nokogiri-1.8.1/test/test_css_cache.rb