From 410fe2843dc5281067c413bafe678d87f38f45cd Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 17 Dec 2014 15:55:16 -0500 Subject: [PATCH] Add some tests for grammars.yml It must be sorted, because it will get re-sorted when script/download-grammars is next run and that would clutter up diffs. And it must not contain any duplicate scopes. --- test/test_grammars.rb | 13 +++++++++++++ test/test_pedantic.rb | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/test_grammars.rb diff --git a/test/test_grammars.rb b/test/test_grammars.rb new file mode 100644 index 00000000..96fdb667 --- /dev/null +++ b/test/test_grammars.rb @@ -0,0 +1,13 @@ +require_relative "./helper" + +class TestGrammars < Test::Unit::TestCase + def setup + @grammars = YAML.load(File.read(File.expand_path("../../grammars.yml", __FILE__))) + end + + def test_no_duplicate_scopes + scopes = @grammars.values.flatten + duplicates = scopes.group_by { |s| s }.select { |k, v| v.length > 1 }.map(&:first) + assert duplicates.empty?, "The following scopes appear in grammars.yml more than once:\n#{duplicates.sort.join("\n")}" + end +end diff --git a/test/test_pedantic.rb b/test/test_pedantic.rb index be8ce063..9e35a8f2 100644 --- a/test/test_pedantic.rb +++ b/test/test_pedantic.rb @@ -3,6 +3,7 @@ require_relative "./helper" class TestPedantic < Test::Unit::TestCase filename = File.expand_path("../../lib/linguist/languages.yml", __FILE__) LANGUAGES = YAML.load(File.read(filename)) + GRAMMARS = YAML.load(File.read(File.expand_path("../../grammars.yml", __FILE__))) def test_language_names_are_sorted assert_sorted LANGUAGES.keys @@ -21,6 +22,16 @@ class TestPedantic < Test::Unit::TestCase end end + def test_grammars_are_sorted + assert_sorted GRAMMARS.keys + end + + def test_scopes_are_sorted + GRAMMARS.values.each do |scopes| + assert_sorted scopes + end + end + def assert_sorted(list) list.each_cons(2) do |previous, item| flunk "#{previous} should come after #{item}" if previous > item