Files
linguist/test/test_modelines.rb
chrisarcand d87fad649c Improved vim modeline detection
TLDR: This greatly increases the flexibility of vim modeline detection
to manually set the language of a file.

In vim there are two forms of modelines:

[text]{white}{vi:|vim:|ex:}[white]{options}
examples: 'vim: syntax=perl', 'ex: filetype=ruby'

-and-

[text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text]
examples: 'vim set syntax=perl:', 'Vim: se ft=ruby:'

As you can see, there are many combinations. These changes should allow
most combinations to be used. The two most important additions are the
use of the keyword 'syntax', as well as the addition of the first form
(you now no longer need to use the keyword 'set' with a colon at the end).
The use of first form with 'syntax' is very, very common across GitHub:

https://github.com/search?l=ruby&q=vim%3A+syntax%3D&ref=searchresults&type=Code&utf8=%E2%9C%93
2016-01-16 08:57:20 -05:00

56 lines
3.6 KiB
Ruby

require_relative "./helper"
class TestModelines < Minitest::Test
include Linguist
def assert_modeline(language, blob)
assert_equal language, Linguist::Strategy::Modeline.call(blob).first
end
def test_modeline_strategy
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby2")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby3")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby4")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby5")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby6")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby7")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby8")
assert_modeline Language["Ruby"], fixture_blob("Data/Modelines/ruby9")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplus")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs1")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs2")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs3")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs4")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs5")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs6")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs7")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs8")
assert_modeline Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs9")
assert_modeline Language["Text"], fixture_blob("Data/Modelines/fundamentalEmacs.c")
assert_modeline Language["Prolog"], fixture_blob("Data/Modelines/not_perl.pl")
assert_modeline Language["Smalltalk"], fixture_blob("Data/Modelines/example_smalltalk.md")
assert_modeline Language["PHP"], fixture_blob("Data/Modelines/iamphp.inc")
end
def test_modeline_languages
assert_equal Language["Ruby"], fixture_blob("Data/Modelines/ruby").language
assert_equal Language["Ruby"], fixture_blob("Data/Modelines/ruby2").language
assert_equal Language["Ruby"], fixture_blob("Data/Modelines/ruby3").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplus").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs1").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs2").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs3").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs4").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs5").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs6").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs7").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs8").language
assert_equal Language["C++"], fixture_blob("Data/Modelines/seeplusplusEmacs9").language
assert_equal Language["Text"], fixture_blob("Data/Modelines/fundamentalEmacs.c").language
assert_equal Language["Prolog"], fixture_blob("Data/Modelines/not_perl.pl").language
assert_equal Language["Smalltalk"], fixture_blob("Data/Modelines/example_smalltalk.md").language
assert_equal Language["PHP"], fixture_blob("Data/Modelines/iamphp.inc").language
end
end