<commit_before>require 'test_helper'

class RendererTest < Minitest::Test

  def setup
    @swapi = File.read(File.join(fixtures_dir, 'sw-schema.graphql'))
    @parsed_schema = GraphQLDocs::Parser.new(@swapi, {}).parse
    @renderer = GraphQLDocs::Renderer.new(@parsed_schema, GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS)
  end

  def test_that_rendering_works
    contents = @renderer.render('R2D2', type: 'Droid', name: 'R2D2')

    assert_match %r{<title>R2D2</title>}, contents
  end

  def test_that_html_conversion_works
    contents = @renderer.to_html('**R2D2**')

    assert_equal '<p><strong>R2D2</strong></p>', contents
  end
end
<commit_msg>Test filename in pipeline context<commit_after>require 'test_helper'

class RendererTest < Minitest::Test

  def setup
    @swapi = File.read(File.join(fixtures_dir, 'sw-schema.graphql'))
    @parsed_schema = GraphQLDocs::Parser.new(@swapi, {}).parse
    @renderer = GraphQLDocs::Renderer.new(@parsed_schema, GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS)
  end

  def test_that_rendering_works
    contents = @renderer.render('R2D2', type: 'Droid', name: 'R2D2')

    assert_match %r{<title>R2D2</title>}, contents
  end

  def test_that_html_conversion_works
    contents = @renderer.to_html('**R2D2**')

    assert_equal '<p><strong>R2D2</strong></p>', contents
  end

  def test_that_filename_accessible_to_filters
    @renderer = GraphQLDocs::Renderer.new(@parsed_schema, GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge({
      pipeline_config: {
        pipeline:
          %i(ExtendedMarkdownFilter
             EmojiFilter
             TableOfContentsFilter
             AddFilenameFilter),
        context: {
          gfm: false,
          asset_root: 'https://a248.e.akamai.net/assets.github.com/images/icons'
        }
      }
    }))
    contents = @renderer.render('<span id="fill-me"></span>', type: 'Droid', name: 'R2D2', filename: '/this/is/the/filename')
    assert_match %r{<span id="fill-me">/this/is/the/filename</span>}, contents
  end
end

class AddFilenameFilter < HTML::Pipeline::Filter
  def call
    doc.search('span[@id="fill-me"]').each do |span|
      span.inner_html=(context[:filename])
    end
    doc
  end

  def validate
    needs :filename
  end
end

{'fraction_non_alphanumeric': 0.13747228381374724, 'fraction_numerical': 0.011086474501108648, 'mean_word_length': 3.9911504424778763, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7229953', 'n_tokens_mistral': 776, 'n_tokens_neox': 778, 'n_words': 128}