
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.
95 lines
2.1 KiB
Python
95 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Tests for inheritance in RegexLexer
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
:copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
|
|
:license: BSD, see LICENSE for details.
|
|
"""
|
|
|
|
import unittest
|
|
|
|
from pygments.lexer import RegexLexer, inherit
|
|
from pygments.token import Text
|
|
|
|
|
|
class InheritTest(unittest.TestCase):
|
|
def test_single_inheritance_position(self):
|
|
t = Two()
|
|
pats = [x[0].__self__.pattern for x in t._tokens['root']]
|
|
self.assertEqual(['x', 'a', 'b', 'y'], pats)
|
|
def test_multi_inheritance_beginning(self):
|
|
t = Beginning()
|
|
pats = [x[0].__self__.pattern for x in t._tokens['root']]
|
|
self.assertEqual(['x', 'a', 'b', 'y', 'm'], pats)
|
|
def test_multi_inheritance_end(self):
|
|
t = End()
|
|
pats = [x[0].__self__.pattern for x in t._tokens['root']]
|
|
self.assertEqual(['m', 'x', 'a', 'b', 'y'], pats)
|
|
|
|
def test_multi_inheritance_position(self):
|
|
t = Three()
|
|
pats = [x[0].__self__.pattern for x in t._tokens['root']]
|
|
self.assertEqual(['i', 'x', 'a', 'b', 'y', 'j'], pats)
|
|
|
|
def test_single_inheritance_with_skip(self):
|
|
t = Skipped()
|
|
pats = [x[0].__self__.pattern for x in t._tokens['root']]
|
|
self.assertEqual(['x', 'a', 'b', 'y'], pats)
|
|
|
|
|
|
class One(RegexLexer):
|
|
tokens = {
|
|
'root': [
|
|
('a', Text),
|
|
('b', Text),
|
|
],
|
|
}
|
|
|
|
class Two(One):
|
|
tokens = {
|
|
'root': [
|
|
('x', Text),
|
|
inherit,
|
|
('y', Text),
|
|
],
|
|
}
|
|
|
|
class Three(Two):
|
|
tokens = {
|
|
'root': [
|
|
('i', Text),
|
|
inherit,
|
|
('j', Text),
|
|
],
|
|
}
|
|
|
|
class Beginning(Two):
|
|
tokens = {
|
|
'root': [
|
|
inherit,
|
|
('m', Text),
|
|
],
|
|
}
|
|
|
|
class End(Two):
|
|
tokens = {
|
|
'root': [
|
|
('m', Text),
|
|
inherit,
|
|
],
|
|
}
|
|
|
|
class Empty(One):
|
|
tokens = {}
|
|
|
|
class Skipped(Empty):
|
|
tokens = {
|
|
'root': [
|
|
('x', Text),
|
|
inherit,
|
|
('y', Text),
|
|
],
|
|
}
|
|
|