<commit_before>require_relative 'helper'

class Appium::Lint
  describe 'Lint' do
    it 'processes globbed files' do
      lint   = Appium::Lint.new
      dir    = File.join(Dir.pwd, 'spec', 'data', '**', '*.md')

      actual = lint.glob dir

      # 1.md has no problems so it doesn't show up in expected failures
      expected = { '0.md' => { 1 => [H1Missing::FAIL],
                               2 => [H1Invalid::FAIL],
                               5 => [H2Invalid::FAIL] },
                   '3.md' => { 3 => [LineBreakInvalid::FAIL],
                               7 => [LineBreakInvalid::FAIL] } }

      # convert path/to/0.md to 0.md
      actual.keys.each do |key|
        new_key = File.basename key
        actual[new_key] = actual[key]
        actual.delete key
      end

      expect(actual).to eq(expected)
    end

    it 'reports globbed files' do
      lint   = Appium::Lint.new
      dir    = File.join(Dir.pwd, 'spec', 'data', '**', '*.md')

      actual = lint.report lint.glob dir
      expected = (<<REPORT).strip
0.md
  1: #{H1Missing::FAIL}
  2: #{H1Invalid::FAIL}
  5: #{H2Invalid::FAIL}

3.md
  3: #{LineBreakInvalid::FAIL}
  7: #{LineBreakInvalid::FAIL}
REPORT

      expect(actual).to eq(expected)
    end


    it 'processes all rules without raising an exception' do
      lint = Appium::Lint.new<commit_msg>Add empty report test<commit_after>require_relative 'helper'

class Appium::Lint
  describe 'Lint' do
    it 'processes globbed files' do
      lint   = Appium::Lint.new
      dir    = File.join(Dir.pwd, 'spec', 'data', '**', '*.md')

      actual = lint.glob dir

      # 1.md has no problems so it doesn't show up in expected failures
      expected = { '0.md' => { 1 => [H1Missing::FAIL],
                               2 => [H1Invalid::FAIL],
                               5 => [H2Invalid::FAIL] },
                   '3.md' => { 3 => [LineBreakInvalid::FAIL],
                               7 => [LineBreakInvalid::FAIL] } }

      # convert path/to/0.md to 0.md
      actual.keys.each do |key|
        new_key = File.basename key
        actual[new_key] = actual[key]
        actual.delete key
      end

      expect(actual).to eq(expected)
    end

    it 'reports globbed files' do
      lint   = Appium::Lint.new
      dir    = File.join(Dir.pwd, 'spec', 'data', '**', '*.md')

      actual = lint.report lint.glob dir
      expected = (<<REPORT).strip
0.md
  1: #{H1Missing::FAIL}
  2: #{H1Invalid::FAIL}
  5: #{H2Invalid::FAIL}

3.md
  3: #{LineBreakInvalid::FAIL}
  7: #{LineBreakInvalid::FAIL}
REPORT

      expect(actual).to eq(expected)
    end

    it 'empty report is falsey' do
      lint   = Appium::Lint.new
      actual = !! lint.report({})
      expect(actual).to eq(false)
    end

    it 'processes all rules without raising an exception' do
      lint = Appium::Lint.new
{'fraction_non_alphanumeric': 0.14245515300738656, 'fraction_numerical': 0.01618009145269082, 'mean_word_length': 2.0287539936102235, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3662961', 'n_tokens_mistral': 969, 'n_tokens_neox': 923, 'n_words': 235}