gobyexample/third_party/pygments/tests/test_lexers_other.py
Hana 9e216da9ef go.mod: add go.mod and move pygments to third_party
After go1.16, go will use module mode by default,
even when the repository is checked out under GOPATH
or in a one-off directory. Add go.mod, go.sum to keep
this repo buildable without opting out of the module
mode.

> go mod init github.com/mmcgrana/gobyexample
> go mod tidy
> go mod vendor

In module mode, the 'vendor' directory is special
and its contents will be actively maintained by the
go command. pygments aren't the dependency the go will
know about, so it will delete the contents from vendor
directory. Move it to `third_party` directory now.

And, vendor the blackfriday package.

Note: the tutorial contents are not affected by the
change in go1.16 because all the examples in this
tutorial ask users to run the go command with the
explicit list of files to be compiled (e.g.
`go run hello-world.go` or `go build command-line-arguments.go`).
When the source list is provided, the go command does
not have to compute the build list and whether it's
running in GOPATH mode or module mode becomes irrelevant.
2021-02-15 16:45:26 -05:00

81 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
"""
Tests for other lexers
~~~~~~~~~~~~~~~~~~~~~~
:copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import glob
import os
import unittest
from pygments.lexers import guess_lexer
from pygments.lexers.scripting import EasytrieveLexer, JclLexer, RexxLexer
def _exampleFilePath(filename):
return os.path.join(os.path.dirname(__file__), 'examplefiles', filename)
class AnalyseTextTest(unittest.TestCase):
def _testCanRecognizeAndGuessExampleFiles(self, lexer):
assert lexer is not None
for pattern in lexer.filenames:
exampleFilesPattern = _exampleFilePath(pattern)
for exampleFilePath in glob.glob(exampleFilesPattern):
with open(exampleFilePath, 'rb') as fp:
text = fp.read().decode('utf-8')
probability = lexer.analyse_text(text)
self.assertTrue(probability > 0,
'%s must recognize %r' % (
lexer.name, exampleFilePath))
guessedLexer = guess_lexer(text)
self.assertEqual(guessedLexer.name, lexer.name)
def testCanRecognizeAndGuessExampleFiles(self):
LEXERS_TO_TEST = [
EasytrieveLexer,
JclLexer,
RexxLexer,
]
for lexerToTest in LEXERS_TO_TEST:
self._testCanRecognizeAndGuessExampleFiles(lexerToTest)
class EasyTrieveLexerTest(unittest.TestCase):
def testCanGuessFromText(self):
self.assertLess(0, EasytrieveLexer.analyse_text('MACRO'))
self.assertLess(0, EasytrieveLexer.analyse_text('\nMACRO'))
self.assertLess(0, EasytrieveLexer.analyse_text(' \nMACRO'))
self.assertLess(0, EasytrieveLexer.analyse_text(' \n MACRO'))
self.assertLess(0, EasytrieveLexer.analyse_text('*\nMACRO'))
self.assertLess(0, EasytrieveLexer.analyse_text(
'*\n *\n\n \n*\n MACRO'))
class RexxLexerTest(unittest.TestCase):
def testCanGuessFromText(self):
self.assertAlmostEqual(0.01,
RexxLexer.analyse_text('/* */'))
self.assertAlmostEqual(1.0,
RexxLexer.analyse_text('''/* Rexx */
say "hello world"'''))
val = RexxLexer.analyse_text('/* */\n'
'hello:pRoceduRe\n'
' say "hello world"')
self.assertTrue(val > 0.5, val)
val = RexxLexer.analyse_text('''/* */
if 1 > 0 then do
say "ok"
end
else do
say "huh?"
end''')
self.assertTrue(val > 0.2, val)
val = RexxLexer.analyse_text('''/* */
greeting = "hello world!"
parse value greeting "hello" name "!"
say name''')
self.assertTrue(val > 0.2, val)