Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix closing tag for unnamed blocks on MasonLexer #1592

Merged
merged 1 commit into from Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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