require_relative "./helper"

class TestGenerated < Minitest::Test
  include Linguist

  class DataLoadedError < StandardError; end

  def generated_without_loading_data(name)
    blob = File.join(samples_path, name)
    begin
      assert Generated.generated?(blob, lambda { raise DataLoadedError.new }), "#{name} was not recognized as a generated file"
    rescue DataLoadedError
      assert false, "Data was loaded when calling generated? on #{name}"
    end
  end

  def generated_loading_data(name)
    blob = File.join(samples_path, name)
    assert_raises(DataLoadedError, "Data wasn't loaded when calling generated? on #{name}") do
      Generated.generated?(blob, lambda { raise DataLoadedError.new })
    end
  end

  def test_check_generated_without_loading_data
    # Xcode project files
    generated_without_loading_data("Binary/MainMenu.nib")
    generated_without_loading_data("Dummy/foo.xcworkspacedata")
    generated_without_loading_data("Dummy/foo.xcuserstate")

    # .NET designer file
    generated_without_loading_data("Dummu/foo.designer.cs")

    # Composer generated composer.lock file
    generated_without_loading_data("JSON/composer.lock")

    # Node modules
    generated_without_loading_data("Dummy/node_modules/foo.js")

    # Godep saved dependencies
    generated_without_loading_data("Godeps/Godeps.json")
    generated_without_loading_data("Godeps/_workspace/src/github.com/kr/s3/sign.go")

    # Generated by Zephir
    generated_without_loading_data("C/exception.zep.c")
    generated_without_loading_data("C/exception.zep.h")
    generated_without_loading_data("PHP/exception.zep.php")

    # Minified files
    generated_loading_data("JavaScript/jquery-1.6.1.min.js")
  end
end
