<commit_before>require 'helper'

class TestLicenseeLicense < Minitest::Test
  def setup
    @license = Licensee::License.new 'MIT'
  end

  should 'read the license body' do
    assert @license.body
    msg = "Expected the following to contain MIT:\n#{@license.body}"
    assert @license.text =~ /MIT/, msg
  end

  should 'read the license body if it contains `---`' do
    license = Licensee::License.new 'MIT'
    content = "---\nfoo: bar\n---\nSome license\n---------\nsome text\n"
    license.instance_variable_set(:@raw_content, content)
    assert_equal "Some license\n---------\nsome text\n", license.body
  end

  should 'read the license meta' do
    assert_equal 'MIT License', @license.meta['title']
  end

  should 'know the license path' do
    path = File.expand_path('./vendor/choosealicense.com/_licenses/mit.txt')
    assert_equal path, @license.path
  end

  should 'know the license name' do
    assert_equal 'MIT License', @license.name
  end

  should 'know the license properties' do
    assert_equal 4, @license.meta['permissions'].length
    assert_equal 1, @license.meta['conditions'].length
    assert_equal 1, @license.meta['limitations'].length
  end

  should 'know the license nickname' do
    expected = 'GNU AGPLv3'
    assert_equal expected, Licensee::License.find('agpl-3.0').nickname
  end

  should 'know the license ID' do
    assert_equal 'mit', @license.key
  end

  should 'know the other license' do
    assert_equal 'other', Licensee::License.find_by_key('other').key
  end

  should 'know license equality' do
    assert @license == Licensee::License.new('MIT')
    refute @license == Licensee::License.new('ISC')
    refute @license.nil?
  end

  should 'know if the license is featured' do
    assert @license.featured?
    assert_equal TrueClass, @license.featured?.class
    refute Licensee::License.new('cc0-1.0').featured?
    assert_equal FalseClass, Licensee::License.new('cc0-1.0').featured?.class
  end

  should 'inject default meta without overriding' do
    license = Licensee::License.new('agpl-3.0')

    assert license.meta.key? 'featured'
    assert_equal false, license.meta['featured']

    assert license.meta.key? 'hidden'
    assert_equal false, license.meta['hidden']
  end

  should 'know when the license is hidden' do
    refute @license.hidden?
    assert Licensee::License.new('ofl-1.1').hidden?
    assert Licensee::License.new('no-license').hidden?
  end

  should 'parse the license parts' do
    assert_equal 3, @license.send(:parts).size
  end

  should 'build the license URL' do
    assert_equal 'http://choosealicense.com/licenses/mit/', @license.url
  end

  should 'return all licenses' do
    assert_equal Array, Licensee::License.all.class
    assert Licensee::License.all.size > 3
  end

  should 'strip leading newlines from the license' do
    assert_equal 'M', @license.body[0]
  end

  should 'fail loudly for invalid licenses' do
    assert_raises(Licensee::InvalidLicense) do
      Licensee::License.new('foo').name
    end
  end

  should "support 'other' licenses" do
    license = Licensee::License.new('other')
    assert_equal nil, license.content
    assert_equal 'Other', license.name
    refute license.featured?
  end<commit_msg>explicitly check for front matter defaults in psuedo licenses<commit_after>require 'helper'

class TestLicenseeLicense < Minitest::Test
  def setup
    @license = Licensee::License.new 'MIT'
  end

  should 'read the license body' do
    assert @license.body
    msg = "Expected the following to contain MIT:\n#{@license.body}"
    assert @license.text =~ /MIT/, msg
  end

  should 'read the license body if it contains `---`' do
    license = Licensee::License.new 'MIT'
    content = "---\nfoo: bar\n---\nSome license\n---------\nsome text\n"
    license.instance_variable_set(:@raw_content, content)
    assert_equal "Some license\n---------\nsome text\n", license.body
  end

  should 'read the license meta' do
    assert_equal 'MIT License', @license.meta['title']
  end

  should 'know the license path' do
    path = File.expand_path('./vendor/choosealicense.com/_licenses/mit.txt')
    assert_equal path, @license.path
  end

  should 'know the license name' do
    assert_equal 'MIT License', @license.name
  end

  should 'know the license properties' do
    assert_equal 4, @license.meta['permissions'].length
    assert_equal 1, @license.meta['conditions'].length
    assert_equal 1, @license.meta['limitations'].length
  end

  should 'know the license nickname' do
    expected = 'GNU AGPLv3'
    assert_equal expected, Licensee::License.find('agpl-3.0').nickname
  end

  should 'know the license ID' do
    assert_equal 'mit', @license.key
  end

  should 'know the other license' do
    assert_equal 'other', Licensee::License.find_by_key('other').key
  end

  should 'know license equality' do
    assert @license == Licensee::License.new('MIT')
    refute @license == Licensee::License.new('ISC')
    refute @license.nil?
  end

  should 'know if the license is featured' do
    assert @license.featured?
    assert_equal TrueClass, @license.featured?.class
    refute Licensee::License.new('cc0-1.0').featured?
    assert_equal FalseClass, Licensee::License.new('cc0-1.0').featured?.class
  end

  should 'inject default meta without overriding' do
    license = Licensee::License.new('agpl-3.0')

    assert license.meta.key? 'featured'
    assert_equal false, license.meta['featured']

    assert license.meta.key? 'hidden'
    assert_equal false, license.meta['hidden']
  end

  should 'know when the license is hidden' do
    refute @license.hidden?
    assert Licensee::License.new('ofl-1.1').hidden?
    assert Licensee::License.new('no-license').hidden?
  end

  should 'parse the license parts' do
    assert_equal 3, @license.send(:parts).size
  end

  should 'build the license URL' do
    assert_equal 'http://choosealicense.com/licenses/mit/', @license.url
  end

  should 'return all licenses' do
    assert_equal Array, Licensee::License.all.class
    assert Licensee::License.all.size > 3
  end

  should 'strip leading newlines from the license' do
    assert_equal 'M', @license.body[0]
  end

  should 'fail loudly for invalid licenses' do
    assert_raises(Licensee::InvalidLicense) do
      Licensee::License.new('foo').name
    end
  end

  should "support 'other' licenses" do
    license = Licensee::License.new('other')
    assert_equal nil, license.content
    assert_equal 'Other', license.name
    assert license.hidden?
    refute license.featured?
    Licensee::License::YAML_DEFAULTS.each do |key, value|
      assert_equal value, license.meta[key]
    end
  end
{'fraction_non_alphanumeric': 0.1198253800993527, 'fraction_numerical': 0.005720307090170104, 'mean_word_length': 3.588397790055249, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2336750', 'n_tokens_mistral': 2085, 'n_tokens_neox': 2020, 'n_words': 579}