Sha256: 1f7408a4aec52f30b296beec9ec5068f627b6e55534db2e633e9fce47ee042c7

Contents?: true

Size: 1.12 KB

Versions: 21

Compression:

Stored size: 1.12 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
      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)

      if cache_setting
        assert_equal(4, Nokogiri::CSS::Parser.class_eval { @cache.count })
      else
        assert_nil(Nokogiri::CSS::Parser.class_eval { @cache.count })
      end
    end
  end


end

Version data entries

21 entries across 18 versions & 3 rubygems

Version Path
tdiary-5.0.11 vendor/bundle/gems/nokogiri-1.8.4/test/test_css_cache.rb
tdiary-5.0.11 vendor/bundle/gems/nokogiri-1.8.5/test/test_css_cache.rb
nokogiri-1.9.0.rc1 test/test_css_cache.rb
nokogiri-1.9.0.rc1-x86-mingw32 test/test_css_cache.rb
nokogiri-1.9.0.rc1-x64-mingw32 test/test_css_cache.rb
nokogiri-1.9.0.rc1-java test/test_css_cache.rb
nokogiri-1.8.5 test/test_css_cache.rb
nokogiri-1.8.5-x86-mingw32 test/test_css_cache.rb
nokogiri-1.8.5-x64-mingw32 test/test_css_cache.rb
nokogiri-1.8.5-java test/test_css_cache.rb
nokogiri-1.8.4 test/test_css_cache.rb
nokogiri-1.8.4-x86-mingw32 test/test_css_cache.rb
nokogiri-1.8.4-x64-mingw32 test/test_css_cache.rb
nokogiri-1.8.4-java test/test_css_cache.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.8.3/test/test_css_cache.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/nokogiri-1.8.3/test/test_css_cache.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.3/test/test_css_cache.rb
nokogiri-1.8.3 test/test_css_cache.rb
nokogiri-1.8.3-x86-mingw32 test/test_css_cache.rb
nokogiri-1.8.3-x64-mingw32 test/test_css_cache.rb