<commit_before># frozen_string_literal: true

require_relative 'spec_helper'

describe 'Asciidoctor::PDF::Converter - List' do
  context 'Unordered' do
    it 'should use different marker for first three list levels' do
      pdf = to_pdf <<~'EOS', analyze: true
      * level one
       ** level two
        *** level three
         **** level four
      * back to level one
      EOS

      expected_lines = [
        '• level one',
        '◦ level two',
        '▪ level three',
        '▪ level four',
        '• back to level one',
      ]

      (expect pdf.lines).to eql expected_lines
    end

    it 'should indent each nested list' do
      pdf = to_pdf <<~'EOS', analyze: true
      * level one
       ** level two
        *** level three
      * back to level one
      EOS

      prev_it = nil
      %w(one two three).each do |it|
        if prev_it
          text = pdf.find_unique_text %(level #{it})
          prev_text = pdf.find_unique_text %(level #{prev_it})
          (expect text[:x]).to be > prev_text[:x]
        end
        prev_it = it
      end
      (expect (pdf.find_unique_text 'level one')[:x]).to eql (pdf.find_unique_text 'back to level one')[:x]
    end

    it 'should disable indent for list if outline_list_indent is 0' do
      pdf = to_pdf <<~'EOS', pdf_theme: { outline_list_indent: 0 }, analyze: true
      before

      * a
      * b
      * c

      after
      EOS

      (expect pdf.lines).to include %(\u2022 a)
      before_text = pdf.find_unique_text 'before'
      list_item_text = pdf.find_unique_text 'a'
      (expect before_text[:x]).to eql list_item_text[:x]
    end

    it 'should use marker specified by style' do
      pdf = to_pdf <<~'EOS', analyze: true
      [square]
      * one
      * two
      * three
      EOS

      (expect pdf.lines).to eql ['▪ one', '▪ two', '▪ three']
    end

    it 'should emit warning if list style is unrecognized and fall back to disc' do
      (expect do
        pdf = to_pdf <<~'EOS', analyze: true
        [oval]
        * one
        * two
        * three
        EOS

        (expect pdf.find_text ?\u2022).to have_size 3
      end).to log_message severity: :WARN, message: 'unknown unordered list style: oval'
    end

    it 'should not emit warning if list style is unrecognized in scratch document' do
      (expect do
        pdf = to_pdf <<~'EOS', analyze: true
        [%unbreakable]
        --
        [foobarbaz]
        * foo
        * bar
        * baz
        --
        EOS

        (expect pdf.find_text ?\u2022).to have_size 3
      end).to log_message severity: :WARN, message: 'unknown unordered list style: foobarbaz' # asserts count of 1
    end

    it 'should make bullets invisible if list has no-bullet style' do
      pdf = to_pdf <<~'EOS', analyze: true
      reference

      [no-bullet]
      * wood
      * hammer
      * nail
      EOS

      (expect pdf.lines[1..-1]).to eql %w(wood hammer nail)
      left_margin = pdf.text[0][:x]
      indents = pdf.text[1..-1].map {|it| it[:x] }
      (expect indents).to have_size 3
      (expect indents.uniq).to have_size 1
      (expect indents[0]).to be > left_margin
    end

    it 'should disable indent for no-bullet list if outline_list_indent is 0' do
      pdf = to_pdf <<~'EOS', pdf_theme: { outline_list_indent: 0 }, analyze: true
      before

      [no-bullet]
      * a
      * b
      * c

      after
      EOS

      (expect pdf.lines).to include 'a'
      before_text = pdf.find_unique_text 'before'
      list_item_text = pdf.find_unique_text 'a'
      (expect before_text[:x]).to eql list_item_text[:x]
    end

    it 'should apply proper indentation for each list style that hides the marker' do
      pdf = to_pdf <<~'EOS', analyze: true
      reference

      [unstyled]
      * unstyled

      [no-bullet]
      * no-bullet

      [none]
      * none
      EOS

      (expect pdf.text).to have_size 4
      left_margin = (pdf.find_unique_text 'reference')[:x]
      unstyled_item = pdf.find_unique_text 'unstyled'
      (expect unstyled_item[:x]).to eql left_margin
      no_bullet_item = pdf.find_unique_text 'no-bullet'
      (expect no_bullet_item[:x]).to eql 56.3805
      none_item = pdf.find_unique_text 'none'
      (expect none_item[:x]).to eql 66.24
    end

    it 'should not indent list with no marker if list indent is set to 0 in theme' do
      pdf = to_pdf <<~'EOS', pdf_theme: { outline_list_indent: 0 }, analyze: true
      before

      [none]
      * a
      * b
      * c

      after
      EOS

      left_margin = (pdf.find_unique_text 'before')[:x]
      none_item = pdf.find_unique_text 'a'
      (expect none_item[:x]).to eql left_margin
    end

    it 'should allow theme to change marker characters' do
      pdf_theme = {
        ulist_marker_disc_content: ?\u25ca,
        ulist_marker_circle_content: ?\u25cc,
        ulist_marker_square_content: '$',
      }

      pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: true
      * diamond
       ** dotted circle
        *** dollar
      EOS

      (expect pdf.lines).to eql [%(\u25ca diamond), %(\u25cc dotted circle), '$ dollar']
    end

    it 'should allow theme to change marker color for ulist' do
      pdf_theme = { ulist_marker_font_color: '00FF00' }<commit_msg>test that list indent defaults to 0 for unstyled list<commit_after># frozen_string_literal: true

require_relative 'spec_helper'

describe 'Asciidoctor::PDF::Converter - List' do
  context 'Unordered' do
    it 'should use different marker for first three list levels' do
      pdf = to_pdf <<~'EOS', analyze: true
      * level one
       ** level two
        *** level three
         **** level four
      * back to level one
      EOS

      expected_lines = [
        '• level one',
        '◦ level two',
        '▪ level three',
        '▪ level four',
        '• back to level one',
      ]

      (expect pdf.lines).to eql expected_lines
    end

    it 'should indent each nested list' do
      pdf = to_pdf <<~'EOS', analyze: true
      * level one
       ** level two
        *** level three
      * back to level one
      EOS

      prev_it = nil
      %w(one two three).each do |it|
        if prev_it
          text = pdf.find_unique_text %(level #{it})
          prev_text = pdf.find_unique_text %(level #{prev_it})
          (expect text[:x]).to be > prev_text[:x]
        end
        prev_it = it
      end
      (expect (pdf.find_unique_text 'level one')[:x]).to eql (pdf.find_unique_text 'back to level one')[:x]
    end

    it 'should disable indent for list if outline_list_indent is 0' do
      pdf = to_pdf <<~'EOS', pdf_theme: { outline_list_indent: 0 }, analyze: true
      before

      * a
      * b
      * c

      after
      EOS

      (expect pdf.lines).to include %(\u2022 a)
      before_text = pdf.find_unique_text 'before'
      list_item_text = pdf.find_unique_text 'a'
      (expect before_text[:x]).to eql list_item_text[:x]
    end

    it 'should use marker specified by style' do
      pdf = to_pdf <<~'EOS', analyze: true
      [square]
      * one
      * two
      * three
      EOS

      (expect pdf.lines).to eql ['▪ one', '▪ two', '▪ three']
    end

    it 'should emit warning if list style is unrecognized and fall back to disc' do
      (expect do
        pdf = to_pdf <<~'EOS', analyze: true
        [oval]
        * one
        * two
        * three
        EOS

        (expect pdf.find_text ?\u2022).to have_size 3
      end).to log_message severity: :WARN, message: 'unknown unordered list style: oval'
    end

    it 'should not emit warning if list style is unrecognized in scratch document' do
      (expect do
        pdf = to_pdf <<~'EOS', analyze: true
        [%unbreakable]
        --
        [foobarbaz]
        * foo
        * bar
        * baz
        --
        EOS

        (expect pdf.find_text ?\u2022).to have_size 3
      end).to log_message severity: :WARN, message: 'unknown unordered list style: foobarbaz' # asserts count of 1
    end

    it 'should make bullets invisible if list has no-bullet style' do
      pdf = to_pdf <<~'EOS', analyze: true
      reference

      [no-bullet]
      * wood
      * hammer
      * nail
      EOS

      (expect pdf.lines[1..-1]).to eql %w(wood hammer nail)
      left_margin = pdf.text[0][:x]
      indents = pdf.text[1..-1].map {|it| it[:x] }
      (expect indents).to have_size 3
      (expect indents.uniq).to have_size 1
      (expect indents[0]).to be > left_margin
    end

    it 'should disable indent for no-bullet list if outline_list_indent is 0' do
      pdf = to_pdf <<~'EOS', pdf_theme: { outline_list_indent: 0 }, analyze: true
      before

      [no-bullet]
      * a
      * b
      * c

      after
      EOS

      (expect pdf.lines).to include 'a'
      before_text = pdf.find_unique_text 'before'
      list_item_text = pdf.find_unique_text 'a'
      (expect before_text[:x]).to eql list_item_text[:x]
    end

    it 'should apply proper indentation for each list style that hides the marker' do
      pdf = to_pdf <<~'EOS', analyze: true
      reference

      [unstyled]
      * unstyled

      [no-bullet]
      * no-bullet

      [none]
      * none
      EOS

      (expect pdf.text).to have_size 4
      left_margin = (pdf.find_unique_text 'reference')[:x]
      unstyled_item = pdf.find_unique_text 'unstyled'
      (expect unstyled_item[:x]).to eql left_margin
      no_bullet_item = pdf.find_unique_text 'no-bullet'
      (expect no_bullet_item[:x]).to eql 56.3805
      none_item = pdf.find_unique_text 'none'
      (expect none_item[:x]).to eql 66.24
    end

    it 'should not indent list with no marker if list indent is not set or set to 0 in theme' do
      [nil, 0].each do |indent|
        pdf = to_pdf <<~'EOS', pdf_theme: { outline_list_indent: 0 }, analyze: true
        before

        [none]
        * a
        * b
        * c

        after
        EOS

        left_margin = (pdf.find_unique_text 'before')[:x]
        none_item = pdf.find_unique_text 'a'
        (expect none_item[:x]).to eql left_margin
      end
    end

    it 'should allow theme to change marker characters' do
      pdf_theme = {
        ulist_marker_disc_content: ?\u25ca,
        ulist_marker_circle_content: ?\u25cc,
        ulist_marker_square_content: '$',
      }

      pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: true
      * diamond
       ** dotted circle
        *** dollar
      EOS

      (expect pdf.lines).to eql [%(\u25ca diamond), %(\u25cc dotted circle), '$ dollar']
    end

    it 'should allow theme to change marker color for ulist' do
      pdf_theme = { ulist_marker_font_color: '00FF00' }
{'fraction_non_alphanumeric': 0.10509464168000754, 'fraction_numerical': 0.009982107543083154, 'mean_word_length': 2.0667051689286744, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '6111035', 'n_tokens_mistral': 3554, 'n_tokens_neox': 3393, 'n_words': 1061}