require 'test/unit'

class TestPedantic < Test::Unit::TestCase
  Lib = File.expand_path("../../lib/linguist", __FILE__)

  def file(name)
    File.read(File.join(Lib, name))
  end

  def test_language_names_are_sorted
    languages = []
    file("languages.yml").lines.each do |line|
      if line =~ /^(\w+):$/
        languages << $1
      end
    end
    assert_sorted languages
  end

  def test_extensions_are_sorted
    extensions = nil
    file("languages.yml").lines.each do |line|
      if line =~ /^  extensions:$/
        extensions = []
      elsif extensions && line =~ /^  - \.([\w\-\.]+)( *#.*)?$/
        extensions << $1
      else
        assert_sorted extensions[1..-1] if extensions
        extensions = nil
      end
    end
  end

  def test_filenames_are_sorted
    filenames = nil
    file("languages.yml").lines.each do |line|
      if line =~ /^  filenames:$/
        filenames = []
      elsif filenames && line =~ /^  - \.(\w+)$/
        filenames << $1
      else
        assert_sorted filenames if filenames
        filenames = nil
      end
    end
  end

  def assert_sorted(list)
    previous = nil
    list.each do |item|
      if previous && previous > item
        flunk "#{previous} should come after #{item}"
      end
      previous = item
    end
  end
end

require 'test/unit'
require 'yaml'

class TestPedantic < Test::Unit::TestCase
  filename = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
  LANGUAGES = YAML.load(File.read(filename))

  def test_language_names_are_sorted
    assert_sorted LANGUAGES.keys
  end

  def test_extensions_are_sorted
    LANGUAGES.each do |name, language|
      extensions = language['extensions']
      assert_sorted extensions[1..-1] if extensions && extensions.size > 1
    end
  end

  def test_filenames_are_sorted
    LANGUAGES.each do |name, language|
      assert_sorted language['filenames'] if language['filenames']
    end
  end

  def assert_sorted(list)
    list.each_cons(2) do |previous, item|
      flunk "#{previous} should come after #{item}" if previous > item
    end
  end
end

Make pedantic test actually pedantic
Make pedantic test actually pedantic

What do you call someone that thinks they are pedantic but actually
aren’t? All the crazy custom parsing in this test was making so it
wasn’t actually doing anything.
