# encoding: UTF-8
require 'pp'
require_relative '../../test_helper'
include Minireq::Gitbook

describe Reader do

  it 'must read .md file' do
    exec_in_minireq_repo do
      txt = "# h1\n## h11\n## h12\n# h2\n## h21\n\n"
      doc = Reader.read(txt)

      doc.find('h1').wont_be_nil
      doc.find('h1').level.must_equal 1

      doc.find('h11').wont_be_nil
      doc.find('h11').level.must_equal 2

      doc.find('h12').wont_be_nil
      doc.find('h12').level.must_equal 2

      doc.find('h2').wont_be_nil
      doc.find('h2').level.must_equal 1

      doc.find('h21').wont_be_nil
      doc.find('h21').level.must_equal 2
    end
  end

  it 'must read requirements.md' do
    exec_in_minireq_repo do
      Minireq.inreq do
        File.write("content.md", "# [f] Functional\n# [n] Non-functional\n")
        File.write("fr.1.md", "# [fr.1] Function 1\n{{\nparent: f\n}}\n")
        File.write("nf.1.md", "# [nf.1] QualityR 1\n{{\nparent: n\n}}\n")
      end
      `minireq doc`
      txt = Minireq.indoc { File.read('requirements.md') }
      doc = Reader.read(txt)
      doc.find('[f] Functional').wont_be_nil
      doc.find('[n] Non-functional').wont_be_nil
      doc.find('[fr.1] Function 1').wont_be_nil
      doc.find('[nf.1] QualityR 1').wont_be_nil
    end
  end

end
