Skip to content

Commit

Permalink
Merge pull request #1260 from pygments/fix/1256
Browse files Browse the repository at this point in the history
Fix #1256.
  • Loading branch information
Anteru committed Nov 24, 2019
2 parents 4aded7d + 8294dc8 commit 461e753
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Version 2.5.0
(fixes #1326)
- Default font in the ``ImageFormatter`` has been updated (#928, PR#1245)
- Test suite switched to py.test, removed nose dependency (#1490)
- Reduce ``TeraTerm`` lexer score -- it used to match nearly all languages
(#1256)


Version 2.4.2
Expand Down
2 changes: 1 addition & 1 deletion pygments/lexers/teraterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ class TeraTermLexer(RegexLexer):
def analyse_text(text):
result = 0.0
if re.search(TeraTermLexer.tokens['commands'][0][0], text):
result += 0.60
result += 0.01
return result
22 changes: 21 additions & 1 deletion tests/test_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

import pytest

from pygments.lexers import CppLexer
from pygments.lexers import CppLexer, CLexer
from pygments.token import Token

from pygments.lexers import guess_lexer


@pytest.fixture(scope='module')
def lexer():
Expand All @@ -33,3 +35,21 @@ def test_open_comment(lexer):
(Token.Comment.Multiline, u'/* foo\n'),
]
assert list(lexer.get_tokens(fragment)) == tokens

def test_guess_c_lexer():
code = '''
#include <stdio.h>
#include <stdlib.h>
int main(void);
int main(void) {
uint8_t x = 42;
uint8_t y = x + 1;
/* exit 1 for success! */
return 1;
}
'''
lexer = guess_lexer(code)
assert isinstance(lexer, CLexer)
Empty file added tests/test_guessing.py
Empty file.

0 comments on commit 461e753

Please sign in to comment.