mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Extracting common methods into helper.
This commit is contained in:
@@ -2,3 +2,21 @@ require "bundler/setup"
|
|||||||
require "minitest/autorun"
|
require "minitest/autorun"
|
||||||
require "mocha/setup"
|
require "mocha/setup"
|
||||||
require "linguist"
|
require "linguist"
|
||||||
|
|
||||||
|
def fixtures_path
|
||||||
|
File.expand_path("../fixtures", __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fixture_blob(name)
|
||||||
|
name = File.join(fixtures_path, name) unless name =~ /^\//
|
||||||
|
Linguist::FileBlob.new(name, fixtures_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def samples_path
|
||||||
|
File.expand_path("../../samples", __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sample_blob(name)
|
||||||
|
name = File.join(samples_path, name) unless name =~ /^\//
|
||||||
|
Linguist::FileBlob.new(name, samples_path)
|
||||||
|
end
|
||||||
|
|||||||
@@ -14,24 +14,6 @@ class TestBlob < Minitest::Test
|
|||||||
Encoding.default_external = @original_external
|
Encoding.default_external = @original_external
|
||||||
end
|
end
|
||||||
|
|
||||||
def samples_path
|
|
||||||
File.expand_path("../../samples", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fixtures_path
|
|
||||||
File.expand_path("../fixtures", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sample_blob(name)
|
|
||||||
name = File.join(samples_path, name) unless name =~ /^\//
|
|
||||||
FileBlob.new(name, samples_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fixture_blob(name)
|
|
||||||
name = File.join(fixtures_path, name) unless name =~ /^\//
|
|
||||||
FileBlob.new(name, fixtures_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def script_blob(name)
|
def script_blob(name)
|
||||||
blob = sample_blob(name)
|
blob = sample_blob(name)
|
||||||
blob.instance_variable_set(:@name, 'script')
|
blob.instance_variable_set(:@name, 'script')
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ require_relative "./helper"
|
|||||||
class TestClassifier < Minitest::Test
|
class TestClassifier < Minitest::Test
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
def samples_path
|
|
||||||
File.expand_path("../../samples", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fixture(name)
|
def fixture(name)
|
||||||
File.read(File.join(samples_path, name))
|
File.read(File.join(samples_path, name))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ require_relative "./helper"
|
|||||||
class TestGenerated < Minitest::Test
|
class TestGenerated < Minitest::Test
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
def samples_path
|
|
||||||
File.expand_path("../../samples", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
class DataLoadedError < StandardError; end
|
class DataLoadedError < StandardError; end
|
||||||
|
|
||||||
def generated_without_loading_data(name)
|
def generated_without_loading_data(name)
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ require_relative "./helper"
|
|||||||
class TestHeuristcs < Minitest::Test
|
class TestHeuristcs < Minitest::Test
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
def samples_path
|
|
||||||
File.expand_path("../../samples", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fixture(name)
|
def fixture(name)
|
||||||
File.read(File.join(samples_path, name))
|
File.read(File.join(samples_path, name))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,15 +3,6 @@ require_relative "./helper"
|
|||||||
class TestModelines < Minitest::Test
|
class TestModelines < Minitest::Test
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
def fixtures_path
|
|
||||||
File.expand_path("../fixtures", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fixture_blob(name)
|
|
||||||
name = File.join(fixtures_path, name) unless name =~ /^\//
|
|
||||||
FileBlob.new(name, fixtures_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_modeline(language, blob)
|
def assert_modeline(language, blob)
|
||||||
assert_equal language, Linguist::Strategy::Modeline.call(blob).first
|
assert_equal language, Linguist::Strategy::Modeline.call(blob).first
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ require_relative "./helper"
|
|||||||
class TestTokenizer < Minitest::Test
|
class TestTokenizer < Minitest::Test
|
||||||
include Linguist
|
include Linguist
|
||||||
|
|
||||||
def samples_path
|
|
||||||
File.expand_path("../../samples", __FILE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def tokenize(data)
|
def tokenize(data)
|
||||||
data = File.read(File.join(samples_path, data.to_s)) if data.is_a?(Symbol)
|
data = File.read(File.join(samples_path, data.to_s)) if data.is_a?(Symbol)
|
||||||
Tokenizer.tokenize(data)
|
Tokenizer.tokenize(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user