Skip to content

Commit

Permalink
fix closing tag for unnamed blocks on MasonLexer (#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed Nov 8, 2020
1 parent 2fe2152 commit f4343b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pygments/lexers/templates.py
Expand Up @@ -565,7 +565,7 @@ class MasonLexer(RegexLexer):

def analyse_text(text):
result = 0.0
if re.search(r'</%(class|doc|init)%>', text) is not None:
if re.search(r'</%(class|doc|init)>', text) is not None:
result = 1.0
elif re.search(r'<&.+&>', text, re.DOTALL) is not None:
result = 0.11
Expand Down
17 changes: 16 additions & 1 deletion tests/test_templates.py
@@ -1,13 +1,16 @@
import pytest

from pygments.lexers.templates import JavascriptDjangoLexer
from pygments.lexers.templates import JavascriptDjangoLexer, MasonLexer
from pygments.token import Comment


@pytest.fixture(scope="module")
def lexer():
yield JavascriptDjangoLexer()

@pytest.fixture(scope='module')
def lexerMason():
yield MasonLexer()

def test_do_not_mistake_JSDoc_for_django_comment(lexer):
"""
Expand All @@ -27,3 +30,15 @@ def test_do_not_mistake_JSDoc_for_django_comment(lexer):
};"""
tokens = lexer.get_tokens(text)
assert not any(t[0] == Comment for t in tokens)

def test_mason_unnamed_block(lexerMason):
text = """
<%class>
has 'foo';
has 'bar' => (required => 1);
has 'baz' => (isa => 'Int', default => 17);
</%class>
"""
res = lexerMason.analyse_text(text)
assert res == 1.0

0 comments on commit f4343b7

Please sign in to comment.