Skip to content

Commit

Permalink
Add method to explicitly retrieve supported languages.
Browse files Browse the repository at this point in the history
  • Loading branch information
MischaTheEvil committed Jun 15, 2017
1 parent 368a28e commit f3b9038
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/coderay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ def get_scanner_options options
options.fetch :scanner_options, {}
end

# Provide a list of supported code languages.
#
# Returns a hash of symbols.
def supported_languages(include_aliases=true, include_internals=false)
languages = CodeRay::Scanners.list
if include_aliases == true
languages += CodeRay::Scanners.plugin_hash.keys.map(&:to_sym)
end
if include_internals == false
languages -= %w(debug default raydebug scanner).map(&:to_sym)
end
return languages
end

end

end
34 changes: 34 additions & 0 deletions test/functional/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,40 @@ def test_list_of_scanners
assert CodeRay::Scanners.list.include?(:text)
end

def test_supported_languages_should_return_array_of_symbols
assert_kind_of(Array, CodeRay.supported_languages)
assert_kind_of(Symbol, CodeRay.supported_languages.first)
end

def test_supported_languages_should_include_languages
assert_includes CodeRay.supported_languages, :ruby
end

def test_supported_languages_without_arguments_should_include_aliases_and_exclude_internals
assert_includes CodeRay.supported_languages, :javascript
refute_includes CodeRay.supported_languages, :debug
end

def test_supported_languages_with_arguments_should_include_aliases_and_exclude_internals
assert_includes CodeRay.supported_languages(true, false), :javascript
refute_includes CodeRay.supported_languages(true, false), :debug
end

def test_supported_languages_with_arguments_should_exclude_aliases_and_include_internals
refute_includes CodeRay.supported_languages(false, true), :javascript
assert_includes CodeRay.supported_languages(false, true), :debug
end

def test_supported_languages_with_arguments_should_include_aliases_and_internals
assert_includes CodeRay.supported_languages(true, true), :javascript
assert_includes CodeRay.supported_languages(true, true), :debug
end

def test_supported_languages_with_arguments_should_exclude_aliases_and_internals
refute_includes CodeRay.supported_languages(false, false), :javascript
refute_includes CodeRay.supported_languages(false, false), :debug
end

def test_token_kinds
assert_kind_of Hash, CodeRay::TokenKinds
for kind, css_class in CodeRay::TokenKinds
Expand Down

0 comments on commit f3b9038

Please sign in to comment.