From 4a8e158be9bdfa22f112f27ff62e83896ef5af86 Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Mon, 22 Feb 2016 15:47:11 -0600 Subject: add tests for custom lexer/formatter loading from file --- tests/support/empty.py | 0 tests/support/python_lexer.py | 226 ++++++++++++++++++++++++++++++++++++++++++ tests/test_cmdline.py | 35 +++++++ 3 files changed, 261 insertions(+) create mode 100644 tests/support/empty.py create mode 100644 tests/support/python_lexer.py (limited to 'tests') diff --git a/tests/support/empty.py b/tests/support/empty.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/support/python_lexer.py b/tests/support/python_lexer.py new file mode 100644 index 00000000..b1367715 --- /dev/null +++ b/tests/support/python_lexer.py @@ -0,0 +1,226 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.python (as CustomLexer) + ~~~~~~~~~~~~~~~~~~~~~~ + + For test_cmdline.py +""" + +import re + +from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ + default, words, combined, do_insertions +from pygments.util import get_bool_opt, shebang_matches +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Generic, Other, Error +from pygments import unistring as uni + +line_re = re.compile('.*?\n') + + +class CustomLexer(RegexLexer): + """ + For `Python `_ source code. + """ + + name = 'Python' + aliases = ['python', 'py', 'sage'] + filenames = ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'] + mimetypes = ['text/x-python', 'application/x-python'] + + def innerstring_rules(ttype): + return [ + # the old style '%s' % (...) string formatting + (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' + '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol), + # backslashes, quotes and formatting signs must be parsed one at a time + (r'[^\\\'"%\n]+', ttype), + (r'[\'"\\]', ttype), + # unhandled string formatting sign + (r'%', ttype), + # newlines are an error (use "nl" state) + ] + + tokens = { + 'root': [ + (r'\n', Text), + (r'^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")', bygroups(Text, String.Doc)), + (r"^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')", bygroups(Text, String.Doc)), + (r'[^\S\n]+', Text), + (r'\A#!.+$', Comment.Hashbang), + (r'#.*$', Comment.Single), + (r'[]{}:(),;[]', Punctuation), + (r'\\\n', Text), + (r'\\', Text), + (r'(in|is|and|or|not)\b', Operator.Word), + (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator), + include('keywords'), + (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'funcname'), + (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'classname'), + (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), + 'fromimport'), + (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), + 'import'), + include('builtins'), + include('magicfuncs'), + include('magicvars'), + include('backtick'), + ('(?:[rR]|[uU][rR]|[rR][uU])"""', String.Double, 'tdqs'), + ("(?:[rR]|[uU][rR]|[rR][uU])'''", String.Single, 'tsqs'), + ('(?:[rR]|[uU][rR]|[rR][uU])"', String.Double, 'dqs'), + ("(?:[rR]|[uU][rR]|[rR][uU])'", String.Single, 'sqs'), + ('[uU]?"""', String.Double, combined('stringescape', 'tdqs')), + ("[uU]?'''", String.Single, combined('stringescape', 'tsqs')), + ('[uU]?"', String.Double, combined('stringescape', 'dqs')), + ("[uU]?'", String.Single, combined('stringescape', 'sqs')), + include('name'), + include('numbers'), + ], + 'keywords': [ + (words(( + 'assert', 'break', 'continue', 'del', 'elif', 'else', 'except', + 'exec', 'finally', 'for', 'global', 'if', 'lambda', 'pass', + 'print', 'raise', 'return', 'try', 'while', 'yield', + 'yield from', 'as', 'with'), suffix=r'\b'), + Keyword), + ], + 'builtins': [ + (words(( + '__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', + 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', + 'cmp', 'coerce', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod', + 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', + 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id', + 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', + 'list', 'locals', 'long', 'map', 'max', 'min', 'next', 'object', + 'oct', 'open', 'ord', 'pow', 'property', 'range', 'raw_input', 'reduce', + 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', + 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', + 'unichr', 'unicode', 'vars', 'xrange', 'zip'), + prefix=r'(?]*>', '', o) + # rstrip is necessary since HTML inserts a \n after the last + self.assertEqual(o.rstrip(), TESTCODE.rstrip()) + def test_stream_opt(self): o = self.check_success('-lpython', '-s', '-fterminal', stdin=TESTCODE) o = re.sub(r'\x1b\[.*?m', '', o) @@ -211,6 +218,20 @@ class CmdLineTest(unittest.TestCase): e = self.check_failure('-lfooo', TESTFILE) self.assertTrue('Error: no lexer for alias' in e) + # cannot load .py file without load_from_file flag + e = self.check_failure('-l', 'nonexistent.py', TESTFILE) + self.assertTrue('Error: no lexer for alias' in e) + + # lexer file is missing/unreadable + e = self.check_failure('-l', 'nonexistent.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: cannot read' in e) + + # lexer file is malformed + e = self.check_failure('-l', 'support/empty.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: no CustomLexer class found' in e) + # formatter not found e = self.check_failure('-lpython', '-ffoo', TESTFILE) self.assertTrue('Error: no formatter found for name' in e) @@ -219,6 +240,20 @@ class CmdLineTest(unittest.TestCase): e = self.check_failure('-ofoo.foo', TESTFILE) self.assertTrue('Error: no formatter found for file name' in e) + # cannot load .py file without load_from_file flag + e = self.check_failure('-f', 'nonexistent.py', TESTFILE) + self.assertTrue('Error: no formatter found for name' in e) + + # formatter file is missing/unreadable + e = self.check_failure('-f', 'nonexistent.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: cannot read' in e) + + # formatter file is malformed + e = self.check_failure('-f', 'support/empty.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: no CustomFormatter class found' in e) + # output file not writable e = self.check_failure('-o', os.path.join('nonexistent', 'dir', 'out.html'), '-lpython', TESTFILE) -- cgit v1.2.1 From 1dcbeab604b4f6b9402a05895ceef1ce31177339 Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Wed, 24 Feb 2016 17:46:32 -0600 Subject: Update pull request per comments by birkenfeld. Add optional function parameter for the class name to instantiate, and update cli to support this. Move error handling to within the loading functions; they now only raise ClassNotFound. Modify doc with these updates and the version number. Test case clean up and additions. --- tests/support/html_formatter.py | 5 +++++ tests/support/python_lexer.py | 4 +++- tests/test_cmdline.py | 35 +++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 tests/support/html_formatter.py (limited to 'tests') diff --git a/tests/support/html_formatter.py b/tests/support/html_formatter.py new file mode 100644 index 00000000..7f5581ed --- /dev/null +++ b/tests/support/html_formatter.py @@ -0,0 +1,5 @@ + +from pygments.formatters import HtmlFormatter + +class HtmlFormatterWrapper(HtmlFormatter): + name = 'HtmlWrapper' diff --git a/tests/support/python_lexer.py b/tests/support/python_lexer.py index b1367715..f3085748 100644 --- a/tests/support/python_lexer.py +++ b/tests/support/python_lexer.py @@ -17,7 +17,6 @@ from pygments import unistring as uni line_re = re.compile('.*?\n') - class CustomLexer(RegexLexer): """ For `Python `_ source code. @@ -224,3 +223,6 @@ class CustomLexer(RegexLexer): return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \ 'import ' in text[:1000] + +class LexerWrapper(CustomLexer): + name="PythonLexerWrapper" \ No newline at end of file diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 80055a43..6e2c917a 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -111,8 +111,27 @@ class CmdLineTest(unittest.TestCase): os.unlink(name) def test_load_from_file(self): - o = self.check_success('-l', TESTDIR + '/support/python_lexer.py', - '-f', 'html', '--load-from-file', stdin=TESTCODE) + lexer_file = os.path.join(TESTDIR, 'support', 'python_lexer.py') + formatter_file = os.path.join(TESTDIR, 'support', 'html_formatter.py') + + # By default, use CustomLexer + o = self.check_success('-l', lexer_file, '-f', 'html', + '-x', stdin=TESTCODE) + o = re.sub('<[^>]*>', '', o) + # rstrip is necessary since HTML inserts a \n after the last + self.assertEqual(o.rstrip(), TESTCODE.rstrip()) + + # If user specifies a name, use it + o = self.check_success('-f', 'html', '-x', '-l', + lexer_file + ':LexerWrapper', stdin=TESTCODE) + o = re.sub('<[^>]*>', '', o) + # rstrip is necessary since HTML inserts a \n after the last + self.assertEqual(o.rstrip(), TESTCODE.rstrip()) + + # Should also work for formatters + o = self.check_success('-lpython', '-f', + formatter_file + ':HtmlFormatterWrapper', + '-x', stdin=TESTCODE) o = re.sub('<[^>]*>', '', o) # rstrip is necessary since HTML inserts a \n after the last self.assertEqual(o.rstrip(), TESTCODE.rstrip()) @@ -224,13 +243,13 @@ class CmdLineTest(unittest.TestCase): # lexer file is missing/unreadable e = self.check_failure('-l', 'nonexistent.py', - '--load-from-file', TESTFILE) + '-x', TESTFILE) self.assertTrue('Error: cannot read' in e) # lexer file is malformed e = self.check_failure('-l', 'support/empty.py', - '--load-from-file', TESTFILE) - self.assertTrue('Error: no CustomLexer class found' in e) + '-x', TESTFILE) + self.assertTrue('Error: no valid CustomLexer class found' in e) # formatter not found e = self.check_failure('-lpython', '-ffoo', TESTFILE) @@ -246,13 +265,13 @@ class CmdLineTest(unittest.TestCase): # formatter file is missing/unreadable e = self.check_failure('-f', 'nonexistent.py', - '--load-from-file', TESTFILE) + '-x', TESTFILE) self.assertTrue('Error: cannot read' in e) # formatter file is malformed e = self.check_failure('-f', 'support/empty.py', - '--load-from-file', TESTFILE) - self.assertTrue('Error: no CustomFormatter class found' in e) + '-x', TESTFILE) + self.assertTrue('Error: no valid CustomFormatter class found' in e) # output file not writable e = self.check_failure('-o', os.path.join('nonexistent', 'dir', 'out.html'), -- cgit v1.2.1 From aab678de6a08ec50a57b749fc3d5ddc8ef949e3e Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Fri, 26 Feb 2016 14:48:43 -0600 Subject: Use exec instead of imp.load_source Custom lexer/formatter are no longer added to sys.modules() --- tests/support/python_lexer.py | 221 +----------------------------------------- 1 file changed, 4 insertions(+), 217 deletions(-) (limited to 'tests') diff --git a/tests/support/python_lexer.py b/tests/support/python_lexer.py index f3085748..ad34d31b 100644 --- a/tests/support/python_lexer.py +++ b/tests/support/python_lexer.py @@ -6,223 +6,10 @@ For test_cmdline.py """ -import re - -from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ - default, words, combined, do_insertions -from pygments.util import get_bool_opt, shebang_matches -from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Generic, Other, Error -from pygments import unistring as uni - -line_re = re.compile('.*?\n') - -class CustomLexer(RegexLexer): - """ - For `Python `_ source code. - """ - - name = 'Python' - aliases = ['python', 'py', 'sage'] - filenames = ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'] - mimetypes = ['text/x-python', 'application/x-python'] - - def innerstring_rules(ttype): - return [ - # the old style '%s' % (...) string formatting - (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' - '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol), - # backslashes, quotes and formatting signs must be parsed one at a time - (r'[^\\\'"%\n]+', ttype), - (r'[\'"\\]', ttype), - # unhandled string formatting sign - (r'%', ttype), - # newlines are an error (use "nl" state) - ] - - tokens = { - 'root': [ - (r'\n', Text), - (r'^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")', bygroups(Text, String.Doc)), - (r"^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')", bygroups(Text, String.Doc)), - (r'[^\S\n]+', Text), - (r'\A#!.+$', Comment.Hashbang), - (r'#.*$', Comment.Single), - (r'[]{}:(),;[]', Punctuation), - (r'\\\n', Text), - (r'\\', Text), - (r'(in|is|and|or|not)\b', Operator.Word), - (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator), - include('keywords'), - (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'funcname'), - (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'classname'), - (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), - 'fromimport'), - (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), - 'import'), - include('builtins'), - include('magicfuncs'), - include('magicvars'), - include('backtick'), - ('(?:[rR]|[uU][rR]|[rR][uU])"""', String.Double, 'tdqs'), - ("(?:[rR]|[uU][rR]|[rR][uU])'''", String.Single, 'tsqs'), - ('(?:[rR]|[uU][rR]|[rR][uU])"', String.Double, 'dqs'), - ("(?:[rR]|[uU][rR]|[rR][uU])'", String.Single, 'sqs'), - ('[uU]?"""', String.Double, combined('stringescape', 'tdqs')), - ("[uU]?'''", String.Single, combined('stringescape', 'tsqs')), - ('[uU]?"', String.Double, combined('stringescape', 'dqs')), - ("[uU]?'", String.Single, combined('stringescape', 'sqs')), - include('name'), - include('numbers'), - ], - 'keywords': [ - (words(( - 'assert', 'break', 'continue', 'del', 'elif', 'else', 'except', - 'exec', 'finally', 'for', 'global', 'if', 'lambda', 'pass', - 'print', 'raise', 'return', 'try', 'while', 'yield', - 'yield from', 'as', 'with'), suffix=r'\b'), - Keyword), - ], - 'builtins': [ - (words(( - '__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', - 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', - 'cmp', 'coerce', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod', - 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', - 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id', - 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', - 'list', 'locals', 'long', 'map', 'max', 'min', 'next', 'object', - 'oct', 'open', 'ord', 'pow', 'property', 'range', 'raw_input', 'reduce', - 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', - 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', - 'unichr', 'unicode', 'vars', 'xrange', 'zip'), - prefix=r'(? Date: Tue, 20 Sep 2016 07:16:04 +0700 Subject: Provide explanation when a test is skipped SkipTest messages are shown when running the test suite with verbosity, such as `nosetests -v`. They help the user see how to fix the problem, in order to achieve higher coverage when running the test suite. --- tests/test_basic_api.py | 8 ++++---- tests/test_examplefiles.py | 2 +- tests/test_latex_formatter.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 022e6c55..03a452d7 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -161,8 +161,8 @@ def test_formatter_public_api(): try: inst = formatter(opt1="val1") - except (ImportError, FontNotFound): - raise support.SkipTest + except (ImportError, FontNotFound) as e: + raise support.SkipTest(e) try: inst.get_style_defs() @@ -209,9 +209,9 @@ def test_formatter_unicode_handling(): def verify(formatter): try: inst = formatter(encoding=None) - except (ImportError, FontNotFound): + except (ImportError, FontNotFound) as e: # some dependency or font not installed - raise support.SkipTest + raise support.SkipTest(e) if formatter.name != 'Raw tokens': out = format(tokens, inst) diff --git a/tests/test_examplefiles.py b/tests/test_examplefiles.py index f43abf9b..28037a55 100644 --- a/tests/test_examplefiles.py +++ b/tests/test_examplefiles.py @@ -89,7 +89,7 @@ def test_example_files(): def check_lexer(lx, fn): if os.name == 'java' and fn in BAD_FILES_FOR_JYTHON: - raise support.SkipTest + raise support.SkipTest('%s is a known bad file on Jython' % fn) absfn = os.path.join(TESTDIR, 'examplefiles', fn) with open(absfn, 'rb') as fp: text = fp.read() diff --git a/tests/test_latex_formatter.py b/tests/test_latex_formatter.py index 05a6c3ac..fbcb6cde 100644 --- a/tests/test_latex_formatter.py +++ b/tests/test_latex_formatter.py @@ -42,9 +42,9 @@ class LatexFormatterTest(unittest.TestCase): ret = po.wait() output = po.stdout.read() po.stdout.close() - except OSError: + except OSError as e: # latex not available - raise support.SkipTest + raise support.SkipTest(e) else: if ret: print(output) -- cgit v1.2.1 From cdbc000e03a5a92ea2a28020e71218cae5010a5d Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Sat, 1 Oct 2016 18:17:05 +0200 Subject: Added analyse_text() that attempts to detect MySQL and Transact-SQL. --- tests/test_sql.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_sql.py b/tests/test_sql.py index c5f5c758..6be34006 100644 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -8,7 +8,10 @@ """ import unittest -from pygments.lexers.sql import TransactSqlLexer +from pygments.lexers.sql import name_between_bracket_re, \ + name_between_backtick_re, tsql_go_re, tsql_declare_re, \ + tsql_variable_re, MySqlLexer, SqlLexer, TransactSqlLexer + from pygments.token import Comment, Name, Number, Punctuation, Whitespace @@ -72,3 +75,44 @@ class TransactSqlLexerTest(unittest.TestCase): (Comment.Multiline, '*/'), (Comment.Multiline, '*/'), )) + + +class SqlAnalyzeTextTest(unittest.TestCase): + def test_can_match_analyze_text_res(self): + self.assertEqual(['`a`', '`bc`'], + name_between_backtick_re.findall('select `a`, `bc` from some')) + self.assertEqual(['[a]', '[bc]'], + name_between_bracket_re.findall('select [a], [bc] from some')) + self.assertTrue(tsql_declare_re.search('--\nDeClaRe @some int;')) + self.assertTrue(tsql_go_re.search('select 1\ngo\n--')) + self.assertTrue(tsql_variable_re.search( + 'create procedure dbo.usp_x @a int, @b int')) + + def test_can_analyze_text(self): + mysql_lexer = MySqlLexer() + sql_lexer = SqlLexer() + tsql_lexer = TransactSqlLexer() + code_to_expected_lexer_map = { + 'select `a`, `bc` from some': mysql_lexer, + 'select a, bc from some': sql_lexer, + 'select [a], [bc] from some': tsql_lexer, + '-- `a`, `bc`\nselect [a], [bc] from some': tsql_lexer, + '-- `a`, `bc`\nselect [a], [bc] from some; go': tsql_lexer, + } + sql_lexers = set(code_to_expected_lexer_map.values()) + for code, expected_lexer in code_to_expected_lexer_map.items(): + ratings_and_lexers = list((lexer.analyse_text(code), lexer.name) for lexer in sql_lexers) + best_rating, best_lexer_name = sorted(ratings_and_lexers, reverse=True)[0] + expected_rating = expected_lexer.analyse_text(code) + message = ( + 'lexer must be %s (rating %.2f) instead of ' + '%s (rating %.2f) for analyse_text() on code:\n%s') % ( + expected_lexer.name, + expected_rating, + best_lexer_name, + best_rating, + code + ) + self.assertEqual( + expected_lexer.name, best_lexer_name, message + ) -- cgit v1.2.1 From bc4380207f90b0c3f8edb77ad0b32ef1d701079f Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Sun, 2 Oct 2016 12:55:12 +0200 Subject: Added lexer for VBScript. --- tests/examplefiles/example.vbs | 55 +++++++++++++++++++++++++++++++ tests/test_basic.py | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 tests/examplefiles/example.vbs create mode 100644 tests/test_basic.py (limited to 'tests') diff --git a/tests/examplefiles/example.vbs b/tests/examplefiles/example.vbs new file mode 100644 index 00000000..d962b73d --- /dev/null +++ b/tests/examplefiles/example.vbs @@ -0,0 +1,55 @@ +rem VBScript examples + +' Various constants of different types +const someText = "some " & """text""" +const someInt = 123 +const someHex = &h3110c0d3 +const someFloat = 123.45e-67 +const someDate = #1/2/2016# +const someTime = #12:34:56 AM# +const someBool = vbTrue ' -1 + +' Do some math. +radius = 1.e2 +area = radius ^ 2 * 3.1315 +a = 17 : b = 23 +c = sqr(a ^2 + b ^ 2) + +' Write 10 files. +For i = 1 to 10 + createFile( i ) +Next + +Public Sub createFile(a) + Dim fso, TargetFile + TargetPath = "C:\some_" & a & ".tmp" + Set fso = CreateObject("Scripting.FileSystemObject") + Set TargetFile = fso.CreateTextFile(TargetPath) + TargetFile.WriteLine("Hello " & vbCrLf & "world!") + TargetFile.Close +End Sub + +' Define a class with a property. +Class Customer + Private m_CustomerName + + Private Sub Class_Initialize + m_CustomerName = "" + End Sub + + ' CustomerName property. + Public Property Get CustomerName + CustomerName = m_CustomerName + End Property + + Public Property Let CustomerName(custname) + m_CustomerName = custname + End Property +End Class + +' Special constructs +Option Explicit +On Error Resume Next +On Error Goto 0 + +' Comment without terminating CR/LF. \ No newline at end of file diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 00000000..03d10cd2 --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +""" + Pygments Basic lexers tests + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import unittest + +from pygments.lexers.basic import VBScriptLexer +from pygments.token import Error, Name, Number, Punctuation, String, Whitespace + + +class VBScriptLexerTest(unittest.TestCase): + + def setUp(self): + self.lexer = VBScriptLexer() + + def _assert_are_tokens_of_type(self, examples, expected_token_type): + for test_number, example in enumerate(examples.split(), 1): + token_count = 0 + for token_type, token_value in self.lexer.get_tokens(example): + if token_type != Whitespace: + token_count += 1 + self.assertEqual( + token_type, expected_token_type, + 'token_type #%d for %s is be %s but must be %s' % + (test_number, token_value, token_type, expected_token_type)) + self.assertEqual( + token_count, 1, + '%s must yield exactly 1 token instead of %d' % + (example, token_count)) + + def _assert_tokens_match(self, text, expected_tokens_without_trailing_newline): + actual_tokens = tuple(self.lexer.get_tokens(text)) + if (len(actual_tokens) >= 1) and (actual_tokens[-1] == (Whitespace, '\n')): + actual_tokens = tuple(actual_tokens[:-1]) + self.assertEqual( + expected_tokens_without_trailing_newline, actual_tokens, + 'text must yield expected tokens: %s' % text) + + def test_can_lex_float(self): + self._assert_are_tokens_of_type( + '1. 1.e1 .1 1.2 1.2e3 1.2e+3 1.2e-3 1e2', Number.Float) + self._assert_tokens_match( + '1e2.1e2', + ((Number.Float, '1e2'), (Number.Float, '.1e2')) + ) + + def test_can_reject_almost_float(self): + self._assert_tokens_match( + '.e1', + ((Punctuation, '.'), (Name, 'e1'))) + + def test_can_lex_integer(self): + self._assert_are_tokens_of_type( + '1 23 456', Number.Integer) + + def test_can_lex_names(self): + self._assert_are_tokens_of_type( + u'thingy thingy123 _thingy _123', Name) + + def test_can_recover_after_unterminated_string(self): + self._assert_tokens_match( + '"x\nx', + ((String.Double, '"'), (String.Double, 'x'), (Error, '\n'), (Name, 'x')) + ) + + def test_can_recover_from_invalid_character(self): + self._assert_tokens_match( + 'a;bc\nd', + ((Name, 'a'), (Error, ';bc\n'), (Name, 'd')) + ) -- cgit v1.2.1 From c8f8ac0ef923681e47ff852809c28978fa790176 Mon Sep 17 00:00:00 2001 From: Nathan Reed Date: Wed, 5 Oct 2016 17:36:45 -0700 Subject: Add example file for HLSL --- tests/examplefiles/example.hlsl | 157 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 tests/examplefiles/example.hlsl (limited to 'tests') diff --git a/tests/examplefiles/example.hlsl b/tests/examplefiles/example.hlsl new file mode 100644 index 00000000..77f1fa49 --- /dev/null +++ b/tests/examplefiles/example.hlsl @@ -0,0 +1,157 @@ +// A few random snippets of HLSL shader code I gathered... + +[numthreads(256, 1, 1)] +void cs_main(uint3 threadId : SV_DispatchThreadID) +{ + // Seed the PRNG using the thread ID + rng_state = threadId.x; + + // Generate a few numbers... + uint r0 = rand_xorshift(); + uint r1 = rand_xorshift(); + // Do some stuff with them... + + // Generate a random float in [0, 1)... + float f0 = float(rand_xorshift()) * (1.0 / 4294967296.0); + + // ...etc. +} + +// Constant buffer of parameters +cbuffer IntegratorParams : register(b0) +{ + float2 specPow; // Spec powers in XY directions (equal for isotropic BRDFs) + float3 L; // Unit vector toward light + int2 cThread; // Total threads launched in XY dimensions + int2 xyOutput; // Where in the output buffer to store the result +} + +static const float pi = 3.141592654; + +float AshikhminShirleyNDF(float3 H) +{ + float normFactor = sqrt((specPow.x + 2.0f) * (specPow.y + 2.0)) * (0.5f / pi); + float NdotH = H.z; + float2 Hxy = normalize(H.xy); + return normFactor * pow(NdotH, dot(specPow, Hxy * Hxy)); +} + +float BeckmannNDF(float3 H) +{ + float glossFactor = specPow.x * 0.5f + 1.0f; // This is 1/m^2 in the usual Beckmann formula + float normFactor = glossFactor * (1.0f / pi); + float NdotHSq = H.z * H.z; + return normFactor / (NdotHSq * NdotHSq) * exp(glossFactor * (1.0f - 1.0f / NdotHSq)); +} + +// Output buffer for compute shader (actually float, but must be declared as uint +// for atomic operations to work) +globallycoherent RWTexture2D o_data : register(u0); + +// Sum up the outputs of all threads and store to the output location +static const uint threadGroupSize2D = 16; +static const uint threadGroupSize1D = threadGroupSize2D * threadGroupSize2D; +groupshared float g_partialSums[threadGroupSize1D]; +void SumAcrossThreadsAndStore(float value, uint iThreadInGroup) +{ + // First reduce within the threadgroup: partial sums of 2, 4, 8... elements + // are calculated by 1/2, 1/4, 1/8... of the threads, always keeping the + // active threads at the front of the group to minimize divergence. + + // NOTE: there are faster ways of doing this...but this is simple to code + // and good enough. + + g_partialSums[iThreadInGroup] = value; + GroupMemoryBarrierWithGroupSync(); + + [unroll] for (uint i = threadGroupSize1D / 2; i > 0; i /= 2) + { + if (iThreadInGroup < i) + { + g_partialSums[iThreadInGroup] += g_partialSums[iThreadInGroup + i]; + } + GroupMemoryBarrierWithGroupSync(); + } + + // Then reduce across threadgroups: one thread from each group adds the group + // total to the final output location, using a software transactional memory + // style since D3D11 doesn't support atomic add on floats. + // (Assumes the output value has been cleared to zero beforehand.) + + if (iThreadInGroup == 0) + { + float threadGroupSum = g_partialSums[0]; + uint outputValueRead = o_data[xyOutput]; + while (true) + { + uint newOutputValue = asuint(asfloat(outputValueRead) + threadGroupSum); + uint previousOutputValue; + InterlockedCompareExchange( + o_data[xyOutput], outputValueRead, newOutputValue, previousOutputValue); + if (previousOutputValue == outputValueRead) + break; + outputValueRead = previousOutputValue; + } + } +} + +void main( + in Vertex i_vtx, + out Vertex o_vtx, + out float3 o_vecCamera : CAMERA, + out float4 o_uvzwShadow : UVZW_SHADOW, + out float4 o_posClip : SV_Position) +{ + o_vtx = i_vtx; + o_vecCamera = g_posCamera - i_vtx.m_pos; + o_uvzwShadow = mul(float4(i_vtx.m_pos, 1.0), g_matWorldToUvzwShadow); + o_posClip = mul(float4(i_vtx.m_pos, 1.0), g_matWorldToClip); +} + +#pragma pack_matrix(row_major) + +struct Vertex +{ + float3 m_pos : POSITION; + float3 m_normal : NORMAL; + float2 m_uv : UV; +}; + +cbuffer CBFrame : CB_FRAME // matches struct CBFrame in test.cpp +{ + float4x4 g_matWorldToClip; + float4x4 g_matWorldToUvzwShadow; + float3x3 g_matWorldToUvzShadowNormal; + float3 g_posCamera; + + float3 g_vecDirectionalLight; + float3 g_rgbDirectionalLight; + + float2 g_dimsShadowMap; + float g_normalOffsetShadow; + float g_shadowSharpening; + + float g_exposure; // Exposure multiplier +} + +Texture2D g_texDiffuse : register(t0); +SamplerState g_ss : register(s0); + +void main( + in Vertex i_vtx, + in float3 i_vecCamera : CAMERA, + in float4 i_uvzwShadow : UVZW_SHADOW, + out float3 o_rgb : SV_Target) +{ + float3 normal = normalize(i_vtx.m_normal); + + // Sample shadow map + float shadow = EvaluateShadow(i_uvzwShadow, normal); + + // Evaluate diffuse lighting + float3 diffuseColor = g_texDiffuse.Sample(g_ss, i_vtx.m_uv); + float3 diffuseLight = g_rgbDirectionalLight * (shadow * saturate(dot(normal, g_vecDirectionalLight))); + diffuseLight += SimpleAmbient(normal); + + o_rgb = diffuseColor * diffuseLight; +} -- cgit v1.2.1 From fd29a2dadd503adbfaf9f677acd0838831ed1af1 Mon Sep 17 00:00:00 2001 From: Christian Hammond Date: Fri, 4 Nov 2016 16:57:38 -0700 Subject: Add support for partials and path segments for Handlebars. This introduces support for some missing features to the Handlebars lexer: Partials and path segments. Partials mostly appeared to work before, but the `>` in `{{> ... }}` would appear as a syntax error, as could other components of the partial. This change introduces support for: * Standard partials: `{{> partialName}}` * Partials with parameters: `{{> partialName varname="value"}}` * Ddynamic partials: `{{> (partialFunc)}}` * Ddynamic partials with lookups: `{{> (lookup ../path "partialName")}}` * Partial blocks: `{{> @partial-block}}` * Inline partials: `{{#*inline}}..{{/inline}}` It also introduces support for path segments, which can reference content in the current context or in a parent context. For instance, `this.name`, `this/name`, `./name`, `../name`, `this/name`, etc. These are all now tracked as variables. --- tests/examplefiles/demo.hbs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/demo.hbs b/tests/examplefiles/demo.hbs index 1b9ed5a7..ae80cc1b 100644 --- a/tests/examplefiles/demo.hbs +++ b/tests/examplefiles/demo.hbs @@ -10,3 +10,25 @@ {{else}} {{/if}} + +{{> myPartial}} +{{> myPartial var="value" }} +{{> myPartial var=../value}} +{{> (myPartial)}} +{{> (myPartial) var="value"}} +{{> (lookup . "myPartial")}} +{{> ( lookup . "myPartial" ) var="value" }} +{{> (lookup ../foo "myPartial") var="value" }} +{{> @partial-block}} + +{{#>myPartial}} +... +{{/myPartial}} + +{{#*inline "myPartial"}} +... +{{/inline}} + +{{../name}} +{{./name}} +{{this/name}} -- cgit v1.2.1 From 5c31893c2af08aa03dc37ca18db213dbfb244c79 Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Tue, 22 Nov 2016 10:14:00 -0500 Subject: SLexer improvements - Remove list of base functions in favor of classifying all calls as Name.Function - Rewrite regex for variable name detection - Correctly classify backtick variable names as Name - Add a few tests for the above --- tests/test_r.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/test_r.py (limited to 'tests') diff --git a/tests/test_r.py b/tests/test_r.py new file mode 100644 index 00000000..a6464480 --- /dev/null +++ b/tests/test_r.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +""" + R Tests + ~~~~~~~~~ + + :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest + +from pygments.lexers import SLexer +from pygments.token import Token, Name, Punctuation + + +class RTest(unittest.TestCase): + def setUp(self): + self.lexer = SLexer() + + def testCall(self): + fragment = u'f(1, a)\n' + tokens = [ + (Name.Function, u'f'), + (Punctuation, u'('), + (Token.Literal.Number, u'1'), + (Punctuation, u','), + (Token.Text, u' '), + (Token.Name, u'a'), + (Punctuation, u')'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testName1(self): + fragment = u'._a_2.c' + tokens = [ + (Name, u'._a_2.c'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testName2(self): + # Invalid names are valid if backticks are used + fragment = u'`.1 blah`' + tokens = [ + (Name, u'`.1 blah`'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testCustomOperator(self): + fragment = u'7 % and % 8' + tokens = [ + (Token.Literal.Number, u'7'), + (Token.Text, u' '), + (Token.Operator, u'% and %'), + (Token.Text, u' '), + (Token.Literal.Number, u'8'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) -- cgit v1.2.1 From e028505914e2e201bb2e346e32d5d29453151750 Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Tue, 22 Nov 2016 11:23:14 -0500 Subject: Support escaping internal backticks --- tests/test_r.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/test_r.py b/tests/test_r.py index a6464480..d0e9090b 100644 --- a/tests/test_r.py +++ b/tests/test_r.py @@ -48,6 +48,15 @@ class RTest(unittest.TestCase): ] self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + def testName3(self): + # Internal backticks can be escaped + fragment = u'`.1 \` blah`' + tokens = [ + (Name, u'`.1 \` blah`'), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + def testCustomOperator(self): fragment = u'7 % and % 8' tokens = [ -- cgit v1.2.1 From a56edd5e77a551a3e310e25e1f204756b67d6730 Mon Sep 17 00:00:00 2001 From: Nathan Whetsell Date: Sun, 11 Dec 2016 12:29:56 -0500 Subject: Update for Csound 6.08.0 --- tests/examplefiles/test.csd | 32 +++++++++++++------------------- tests/examplefiles/test.orc | 32 +++++++++++++------------------- tests/examplefiles/test.sco | 2 +- 3 files changed, 27 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/examplefiles/test.csd b/tests/examplefiles/test.csd index 9122309b..3f43bede 100644 --- a/tests/examplefiles/test.csd +++ b/tests/examplefiles/test.csd @@ -13,6 +13,7 @@ nchnls_i = 1 sr = 44100 0dbfs = 1 ksmps = 10 +A4 = 440 // The control rate kr = sr / ksmps can be omitted when the number of audio // samples in a control period (ksmps) is set, but kr may appear in older @@ -80,9 +81,8 @@ instr TestOscillator outc(anOscillator(0dbfs, 110)) endin -// Python can be executed in Csound -// . So can Lua -// . +// You can execute Python and +// Lua in Csound. pyruni {{ import random @@ -106,13 +106,13 @@ def get_number_from_pool(n, p): #define A_HZ #440# // This is a function-like macro: -#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# // Bodies of macros are enclosed in # and can contain newlines. The arguments of // function-like macros are separated by single-quotes. Uses of macros are // prefixed with a dollar sign. instr TestMacro - aSignal $OSCIL_MACRO(1'$A_HZ'1) + aSignal $OSCIL_MACRO(1' $A_HZ' 1) // Not unlike PHP, macros expand in double-quoted strings. prints "The frequency of the oscillator is $A_HZ Hz.\n" out aSignal @@ -129,7 +129,7 @@ instr TestBitwiseNOT endin // Csound uses # for bitwise XOR, which the Csound manual calls bitwise -// non-equivalence . +// non-equivalence . instr TestBitwiseXOR print 0 # 0 print 0 # 1 @@ -178,10 +178,8 @@ loop_lt_label: od endin -// The prints and printks opcodes -// , arguably -// the primary methods of logging output, treat certain sequences of characters -// different from printf in C. +// The prints and printks opcodes, arguably the primary methods of logging +// output, treat certain sequences of characters different from printf in C. instr TestPrints // ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character // (U+005E). ^^ prints a CIRCUMFLEX ACCENT. @@ -202,26 +200,22 @@ endin // The arguments of function-like macros can be separated by # instead of '. // These two lines define the same macro. -#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# -#define OSCIL_MACRO(VOLUME#FREQUENCY#TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME# FREQUENCY# TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# // Uses of macros can optionally be suffixed with a period. instr TestMacroPeriodSuffix - aSignal $OSCIL_MACRO.(1'$A_HZ'1) + aSignal $OSCIL_MACRO.(1' $A_HZ' 1) prints "The frequency of the oscillator is $A_HZ.Hz.\n" out aSignal endin // Csound has @ and @@ operator-like macros that, when followed by a literal // non-negative integer, expand to the next power of 2 and the next power of 2 -// plus 1: +// plus 1 : // @x = 2^(ceil(log2(x + 1))), x >= 0 // @@0 = 2 // @@x = 2^(ceil(log2(x))) + 1, x > 0 -// These macros are in -// (and -// ) -// and are described at . instr TestAt prints "%d %2d %2d\n", 0, @0, @@0 prints "%d %2d %2d\n", 1, @1, @@1 @@ -252,7 +246,7 @@ i "TestOscillator" 2 2 i "TestBitwiseNOT" 0 1 i "TestBitwiseXOR" 0 1 i "TestGoto" 0 1 -i "TestMacroPeriodSuffix" 4 1 +i "TestMacroPeriodSuffix" 0 1 i "TestAt" 0 1 i "MacroAbuse" 0 1 e diff --git a/tests/examplefiles/test.orc b/tests/examplefiles/test.orc index 36725342..36e35b34 100644 --- a/tests/examplefiles/test.orc +++ b/tests/examplefiles/test.orc @@ -11,6 +11,7 @@ nchnls_i = 1 sr = 44100 0dbfs = 1 ksmps = 10 +A4 = 440 // The control rate kr = sr / ksmps can be omitted when the number of audio // samples in a control period (ksmps) is set, but kr may appear in older @@ -78,9 +79,8 @@ instr TestOscillator outc(anOscillator(0dbfs, 110)) endin -// Python can be executed in Csound -// . So can Lua -// . +// You can execute Python and +// Lua in Csound. pyruni {{ import random @@ -104,13 +104,13 @@ def get_number_from_pool(n, p): #define A_HZ #440# // This is a function-like macro: -#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# // Bodies of macros are enclosed in # and can contain newlines. The arguments of // function-like macros are separated by single-quotes. Uses of macros are // prefixed with a dollar sign. instr TestMacro - aSignal $OSCIL_MACRO(1'$A_HZ'1) + aSignal $OSCIL_MACRO(1' $A_HZ' 1) // Not unlike PHP, macros expand in double-quoted strings. prints "The frequency of the oscillator is $A_HZ Hz.\n" out aSignal @@ -127,7 +127,7 @@ instr TestBitwiseNOT endin // Csound uses # for bitwise XOR, which the Csound manual calls bitwise -// non-equivalence . +// non-equivalence . instr TestBitwiseXOR print 0 # 0 print 0 # 1 @@ -176,10 +176,8 @@ loop_lt_label: od endin -// The prints and printks opcodes -// , arguably -// the primary methods of logging output, treat certain sequences of characters -// different from printf in C. +// The prints and printks opcodes, arguably the primary methods of logging +// output, treat certain sequences of characters different from printf in C. instr TestPrints // ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character // (U+005E). ^^ prints a CIRCUMFLEX ACCENT. @@ -200,26 +198,22 @@ endin // The arguments of function-like macros can be separated by # instead of '. // These two lines define the same macro. -#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# -#define OSCIL_MACRO(VOLUME#FREQUENCY#TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME# FREQUENCY# TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# // Uses of macros can optionally be suffixed with a period. instr TestMacroPeriodSuffix - aSignal $OSCIL_MACRO.(1'$A_HZ'1) + aSignal $OSCIL_MACRO.(1' $A_HZ' 1) prints "The frequency of the oscillator is $A_HZ.Hz.\n" out aSignal endin // Csound has @ and @@ operator-like macros that, when followed by a literal // non-negative integer, expand to the next power of 2 and the next power of 2 -// plus 1: +// plus 1 : // @x = 2^(ceil(log2(x + 1))), x >= 0 // @@0 = 2 // @@x = 2^(ceil(log2(x))) + 1, x > 0 -// These macros are in -// (and -// ) -// and are described at . instr TestAt prints "%d %2d %2d\n", 0, @0, @@0 prints "%d %2d %2d\n", 1, @1, @@1 @@ -250,7 +244,7 @@ i "TestOscillator" 2 2 i "TestBitwiseNOT" 0 1 i "TestBitwiseXOR" 0 1 i "TestGoto" 0 1 -i "TestMacroPeriodSuffix" 4 1 +i "TestMacroPeriodSuffix" 0 1 i "TestAt" 0 1 i "MacroAbuse" 0 1 e diff --git a/tests/examplefiles/test.sco b/tests/examplefiles/test.sco index a0b39251..07818133 100644 --- a/tests/examplefiles/test.sco +++ b/tests/examplefiles/test.sco @@ -4,7 +4,7 @@ i "TestOscillator" 2 2 i "TestBitwiseNOT" 0 1 i "TestBitwiseXOR" 0 1 i "TestGoto" 0 1 -i "TestMacroPeriodSuffix" 4 1 +i "TestMacroPeriodSuffix" 0 1 i "TestAt" 0 1 i "MacroAbuse" 0 1 e -- cgit v1.2.1 From 31787399112ac4f6ad30895b460a1e53276e2061 Mon Sep 17 00:00:00 2001 From: Tom Hunger Date: Mon, 19 Dec 2016 11:23:30 +0000 Subject: Add `family` as a keyword to support Haskell's type families. See #820. --- tests/examplefiles/example.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/example.hs b/tests/examplefiles/example.hs index f5e2b555..3a0c3032 100644 --- a/tests/examplefiles/example.hs +++ b/tests/examplefiles/example.hs @@ -29,3 +29,8 @@ data ĈrazyThings = -- some char literals: charl = ['"', 'a', '\ESC', '\'', ' '] + +-- closed type families +type family Fam (a :: Type) = r :: Type where + Fam Int = True + Fam a = False -- cgit v1.2.1 From 4cba1dc69e9fb3be36936ad70082ee831c362eb6 Mon Sep 17 00:00:00 2001 From: Tom Hunger Date: Mon, 19 Dec 2016 11:34:08 +0000 Subject: Support GHC DataKinds extension. Closes #820. --- tests/examplefiles/example.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/example.hs b/tests/examplefiles/example.hs index 3a0c3032..764cab77 100644 --- a/tests/examplefiles/example.hs +++ b/tests/examplefiles/example.hs @@ -34,3 +34,8 @@ charl = ['"', 'a', '\ESC', '\'', ' '] type family Fam (a :: Type) = r :: Type where Fam Int = True Fam a = False + +-- type literals +type IntChar = '[Int, Char] +type Falsy = 'False +type Falsy = '(10, 20, 30) -- cgit v1.2.1 From 7fd626cad80ee0257ac4ac5b1365d5cbb52ac247 Mon Sep 17 00:00:00 2001 From: Nathan Reed Date: Thu, 29 Dec 2016 17:48:53 -0800 Subject: Add string literal parsing to HLSL lexer (copied from the one for C++). - Also added a snippet to the example file where a string shows up (uncommon in HLSL). --- tests/examplefiles/example.hlsl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/example.hlsl b/tests/examplefiles/example.hlsl index 77f1fa49..21d0a672 100644 --- a/tests/examplefiles/example.hlsl +++ b/tests/examplefiles/example.hlsl @@ -155,3 +155,14 @@ void main( o_rgb = diffuseColor * diffuseLight; } + +[domain("quad")] +void ds( + in float edgeFactors[4] : SV_TessFactor, + in float insideFactors[2] : SV_InsideTessFactor, + in OutputPatch inp, + in float2 uv : SV_DomainLocation, + out float4 o_pos : SV_Position) +{ + o_pos = lerp(lerp(inp[0].pos, inp[1].pos, uv.x), lerp(inp[2].pos, inp[3].pos, uv.x), uv.y); +} -- cgit v1.2.1 From 0fa23bf835caf6dc01ddb7fde63e01113a7b10af Mon Sep 17 00:00:00 2001 From: Zhenyi Zhou Date: Sun, 1 Jan 2017 19:59:11 +0800 Subject: Fix Perl5 lexer for namespaces/modules. Also see https://github.com/EntropyOrg/p5-Devel-IPerl/issues/25 --- tests/test_perllexer.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_perllexer.py b/tests/test_perllexer.py index 26b2d0a7..90741397 100644 --- a/tests/test_perllexer.py +++ b/tests/test_perllexer.py @@ -10,7 +10,7 @@ import time import unittest -from pygments.token import String +from pygments.token import Keyword, Name, String, Text from pygments.lexers.perl import PerlLexer @@ -135,3 +135,23 @@ class RunawayRegexTest(unittest.TestCase): def test_substitution_with_parenthesis(self): self.assert_single_token(r's(aaa)', String.Regex) self.assert_fast_tokenization('s(' + '\\'*999) + + ### Namespaces/modules + + def test_package_statement(self): + self.assert_tokens(['package', ' ', 'Foo'], [Keyword, Text, Name.Namespace]) + self.assert_tokens(['package', ' ', 'Foo::Bar'], [Keyword, Text, Name.Namespace]) + + def test_use_statement(self): + self.assert_tokens(['use', ' ', 'Foo'], [Keyword, Text, Name.Namespace]) + self.assert_tokens(['use', ' ', 'Foo::Bar'], [Keyword, Text, Name.Namespace]) + + def test_no_statement(self): + self.assert_tokens(['no', ' ', 'Foo'], [Keyword, Text, Name.Namespace]) + self.assert_tokens(['no', ' ', 'Foo::Bar'], [Keyword, Text, Name.Namespace]) + + def test_require_statement(self): + self.assert_tokens(['require', ' ', 'Foo'], [Keyword, Text, Name.Namespace]) + self.assert_tokens(['require', ' ', 'Foo::Bar'], [Keyword, Text, Name.Namespace]) + self.assert_tokens(['require', ' ', '"Foo/Bar.pm"'], [Keyword, Text, String]) + -- cgit v1.2.1 From 6af1485becae0a9847c1f49e7dd0e6040a412c9c Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 22 Jan 2017 18:35:50 +0100 Subject: modeline: work for the first N lines and add a test to keep it that way --- tests/test_modeline.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/test_modeline.py (limited to 'tests') diff --git a/tests/test_modeline.py b/tests/test_modeline.py new file mode 100644 index 00000000..d3a0c915 --- /dev/null +++ b/tests/test_modeline.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" + Tests for the vim modeline feature + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from __future__ import print_function + +from pygments import modeline + + +def test_lexer_classes(): + def verify(buf): + assert modeline.get_filetype_from_buffer(buf) == 'python' + + for buf in [ + 'vi: ft=python' + '\n' * 8, + 'vi: ft=python' + '\n' * 8, + '\n\n\n\nvi=8: syntax=python' + '\n' * 8, + '\n' * 8 + 'ex: filetype=python', + '\n' * 8 + 'vim: some,other,syn=python\n\n\n\n' + ]: + yield verify, buf -- cgit v1.2.1 From c77c9c90964b8b457bc831f5aa0524f3de8f1ca8 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 22 Jan 2017 18:38:11 +0100 Subject: Copyright update. --- tests/run.py | 2 +- tests/string_asserts.py | 2 +- tests/test_basic_api.py | 2 +- tests/test_bibtex.py | 2 +- tests/test_cfm.py | 2 +- tests/test_clexer.py | 2 +- tests/test_cmdline.py | 2 +- tests/test_examplefiles.py | 2 +- tests/test_html_formatter.py | 2 +- tests/test_inherit.py | 2 +- tests/test_irc_formatter.py | 2 +- tests/test_java.py | 2 +- tests/test_javascript.py | 2 +- tests/test_julia.py | 2 +- tests/test_latex_formatter.py | 2 +- tests/test_lexers_other.py | 2 +- tests/test_modeline.py | 2 +- tests/test_objectiveclexer.py | 2 +- tests/test_perllexer.py | 2 +- tests/test_php.py | 2 +- tests/test_praat.py | 2 +- tests/test_properties.py | 2 +- tests/test_python.py | 2 +- tests/test_qbasiclexer.py | 2 +- tests/test_regexlexer.py | 2 +- tests/test_regexopt.py | 2 +- tests/test_rtf_formatter.py | 2 +- tests/test_ruby.py | 2 +- tests/test_shell.py | 2 +- tests/test_smarty.py | 2 +- tests/test_string_asserts.py | 2 +- tests/test_terminal_formatter.py | 2 +- tests/test_textfmts.py | 2 +- tests/test_token.py | 2 +- tests/test_unistring.py | 2 +- tests/test_using_api.py | 2 +- tests/test_util.py | 2 +- 37 files changed, 37 insertions(+), 37 deletions(-) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index 8167b911..07665b2a 100644 --- a/tests/run.py +++ b/tests/run.py @@ -8,7 +8,7 @@ python run.py [testfile ...] - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/string_asserts.py b/tests/string_asserts.py index 11f5c7f0..05e95e6a 100644 --- a/tests/string_asserts.py +++ b/tests/string_asserts.py @@ -3,7 +3,7 @@ Pygments string assert utility ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 03a452d7..ac3b4a51 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -3,7 +3,7 @@ Pygments basic API tests ~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_bibtex.py b/tests/test_bibtex.py index d007766d..5ad92db4 100644 --- a/tests/test_bibtex.py +++ b/tests/test_bibtex.py @@ -3,7 +3,7 @@ BibTeX Test ~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_cfm.py b/tests/test_cfm.py index 2585489a..0ff1b167 100644 --- a/tests/test_cfm.py +++ b/tests/test_cfm.py @@ -3,7 +3,7 @@ Basic ColdfusionHtmlLexer Test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_clexer.py b/tests/test_clexer.py index fd7f58fc..5095b797 100644 --- a/tests/test_clexer.py +++ b/tests/test_clexer.py @@ -3,7 +3,7 @@ Basic CLexer Test ~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 5883fb5c..a37fb498 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -3,7 +3,7 @@ Command line test ~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_examplefiles.py b/tests/test_examplefiles.py index 28037a55..2fae1125 100644 --- a/tests/test_examplefiles.py +++ b/tests/test_examplefiles.py @@ -3,7 +3,7 @@ Pygments tests with example files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py index 596d9fbc..79990edd 100644 --- a/tests/test_html_formatter.py +++ b/tests/test_html_formatter.py @@ -3,7 +3,7 @@ Pygments HTML formatter tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_inherit.py b/tests/test_inherit.py index 34033a08..5da57dd9 100644 --- a/tests/test_inherit.py +++ b/tests/test_inherit.py @@ -3,7 +3,7 @@ Tests for inheritance in RegexLexer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_irc_formatter.py b/tests/test_irc_formatter.py index 16a8fd30..3b34f0bc 100644 --- a/tests/test_irc_formatter.py +++ b/tests/test_irc_formatter.py @@ -3,7 +3,7 @@ Pygments IRC formatter tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_java.py b/tests/test_java.py index f4096647..6e5e8992 100644 --- a/tests/test_java.py +++ b/tests/test_java.py @@ -3,7 +3,7 @@ Basic JavaLexer Test ~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_javascript.py b/tests/test_javascript.py index 59890659..21dff7c4 100644 --- a/tests/test_javascript.py +++ b/tests/test_javascript.py @@ -3,7 +3,7 @@ Javascript tests ~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_julia.py b/tests/test_julia.py index 08c420d3..ed46f27e 100644 --- a/tests/test_julia.py +++ b/tests/test_julia.py @@ -3,7 +3,7 @@ Julia Tests ~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_latex_formatter.py b/tests/test_latex_formatter.py index fbcb6cde..ebed7964 100644 --- a/tests/test_latex_formatter.py +++ b/tests/test_latex_formatter.py @@ -3,7 +3,7 @@ Pygments LaTeX formatter tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_lexers_other.py b/tests/test_lexers_other.py index 90d05ef8..3716fb72 100644 --- a/tests/test_lexers_other.py +++ b/tests/test_lexers_other.py @@ -3,7 +3,7 @@ Tests for other lexers ~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import glob diff --git a/tests/test_modeline.py b/tests/test_modeline.py index d3a0c915..efe038df 100644 --- a/tests/test_modeline.py +++ b/tests/test_modeline.py @@ -3,7 +3,7 @@ Tests for the vim modeline feature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_objectiveclexer.py b/tests/test_objectiveclexer.py index 90bd680f..aee7db66 100644 --- a/tests/test_objectiveclexer.py +++ b/tests/test_objectiveclexer.py @@ -3,7 +3,7 @@ Basic CLexer Test ~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_perllexer.py b/tests/test_perllexer.py index 26b2d0a7..2fcaae7e 100644 --- a/tests/test_perllexer.py +++ b/tests/test_perllexer.py @@ -3,7 +3,7 @@ Pygments regex lexer tests ~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_php.py b/tests/test_php.py index 050ca70d..b4117381 100644 --- a/tests/test_php.py +++ b/tests/test_php.py @@ -3,7 +3,7 @@ PHP Tests ~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_praat.py b/tests/test_praat.py index 471d5e2c..1ca97d1e 100644 --- a/tests/test_praat.py +++ b/tests/test_praat.py @@ -3,7 +3,7 @@ Praat lexer tests ~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_properties.py b/tests/test_properties.py index 333f3d7a..562778ba 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -3,7 +3,7 @@ Properties Tests ~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_python.py b/tests/test_python.py index f5784cb1..e99687a6 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -3,7 +3,7 @@ Python Tests ~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_qbasiclexer.py b/tests/test_qbasiclexer.py index 8b790cee..0ea221a1 100644 --- a/tests/test_qbasiclexer.py +++ b/tests/test_qbasiclexer.py @@ -3,7 +3,7 @@ Tests for QBasic ~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_regexlexer.py b/tests/test_regexlexer.py index eb25be61..d919a950 100644 --- a/tests/test_regexlexer.py +++ b/tests/test_regexlexer.py @@ -3,7 +3,7 @@ Pygments regex lexer tests ~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_regexopt.py b/tests/test_regexopt.py index 6322c735..5cfb62a3 100644 --- a/tests/test_regexopt.py +++ b/tests/test_regexopt.py @@ -3,7 +3,7 @@ Tests for pygments.regexopt ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_rtf_formatter.py b/tests/test_rtf_formatter.py index 25784743..756c03a9 100644 --- a/tests/test_rtf_formatter.py +++ b/tests/test_rtf_formatter.py @@ -3,7 +3,7 @@ Pygments RTF formatter tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_ruby.py b/tests/test_ruby.py index ab210bad..b7d4110a 100644 --- a/tests/test_ruby.py +++ b/tests/test_ruby.py @@ -3,7 +3,7 @@ Basic RubyLexer Test ~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_shell.py b/tests/test_shell.py index 6faac9fd..e283793e 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -3,7 +3,7 @@ Basic Shell Tests ~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_smarty.py b/tests/test_smarty.py index 450e4e6b..e1e079d9 100644 --- a/tests/test_smarty.py +++ b/tests/test_smarty.py @@ -3,7 +3,7 @@ Basic SmartyLexer Test ~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_string_asserts.py b/tests/test_string_asserts.py index ba7b37fa..5e9e5617 100644 --- a/tests/test_string_asserts.py +++ b/tests/test_string_asserts.py @@ -3,7 +3,7 @@ Pygments string assert utility tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_terminal_formatter.py b/tests/test_terminal_formatter.py index cb5c6c44..ee0ac380 100644 --- a/tests/test_terminal_formatter.py +++ b/tests/test_terminal_formatter.py @@ -3,7 +3,7 @@ Pygments terminal formatter tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_textfmts.py b/tests/test_textfmts.py index d355ab68..453dd61f 100644 --- a/tests/test_textfmts.py +++ b/tests/test_textfmts.py @@ -3,7 +3,7 @@ Basic Tests for textfmts ~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_token.py b/tests/test_token.py index 0c6b02bf..94522373 100644 --- a/tests/test_token.py +++ b/tests/test_token.py @@ -3,7 +3,7 @@ Test suite for the token module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_unistring.py b/tests/test_unistring.py index a414347c..c56b68c7 100644 --- a/tests/test_unistring.py +++ b/tests/test_unistring.py @@ -3,7 +3,7 @@ Test suite for the unistring module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_using_api.py b/tests/test_using_api.py index 16d865e6..7517ce7d 100644 --- a/tests/test_using_api.py +++ b/tests/test_using_api.py @@ -3,7 +3,7 @@ Pygments tests for using() ~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/tests/test_util.py b/tests/test_util.py index 720b384a..cdb58b3f 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -3,7 +3,7 @@ Test suite for the util module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -- cgit v1.2.1 From 1f75c51afdbe281e0044ca5c5369e14fc5e0e8e1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 22 Jan 2017 19:57:19 +0100 Subject: -x functionality updates, Python 3 compatibility fix --- tests/support/empty.py | 1 + tests/support/html_formatter.py | 5 +++-- tests/support/python_lexer.py | 11 ++++------- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/support/empty.py b/tests/support/empty.py index e69de29b..40a96afc 100644 --- a/tests/support/empty.py +++ b/tests/support/empty.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/tests/support/html_formatter.py b/tests/support/html_formatter.py index 7f5581ed..169cd4af 100644 --- a/tests/support/html_formatter.py +++ b/tests/support/html_formatter.py @@ -1,5 +1,6 @@ - +# -*- coding: utf-8 -*- from pygments.formatters import HtmlFormatter + class HtmlFormatterWrapper(HtmlFormatter): - name = 'HtmlWrapper' + name = 'HtmlWrapper' diff --git a/tests/support/python_lexer.py b/tests/support/python_lexer.py index ad34d31b..565ee674 100644 --- a/tests/support/python_lexer.py +++ b/tests/support/python_lexer.py @@ -1,15 +1,12 @@ # -*- coding: utf-8 -*- -""" - pygments.lexers.python (as CustomLexer) - ~~~~~~~~~~~~~~~~~~~~~~ - - For test_cmdline.py -""" +# pygments.lexers.python (as CustomLexer) for test_cmdline.py from pygments.lexers import PythonLexer + class CustomLexer(PythonLexer): name = 'PythonLexerWrapper' + class LexerWrapper(CustomLexer): - name="PythonLexerWrapperWrapper" + name = 'PythonLexerWrapperWrapper' -- cgit v1.2.1 From b527da9f8638a77fec2c5b6de395631736658b6f Mon Sep 17 00:00:00 2001 From: Nathan Whetsell Date: Fri, 27 Jan 2017 17:25:37 -0500 Subject: Update lexers --- tests/examplefiles/test.csd | 258 ++----------------------------------- tests/examplefiles/test.orc | 300 ++++++++++---------------------------------- tests/examplefiles/test.sco | 32 +++-- 3 files changed, 98 insertions(+), 492 deletions(-) (limited to 'tests') diff --git a/tests/examplefiles/test.csd b/tests/examplefiles/test.csd index 3f43bede..6512d99e 100644 --- a/tests/examplefiles/test.csd +++ b/tests/examplefiles/test.csd @@ -1,254 +1,18 @@ +/* + * comment + */ +; comment +// comment +/ -// This is a Csound orchestra file for testing a Pygments -// lexer. Csound single-line comments can be preceded by a pair of forward -// slashes... -; ...or a semicolon. - -/* Block comments begin with /* and end with */ - -// Orchestras begin with a header of audio parameters. -nchnls = 1 -nchnls_i = 1 -sr = 44100 0dbfs = 1 -ksmps = 10 -A4 = 440 - -// The control rate kr = sr / ksmps can be omitted when the number of audio -// samples in a control period (ksmps) is set, but kr may appear in older -// orchestras. -kr = 4410 - -// Orchestras contain instruments. These begin with the keyword instr followed -// by a comma-separated list of numbers or names of the instrument. Instruments -// end at the endin keyword and cannot be nested. -instr 1, N_a_M_e_, +Name - // Instruments contain statements. Here is a typical statement: - aSignal oscil 0dbfs, 440, 1 - // Statements are terminated with a newline (possibly preceded by a comment). - // To write a statement on several lines, precede the newline with a - // backslash. - prints \ - "hello, world\n";comment - - // Csound 6 introduced function syntax for opcodes with one or zero outputs. - // The oscil statement above is the same as - aSignal = oscil(0dbfs, 440, 1) - - // Instruments can contain control structures. - kNote = p3 - if (kNote == 0) then - kFrequency = 220 - elseif kNote == 1 then // Parentheses around binary expressions are optional. - kFrequency = 440 - endif - - // Csound 6 introduced looping structures. - iIndex = 0 - while iIndex < 5 do - print iIndex - iIndex += 1 - od - iIndex = 0 - until iIndex >= 5 do - print iIndex - iIndex += 1 - enduntil - // Both kinds of loops can be terminated by either od or enduntil. - - // Single-line strings are enclosed in double-quotes. - prints "string\\\r\n\t\"" - // Multi-line strings are enclosed in pairs of curly braces. - prints {{ - hello, - - world - }} - - // Instruments often end with a statement containing an output opcode. - outc aSignal -endin - -// Orchestras can also contain user-defined opcodes (UDOs). Here is an -// oscillator with one audio-rate output and two control-rate inputs: -opcode anOscillator, a, kk - kAmplitude, kFrequency xin - aSignal vco2 kAmplitude, kFrequency - xout aSignal -endop -instr TestOscillator - outc(anOscillator(0dbfs, 110)) -endin - -// You can execute Python and -// Lua in Csound. -pyruni {{ -import random - -pool = [(1 + i / 10.0) ** 1.2 for i in range(100)] - -def get_number_from_pool(n, p): - if random.random() < p: - i = int(random.random() * len(pool)) - pool[i] = n - return random.choice(pool) -}} - -// The Csound preprocessor supports conditional compilation and including files. -#ifdef DEBUG -#undef DEBUG -#include "filename.orc" -#endif - -// The preprocessor also supports object- and function-like macros. This is an -// object-like macro that defines a number: -#define A_HZ #440# - -// This is a function-like macro: -#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# - -// Bodies of macros are enclosed in # and can contain newlines. The arguments of -// function-like macros are separated by single-quotes. Uses of macros are -// prefixed with a dollar sign. -instr TestMacro - aSignal $OSCIL_MACRO(1' $A_HZ' 1) - // Not unlike PHP, macros expand in double-quoted strings. - prints "The frequency of the oscillator is $A_HZ Hz.\n" - out aSignal -endin - -// Here are other things to note about Csound. - -// There are two bitwise NOT operators, ~ and ¬ (U+00AC). The latter is common -// on keyboards in the United Kingdom -// . -instr TestBitwiseNOT - print ~42 - print ¬42 -endin - -// Csound uses # for bitwise XOR, which the Csound manual calls bitwise -// non-equivalence . -instr TestBitwiseXOR - print 0 # 0 - print 0 # 1 - print 1 # 0 - print 1 # 1 -endin - -// Loops and if-then statements are relatively recent additions to Csound. There -// are many flow-control opcodes that involve goto and labels. -instr TestGoto - // This... - if p3 > 0 goto if_label - goto else_label -if_label: - prints "if branch\n" - goto endif_label -else_label: - prints "else branch\n" -endif_label: - - // ...is the same as this. - if p3 > 0 then - prints "if branch\n" - else - prints "else branch\n" - endif - - // This... - iIndex = 0 -loop_label: - print iIndex - iIndex += 1 - if iIndex < 10 goto loop_label - - // ...is the same as this... - iIndex = 0 -loop_lt_label: - print iIndex - loop_lt iIndex, 1, 10, loop_lt_label - - // ...and this. - iIndex = 0 - while iIndex < 10 do - print iIndex - iIndex += 1 - od -endin - -// The prints and printks opcodes, arguably the primary methods of logging -// output, treat certain sequences of characters different from printf in C. -instr TestPrints - // ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character - // (U+005E). ^^ prints a CIRCUMFLEX ACCENT. - prints "^^\n" - // ~ prints an ESCAPE character (U+001B) followed by a [, not a TILDE - // character (U+007E). ~~ prints a TILDE. - prints "~~\n" - // \A, \B, \N, \R, and \T correspond to the escaped lowercase characters (that - // is, BELL (U+0007), BACKSPACE (U+0008), new line (U+000A), CARRIAGE RETURN - // (U+000D), and tab (U+0009)). - prints "\T\R\N" - // %n, %r, and %t are the same as \n, \r, and \t, as are %N, %R, and %T. - prints "%t%r%n" - // %! prints a semicolon. This is a hold-over from old versions of Csound that - // allowed comments to begin in strings. - prints "; %!\n" -endin - -// The arguments of function-like macros can be separated by # instead of '. -// These two lines define the same macro. -#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# -#define OSCIL_MACRO(VOLUME# FREQUENCY# TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# - -// Uses of macros can optionally be suffixed with a period. -instr TestMacroPeriodSuffix - aSignal $OSCIL_MACRO.(1' $A_HZ' 1) - prints "The frequency of the oscillator is $A_HZ.Hz.\n" - out aSignal -endin - -// Csound has @ and @@ operator-like macros that, when followed by a literal -// non-negative integer, expand to the next power of 2 and the next power of 2 -// plus 1 : -// @x = 2^(ceil(log2(x + 1))), x >= 0 -// @@0 = 2 -// @@x = 2^(ceil(log2(x))) + 1, x > 0 -instr TestAt - prints "%d %2d %2d\n", 0, @0, @@0 - prints "%d %2d %2d\n", 1, @1, @@1 - prints "%d %2d %2d\n", 2, @2, @@2 - prints "%d %2d %2d\n", 3, @3, @@3 - prints "%d %2d %2d\n", 4, @4, @@4 - prints "%d %2d %2d\n", 5, @5, @@5 - prints "%d %2d %2d\n", 6, @6, @@6 - prints "%d %2d %2d\n", 7, @7, @@7 - prints "%d %2d %2d\n", 8, @8, @@8 - prints "%d %2d %2d\n", 9, @9, @@9 -endin - -// Including newlines in macros can lead to confusing code, but it tests the -// lexer. -instr MacroAbuse - if 1 == 1 then - prints "on\n" -#define FOO# -BAR -#endif // This ends the if statement. It is not a preprocessor directive. -endin +prints "hello, world\n" -f 1 0 16384 10 1 -i "N_a_M_e_" 0 2 -i "TestOscillator" 2 2 -i "TestBitwiseNOT" 0 1 -i "TestBitwiseXOR" 0 1 -i "TestGoto" 0 1 -i "TestMacroPeriodSuffix" 0 1 -i "TestAt" 0 1 -i "MacroAbuse" 0 1 -e +i 1 0 0 + + + diff --git a/tests/examplefiles/test.orc b/tests/examplefiles/test.orc index 36e35b34..59bf7f66 100644 --- a/tests/examplefiles/test.orc +++ b/tests/examplefiles/test.orc @@ -1,251 +1,81 @@ -// This is a Csound orchestra file for testing a Pygments -// lexer. Csound single-line comments can be preceded by a pair of forward -// slashes... -; ...or a semicolon. - -/* Block comments begin with /* and end with */ - -// Orchestras begin with a header of audio parameters. -nchnls = 1 -nchnls_i = 1 -sr = 44100 -0dbfs = 1 -ksmps = 10 -A4 = 440 - -// The control rate kr = sr / ksmps can be omitted when the number of audio -// samples in a control period (ksmps) is set, but kr may appear in older -// orchestras. -kr = 4410 - -// Orchestras contain instruments. These begin with the keyword instr followed -// by a comma-separated list of numbers or names of the instrument. Instruments -// end at the endin keyword and cannot be nested. -instr 1, N_a_M_e_, +Name - // Instruments contain statements. Here is a typical statement: - aSignal oscil 0dbfs, 440, 1 - // Statements are terminated with a newline (possibly preceded by a comment). - // To write a statement on several lines, precede the newline with a - // backslash. - prints \ - "hello, world\n";comment - - // Csound 6 introduced function syntax for opcodes with one or zero outputs. - // The oscil statement above is the same as - aSignal = oscil(0dbfs, 440, 1) - - // Instruments can contain control structures. - kNote = p3 - if (kNote == 0) then - kFrequency = 220 - elseif kNote == 1 then // Parentheses around binary expressions are optional. - kFrequency = 440 - endif - - // Csound 6 introduced looping structures. - iIndex = 0 - while iIndex < 5 do - print iIndex - iIndex += 1 - od - iIndex = 0 - until iIndex >= 5 do - print iIndex - iIndex += 1 - enduntil - // Both kinds of loops can be terminated by either od or enduntil. - - // Single-line strings are enclosed in double-quotes. - prints "string\\\r\n\t\"" - // Multi-line strings are enclosed in pairs of curly braces. - prints {{ - hello, - - world - }} - - // Instruments often end with a statement containing an output opcode. - outc aSignal +/* + * comment + */ +; comment +// comment + +instr/**/1,/**/N_a_M_e_,/**/+Name/**/// + iDuration = p3 + outc:a(aSignal) endin -// Orchestras can also contain user-defined opcodes (UDOs). Here is an -// oscillator with one audio-rate output and two control-rate inputs: -opcode anOscillator, a, kk - kAmplitude, kFrequency xin - aSignal vco2 kAmplitude, kFrequency - xout aSignal +opcode/**/aUDO,/**/0,/**/aik// + aUDO endop -instr TestOscillator - outc(anOscillator(0dbfs, 110)) -endin -// You can execute Python and -// Lua in Csound. -pyruni {{ -import random +123 0123456789 +0xabcdef0123456789 0XABCDEF +1e2 3e+4 5e-6 7E8 9E+0 1E-2 3. 4.56 .789 -pool = [(1 + i / 10.0) ** 1.2 for i in range(100)] +"characters$MACRO." +"\\\a\b\n\r\t\012\345\67\"" -def get_number_from_pool(n, p): - if random.random() < p: - i = int(random.random() * len(pool)) - pool[i] = n - return random.choice(pool) +{{ +characters$MACRO. }} +{{\\\a\b\n\r\t\"\012\345\67}} -// The Csound preprocessor supports conditional compilation and including files. -#ifdef DEBUG -#undef DEBUG -#include "filename.orc" -#endif ++ - ~ ¬ ! * / ^ % << >> < > <= >= == != & # | && || ? : += -= *= /= -// The preprocessor also supports object- and function-like macros. This is an -// object-like macro that defines a number: -#define A_HZ #440# - -// This is a function-like macro: -#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# - -// Bodies of macros are enclosed in # and can contain newlines. The arguments of -// function-like macros are separated by single-quotes. Uses of macros are -// prefixed with a dollar sign. -instr TestMacro - aSignal $OSCIL_MACRO(1' $A_HZ' 1) - // Not unlike PHP, macros expand in double-quoted strings. - prints "The frequency of the oscillator is $A_HZ Hz.\n" - out aSignal -endin +0dbfs A4 kr ksmps nchnls nchnls_i sr -// Here are other things to note about Csound. - -// There are two bitwise NOT operators, ~ and ¬ (U+00AC). The latter is common -// on keyboards in the United Kingdom -// . -instr TestBitwiseNOT - print ~42 - print ¬42 -endin - -// Csound uses # for bitwise XOR, which the Csound manual calls bitwise -// non-equivalence . -instr TestBitwiseXOR - print 0 # 0 - print 0 # 1 - print 1 # 0 - print 1 # 1 -endin - -// Loops and if-then statements are relatively recent additions to Csound. There -// are many flow-control opcodes that involve goto and labels. -instr TestGoto - // This... - if p3 > 0 goto if_label - goto else_label -if_label: - prints "if branch\n" - goto endif_label -else_label: - prints "else branch\n" -endif_label: - - // ...is the same as this. - if p3 > 0 then - prints "if branch\n" - else - prints "else branch\n" - endif - - // This... - iIndex = 0 -loop_label: - print iIndex - iIndex += 1 - if iIndex < 10 goto loop_label - - // ...is the same as this... - iIndex = 0 -loop_lt_label: - print iIndex - loop_lt iIndex, 1, 10, loop_lt_label - - // ...and this. - iIndex = 0 - while iIndex < 10 do - print iIndex - iIndex += 1 - od -endin +do else elseif endif enduntil fi if ithen kthen od then until while +return rireturn -// The prints and printks opcodes, arguably the primary methods of logging -// output, treat certain sequences of characters different from printf in C. -instr TestPrints - // ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character - // (U+005E). ^^ prints a CIRCUMFLEX ACCENT. - prints "^^\n" - // ~ prints an ESCAPE character (U+001B) followed by a [, not a TILDE - // character (U+007E). ~~ prints a TILDE. - prints "~~\n" - // \A, \B, \N, \R, and \T correspond to the escaped lowercase characters (that - // is, BELL (U+0007), BACKSPACE (U+0008), new line (U+000A), CARRIAGE RETURN - // (U+000D), and tab (U+0009)). - prints "\T\R\N" - // %n, %r, and %t are the same as \n, \r, and \t, as are %N, %R, and %T. - prints "%t%r%n" - // %! prints a semicolon. This is a hold-over from old versions of Csound that - // allowed comments to begin in strings. - prints "; %!\n" -endin +aLabel: + label2: -// The arguments of function-like macros can be separated by # instead of '. -// These two lines define the same macro. -#define OSCIL_MACRO(VOLUME' FREQUENCY' TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# -#define OSCIL_MACRO(VOLUME# FREQUENCY# TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +goto aLabel +reinit aLabel +cggoto 1==0, aLabel +timout 0, 0, aLabel +loop_ge 0, 0, 0, aLabel -// Uses of macros can optionally be suffixed with a period. -instr TestMacroPeriodSuffix - aSignal $OSCIL_MACRO.(1' $A_HZ' 1) - prints "The frequency of the oscillator is $A_HZ.Hz.\n" - out aSignal -endin +prints "%! %% %n%N %r%R %t%T \\a\\A \\b\\B \\n\\N \\r\\R \\t\\T" +prints Soutput -// Csound has @ and @@ operator-like macros that, when followed by a literal -// non-negative integer, expand to the next power of 2 and the next power of 2 -// plus 1 : -// @x = 2^(ceil(log2(x + 1))), x >= 0 -// @@0 = 2 -// @@x = 2^(ceil(log2(x))) + 1, x > 0 -instr TestAt - prints "%d %2d %2d\n", 0, @0, @@0 - prints "%d %2d %2d\n", 1, @1, @@1 - prints "%d %2d %2d\n", 2, @2, @@2 - prints "%d %2d %2d\n", 3, @3, @@3 - prints "%d %2d %2d\n", 4, @4, @@4 - prints "%d %2d %2d\n", 5, @5, @@5 - prints "%d %2d %2d\n", 6, @6, @@6 - prints "%d %2d %2d\n", 7, @7, @@7 - prints "%d %2d %2d\n", 8, @8, @@8 - prints "%d %2d %2d\n", 9, @9, @@9 -endin +readscore {{ +i 1 0 0 +}} +pyrun {{ +# Python +}} +lua_exec {{ +-- Lua +}} -// Including newlines in macros can lead to confusing code, but it tests the -// lexer. -instr MacroAbuse - if 1 == 1 then - prints "on\n" -#define FOO# -BAR -#endif // This ends the if statement. It is not a preprocessor directive. -endin +#include/**/"file.udo" +#include/**/|file.udo| -scoreline_i {{ -f 1 0 16384 10 1 -i "N_a_M_e_" 0 2 -i "TestOscillator" 2 2 -i "TestBitwiseNOT" 0 1 -i "TestBitwiseXOR" 0 1 -i "TestGoto" 0 1 -i "TestMacroPeriodSuffix" 0 1 -i "TestAt" 0 1 -i "MacroAbuse" 0 1 -e -}} +#ifdef MACRO +#else +#ifndef MACRO +#endif +#undef MACRO + +# define MACRO#macro_body# +#define/**/ +MACRO/**/ +#\#macro +body\## + +#define MACRO(ARG1#ARG2) #macro_body# +#define/**/ +MACRO(ARG1'ARG2'ARG3)/**/ +#\#macro +body\## + +$MACRO $MACRO. +$MACRO(x) +@0 +@@ 1 diff --git a/tests/examplefiles/test.sco b/tests/examplefiles/test.sco index 07818133..e855e563 100644 --- a/tests/examplefiles/test.sco +++ b/tests/examplefiles/test.sco @@ -1,10 +1,22 @@ -f 1 0 16384 10 1 -i "N_a_M_e_" 0 2 -i "TestOscillator" 2 2 -i "TestBitwiseNOT" 0 1 -i "TestBitwiseXOR" 0 1 -i "TestGoto" 0 1 -i "TestMacroPeriodSuffix" 0 1 -i "TestAt" 0 1 -i "MacroAbuse" 0 1 -e +/* + * comment + */ +; comment +// comment +a b C e f i q s t v x y +z +np0 nP1 Np2 NP3 +m/**/label; +n label +123 0123456789 +0xabcdef0123456789 0XABCDEF +1e2 3e+4 5e-6 7E8 9E+0 1E-2 3. 4.56 .789 +"characters$MACRO." +{ 1 I + { 2 J + { 3 K + $I $J $K + } + } +} +#include "score.sco" -- cgit v1.2.1 From 1ce702fcde424a8cb16179d0d7a9e32c20636003 Mon Sep 17 00:00:00 2001 From: Nathan Whetsell Date: Sat, 28 Jan 2017 12:15:10 -0500 Subject: Add Csound lexer tests --- tests/test_csound.py | 471 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 471 insertions(+) create mode 100644 tests/test_csound.py (limited to 'tests') diff --git a/tests/test_csound.py b/tests/test_csound.py new file mode 100644 index 00000000..610dec1a --- /dev/null +++ b/tests/test_csound.py @@ -0,0 +1,471 @@ +# -*- coding: utf-8 -*- +""" + Csound lexer tests + ~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest +from textwrap import dedent + +from pygments.token import Comment, Error, Keyword, Name, Number, Operator, Punctuation, \ + String, Text +from pygments.lexers import CsoundOrchestraLexer + + +class CsoundOrchestraTest(unittest.TestCase): + + def setUp(self): + self.lexer = CsoundOrchestraLexer() + self.maxDiff = None + + def testComments(self): + fragment = dedent('''\ + /* + * comment + */ + ; comment + // comment + ''') + tokens = [ + (Comment.Multiline, u'/*\n * comment\n */'), + (Text, u'\n'), + (Comment.Single, u'; comment'), + (Text, u'\n'), + (Comment.Single, u'// comment'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testInstrumentBlocks(self): + fragment = dedent('''\ + instr/**/1,/**/N_a_M_e_,/**/+Name/**/// + iDuration = p3 + outc:a(aSignal) + endin + ''') + tokens = [ + (Keyword.Declaration, u'instr'), + (Comment.Multiline, u'/**/'), + (Name.Function, u'1'), + (Punctuation, u','), + (Comment.Multiline, u'/**/'), + (Name.Function, u'N_a_M_e_'), + (Punctuation, u','), + (Comment.Multiline, u'/**/'), + (Punctuation, u'+'), + (Name.Function, u'Name'), + (Comment.Multiline, u'/**/'), + (Comment.Single, u'//'), + (Text, u'\n'), + (Text, u' '), + (Keyword.Type, u'i'), + (Name, u'Duration'), + (Text, u' '), + (Operator, u'='), + (Text, u' '), + (Name.Variable.Instance, u'p3'), + (Text, u'\n'), + (Text, u' '), + (Name.Builtin, u'outc'), + (Punctuation, u':'), + (Keyword.Type, u'a'), + (Punctuation, u'('), + (Keyword.Type, u'a'), + (Name, u'Signal'), + (Punctuation, u')'), + (Text, u'\n'), + (Keyword.Declaration, u'endin'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testUserDefinedOpcodes(self): + fragment = dedent('''\ + opcode/**/aUDO,/**/0,/**/aik// + aUDO + endop + ''') + tokens = [ + (Keyword.Declaration, u'opcode'), + (Comment.Multiline, u'/**/'), + (Name.Function, u'aUDO'), + (Punctuation, u','), + (Comment.Multiline, u'/**/'), + (Keyword.Type, u'0'), + (Punctuation, u','), + (Comment.Multiline, u'/**/'), + (Keyword.Type, u'aik'), + (Comment.Single, u'//'), + (Text, u'\n'), + (Text, u' '), + (Name.Function, u'aUDO'), + (Text, u'\n'), + (Keyword.Declaration, u'endop'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testNumbers(self): + fragment = '123 0123456789' + tokens = [ + (Number.Integer, u'123'), + (Text, u' '), + (Number.Integer, u'0123456789'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + fragment = '0xabcdef0123456789 0XABCDEF' + tokens = [ + (Number.Hex, u'0xabcdef0123456789'), + (Text, u' '), + (Number.Hex, u'0XABCDEF'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + fragments = ['1e2', '3e+4', '5e-6', '7E8', '9E+0', '1E-2', '3.', '4.56', '.789'] + for fragment in fragments: + tokens = [ + (Number.Float, fragment), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testQuotedStrings(self): + fragment = '"characters$MACRO."' + tokens = [ + (String, u'"'), + (String, u'characters'), + (Comment.Preproc, u'$MACRO.'), + (String, u'"'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testBracedStrings(self): + fragment = dedent('''\ + {{ + characters$MACRO. + }} + ''') + tokens = [ + (String, u'{{'), + (String, u'\ncharacters$MACRO.\n'), + (String, u'}}'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testEscapeSequences(self): + for character in ['\\', 'a', 'b', 'n', 'r', 't', '"', '012', '345', '67']: + escapedCharacter = '\\' + character + fragment = '"' + escapedCharacter + '"' + tokens = [ + (String, u'"'), + (String.Escape, escapedCharacter), + (String, u'"'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + fragment = '{{' + escapedCharacter + '}}' + tokens = [ + (String, u'{{'), + (String.Escape, escapedCharacter), + (String, u'}}'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testOperators(self): + fragments = ['+', '-', '~', u'¬', '!', '*', '/', '^', '%', '<<', '>>', '<', '>', + '<=', '>=', '==', '!=', '&', '#', '|', '&&', '||', '?', ':', '+=', + '-=', '*=', '/='] + for fragment in fragments: + tokens = [ + (Operator, fragment), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testGlobalValueIdentifiers(self): + for fragment in ['0dbfs', 'A4', 'kr', 'ksmps', 'nchnls', 'nchnls_i', 'sr']: + tokens = [ + (Name.Variable.Global, fragment), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testKeywords(self): + fragments = ['do', 'else', 'elseif', 'endif', 'enduntil', 'fi', 'if', 'ithen', + 'kthen', 'od', 'then', 'until', 'while'] + for fragment in fragments: + tokens = [ + (Keyword, fragment), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + for fragment in ['return', 'rireturn']: + tokens = [ + (Keyword.Pseudo, fragment), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testLabels(self): + fragment = dedent('''\ + aLabel: + label2: + ''') + tokens = [ + (Name.Label, u'aLabel'), + (Punctuation, u':'), + (Text, u'\n'), + (Text, u' '), + (Name.Label, u'label2'), + (Punctuation, u':'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testPrintksAndPrintsEscapeSequences(self): + escapedCharacters = ['%!', '%%', '%n', '%N', '%r', '%R', '%t', '%T', '\\\\a', + '\\\\A', '\\\\b', '\\\\B', '\\\\n', '\\\\N', '\\\\r', + '\\\\R', '\\\\t', '\\\\T'] + for opcode in ['printks', 'prints']: + for escapedCharacter in escapedCharacters: + fragment = opcode + ' "' + escapedCharacter + '"' + tokens = [ + (Name.Builtin, opcode), + (Text, u' '), + (String, u'"'), + (String.Escape, escapedCharacter), + (String, u'"'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testGotoStatements(self): + for keyword in ['goto', 'igoto', 'kgoto']: + fragment = keyword + ' aLabel' + tokens = [ + (Keyword, keyword), + (Text, u' '), + (Name.Label, u'aLabel'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + for opcode in ['reinit', 'rigoto', 'tigoto']: + fragment = opcode + ' aLabel' + tokens = [ + (Keyword.Pseudo, opcode), + (Text, u' '), + (Name.Label, u'aLabel'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + for opcode in ['cggoto', 'cigoto', 'cingoto', 'ckgoto', 'cngoto', 'cnkgoto']: + fragment = opcode + ' 1==0, aLabel' + tokens = [ + (Keyword.Pseudo, opcode), + (Text, u' '), + (Number.Integer, u'1'), + (Operator, u'=='), + (Number.Integer, u'0'), + (Punctuation, u','), + (Text, u' '), + (Name.Label, u'aLabel'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + fragment = 'timout 0, 0, aLabel' + tokens = [ + (Keyword.Pseudo, 'timout'), + (Text, u' '), + (Number.Integer, u'0'), + (Punctuation, u','), + (Text, u' '), + (Number.Integer, u'0'), + (Punctuation, u','), + (Text, u' '), + (Name.Label, u'aLabel'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + for opcode in ['loop_ge', 'loop_gt', 'loop_le', 'loop_lt']: + fragment = opcode + ' 0, 0, 0, aLabel' + tokens = [ + (Keyword.Pseudo, opcode), + (Text, u' '), + (Number.Integer, u'0'), + (Punctuation, u','), + (Text, u' '), + (Number.Integer, u'0'), + (Punctuation, u','), + (Text, u' '), + (Number.Integer, u'0'), + (Punctuation, u','), + (Text, u' '), + (Name.Label, u'aLabel'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testIncludeDirectives(self): + for character in ['"', '|']: + fragment = '#include/**/' + character + 'file.udo' + character + tokens = [ + (Comment.Preproc, u'#include'), + (Comment.Multiline, u'/**/'), + (String, character + u'file.udo' + character), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testObjectLikeMacroDefinitions(self): + fragment = dedent('''\ + # \tdefine MACRO#macro_body# + #define/**/ + MACRO/**/ + #\\#macro + body\\## + ''') + tokens = [ + (Comment.Preproc, u'# \tdefine'), + (Text, u' '), + (Comment.Preproc, u'MACRO'), + (Punctuation, u'#'), + (Comment.Preproc, u'macro_body'), + (Punctuation, u'#'), + (Text, u'\n'), + (Comment.Preproc, u'#define'), + (Comment.Multiline, u'/**/'), + (Text, u'\n'), + (Comment.Preproc, u'MACRO'), + (Comment.Multiline, u'/**/'), + (Text, u'\n'), + (Punctuation, u'#'), + (Comment.Preproc, u'\\#'), + (Comment.Preproc, u'macro\nbody'), + (Comment.Preproc, u'\\#'), + (Punctuation, u'#'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testFunctionLikeMacroDefinitions(self): + fragment = dedent('''\ + #define MACRO(ARG1#ARG2) #macro_body# + #define/**/ + MACRO(ARG1'ARG2' ARG3)/**/ + #\\#macro + body\\## + ''') + tokens = [ + (Comment.Preproc, u'#define'), + (Text, u' '), + (Comment.Preproc, u'MACRO'), + (Punctuation, u'('), + (Comment.Preproc, u'ARG1'), + (Punctuation, u'#'), + (Comment.Preproc, u'ARG2'), + (Punctuation, u')'), + (Text, u' '), + (Punctuation, u'#'), + (Comment.Preproc, u'macro_body'), + (Punctuation, u'#'), + (Text, u'\n'), + (Comment.Preproc, u'#define'), + (Comment.Multiline, u'/**/'), + (Text, u'\n'), + (Comment.Preproc, u'MACRO'), + (Punctuation, u'('), + (Comment.Preproc, u'ARG1'), + (Punctuation, u"'"), + (Comment.Preproc, u'ARG2'), + (Punctuation, u"'"), + (Text, u' '), + (Comment.Preproc, u'ARG3'), + (Punctuation, u')'), + (Comment.Multiline, u'/**/'), + (Text, u'\n'), + (Punctuation, u'#'), + (Comment.Preproc, u'\\#'), + (Comment.Preproc, u'macro\nbody'), + (Comment.Preproc, u'\\#'), + (Punctuation, u'#'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testMacroPreprocessorDirectives(self): + for directive in ['#ifdef', '#ifndef', '#undef']: + fragment = directive + ' MACRO' + tokens = [ + (Comment.Preproc, directive), + (Text, u' '), + (Comment.Preproc, u'MACRO'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testOtherPreprocessorDirectives(self): + fragment = dedent('''\ + #else + #end + #endif + ### + @ \t12345 + @@ \t67890 + ''') + tokens = [ + (Comment.Preproc, u'#else'), + (Text, u'\n'), + (Comment.Preproc, u'#end'), + (Text, u'\n'), + (Comment.Preproc, u'#endif'), + (Text, u'\n'), + (Comment.Preproc, u'###'), + (Text, u'\n'), + (Comment.Preproc, u'@ \t12345'), + (Text, u'\n'), + (Comment.Preproc, u'@@ \t67890'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testFunctionLikeMacros(self): + fragment = '$MACRO.(((x\\))\' "x)\\)x\\))"# {{x\\))x)\\)}})' + tokens = [ + (Comment.Preproc, u'$MACRO.'), + (Punctuation, u'('), + (Comment.Preproc, u'('), + (Comment.Preproc, u'('), + (Comment.Preproc, u'x'), + (Comment.Preproc, u'\\)'), + (Error, u')'), + (Punctuation, u"'"), + (Comment.Preproc, u' '), + (String, u'"'), + (String, u'x'), + (Error, u')'), + (Comment.Preproc, u'\\)'), + (String, u'x'), + (Comment.Preproc, u'\\)'), + (Error, u')'), + (String, u'"'), + (Punctuation, u'#'), + (Comment.Preproc, u' '), + (String, u'{{'), + (String, u'x'), + (Comment.Preproc, u'\\)'), + (Error, u')'), + (String, u'x'), + (Error, u')'), + (Comment.Preproc, u'\\)'), + (String, u'}}'), + (Punctuation, u')'), + (Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) -- cgit v1.2.1 From 68cfbd6fb823f77b741be33109deab4936ac9fe5 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 29 Jan 2017 08:30:26 +0100 Subject: Xorg: fixup style, add test file, regenerate mapping. --- tests/examplefiles/xorg.conf | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/examplefiles/xorg.conf (limited to 'tests') diff --git a/tests/examplefiles/xorg.conf b/tests/examplefiles/xorg.conf new file mode 100644 index 00000000..a189be9f --- /dev/null +++ b/tests/examplefiles/xorg.conf @@ -0,0 +1,48 @@ +Section "Files" + ModulePath "/usr/lib64/opengl/nvidia/extensions" + ModulePath "/usr/lib64/xorg/modules" +EndSection + +Section "ServerLayout" + Identifier "XFree86 Configured" + Screen "Screen" +EndSection + +Section "ServerFlags" + Option "AutoAddDevices" "false" +EndSection + +Section "Screen" + Identifier "Screen" + Device "Card0" + DefaultDepth 24 + SubSection "Display" + Depth 24 + EndSubSection + Option "UseEDIDDpi" "False" + Option "DPI" "96 x 96" +EndSection + +Section "Device" + Identifier "Card0" + Driver "nvidia" + VendorName "NVIDIA Corporation" + #Option "RenderAccel" "true" + + #Option "NvAgp" "3" + #Option "AllowGLXWithComposite" "true" + #Option "AddARGBGLXVisuals" "true" + #Option "XAANoOffscreenPixmaps" "true" + #Option "DRI" "true" + + #Option "UseEvents" "false" + #Option "TripleBuffer" "1" + #Option "DamageEvents" "1" + ##Option "BackingStore" "1" + #Option "PixmapCacheSize" "70000" + #Option "OnDemandVBlankInterrupts" "true" +EndSection + +Section "Extensions" +# Option "Composite" "Disabled" +EndSection -- cgit v1.2.1 From 1aec641cfd9cb1a15a504d3d4b0a5f4092a593c3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 30 Jan 2017 07:42:59 +0100 Subject: Xorg: add whitespace rule --- tests/examplefiles/xorg.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/examplefiles/xorg.conf b/tests/examplefiles/xorg.conf index a189be9f..e1f7164b 100644 --- a/tests/examplefiles/xorg.conf +++ b/tests/examplefiles/xorg.conf @@ -26,7 +26,7 @@ EndSection Section "Device" Identifier "Card0" Driver "nvidia" - VendorName "NVIDIA Corporation" + VendorName "NVIDIA Corporation" # inline comment #Option "RenderAccel" "true" #Option "NvAgp" "3" -- cgit v1.2.1 From 0db8e281af377923115b894703b2b8beb8f1e9d5 Mon Sep 17 00:00:00 2001 From: James Edwards Date: Mon, 13 Mar 2017 19:16:03 +0000 Subject: fix an issue where a route 53 alias was shown as an error --- tests/examplefiles/example.tf | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/example.tf b/tests/examplefiles/example.tf index d3f02779..5a85dbee 100644 --- a/tests/examplefiles/example.tf +++ b/tests/examplefiles/example.tf @@ -39,6 +39,16 @@ provider "aws" { */ +resource "aws_route53_record" "test" { + zone_id = "zone" + name = "name" + type = "A" + alias { + name = "alias name" + } +} + + # Single line comment resource "aws_instance" "example" { ami = "ami-408c7f28" -- cgit v1.2.1 From 8d6dced7b7bf0854089c185679420861888abaf2 Mon Sep 17 00:00:00 2001 From: Maxime Vidori Date: Tue, 28 Mar 2017 11:21:29 +0200 Subject: Update Dockerfile lexer Add Dockerfiles new keyword in the lexer Improve lexer to parse json arrays on specific commands Handle line breaks as a bash syntax --- tests/examplefiles/docker.docker | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/examplefiles/docker.docker b/tests/examplefiles/docker.docker index d65385b6..1ae3c3a1 100644 --- a/tests/examplefiles/docker.docker +++ b/tests/examplefiles/docker.docker @@ -1,5 +1,34 @@ -maintainer First O'Last +FROM alpine:3.5 +MAINTAINER First O'Last +# comment run echo \ 123 $bar -# comment +RUN apk --update add rsync dumb-init + +# Test env with both syntax +ENV FOO = "BAR" +ENV FOO \ + "BAR" + +COPY foo "bar" +COPY foo \ + "bar" + +HEALTHCHECK \ + --interval=5m --timeout=3s \ + CMD curl -f http://localhost/ || exit 1 + +# ONBUILD keyword, then with linebreak +ONBUILD ADD . /app/src +ONBUILD \ + RUN echo 123 $bar + +# Potential JSON array parsing, mixed with linebreaks +VOLUME \ + /foo +VOLUME \ + ["/bar"] +VOLUME ["/bar"] +VOLUME /foo +CMD ["foo", "bar"] -- cgit v1.2.1 From b28b24c5ffe0274a2ac45398766213e83bf6b2d7 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Tue, 2 May 2017 10:03:14 -0700 Subject: Added pep 515 support to the python lexer Fixes #1299 --- tests/test_python.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/test_python.py b/tests/test_python.py index e99687a6..6ef8169d 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -111,3 +111,22 @@ class Python3Test(unittest.TestCase): (Token.Text, u'\n'), ] self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def test_pep_515(self): + """ + Tests that the lexer can parse numeric literals with underscores + """ + fragments = ( + (Token.Literal.Number.Integer, u'1_000_000'), + (Token.Literal.Number.Float, u'1_000.000_001'), + (Token.Literal.Number.Hex, u'0xCAFE_F00D'), + (Token.Literal.Number.Bin, u'0b_0011_1111_0100_1110'), + (Token.Literal.Number.Oct, u'0o_777_123'), + ) + + for token, fragment in fragments: + tokens = [ + (token, fragment), + (Token.Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) -- cgit v1.2.1 From ed3bd801548a301071823a38ce6e19aa18e8215b Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Tue, 2 May 2017 22:46:05 -0700 Subject: Fixed missing complex float case --- tests/test_python.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/test_python.py b/tests/test_python.py index 6ef8169d..6445022c 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -119,6 +119,7 @@ class Python3Test(unittest.TestCase): fragments = ( (Token.Literal.Number.Integer, u'1_000_000'), (Token.Literal.Number.Float, u'1_000.000_001'), + (Token.Literal.Number.Float, u'1_000e1_000j'), (Token.Literal.Number.Hex, u'0xCAFE_F00D'), (Token.Literal.Number.Bin, u'0b_0011_1111_0100_1110'), (Token.Literal.Number.Oct, u'0o_777_123'), -- cgit v1.2.1 From 2235e4a7cd8b91cbd277643ad523610fcee84f98 Mon Sep 17 00:00:00 2001 From: Nathan Whetsell Date: Fri, 26 May 2017 17:29:45 -0400 Subject: Fix issue with opcode types --- tests/examplefiles/test.orc | 2 +- tests/test_csound.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/examplefiles/test.orc b/tests/examplefiles/test.orc index 59bf7f66..d113303e 100644 --- a/tests/examplefiles/test.orc +++ b/tests/examplefiles/test.orc @@ -9,7 +9,7 @@ instr/**/1,/**/N_a_M_e_,/**/+Name/**/// outc:a(aSignal) endin -opcode/**/aUDO,/**/0,/**/aik// +opcode/**/aUDO,/**/i[],/**/aik// aUDO endop diff --git a/tests/test_csound.py b/tests/test_csound.py index 610dec1a..b5094fc6 100644 --- a/tests/test_csound.py +++ b/tests/test_csound.py @@ -84,7 +84,7 @@ class CsoundOrchestraTest(unittest.TestCase): def testUserDefinedOpcodes(self): fragment = dedent('''\ - opcode/**/aUDO,/**/0,/**/aik// + opcode/**/aUDO,/**/i[],/**/aik// aUDO endop ''') @@ -94,7 +94,7 @@ class CsoundOrchestraTest(unittest.TestCase): (Name.Function, u'aUDO'), (Punctuation, u','), (Comment.Multiline, u'/**/'), - (Keyword.Type, u'0'), + (Keyword.Type, u'i[]'), (Punctuation, u','), (Comment.Multiline, u'/**/'), (Keyword.Type, u'aik'), -- cgit v1.2.1 From a20d1aa299b7fadb347a1d5ed482696879e4e9b1 Mon Sep 17 00:00:00 2001 From: Nathan Whetsell Date: Sat, 27 May 2017 08:17:33 -0400 Subject: Add Csound Score d statement --- tests/examplefiles/test.sco | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/examplefiles/test.sco b/tests/examplefiles/test.sco index e855e563..d997c1b3 100644 --- a/tests/examplefiles/test.sco +++ b/tests/examplefiles/test.sco @@ -3,7 +3,7 @@ */ ; comment // comment -a b C e f i q s t v x y +a b C d e f i q s t v x y z np0 nP1 Np2 NP3 m/**/label; -- cgit v1.2.1 From 87fdfbab1a8bd27420d143816eb3645b22a6b4e0 Mon Sep 17 00:00:00 2001 From: Nathan Whetsell Date: Sun, 6 Aug 2017 13:17:38 -0400 Subject: Update for Csound 6.09.1 --- tests/test_csound.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_csound.py b/tests/test_csound.py index b5094fc6..4d10c267 100644 --- a/tests/test_csound.py +++ b/tests/test_csound.py @@ -119,9 +119,11 @@ class CsoundOrchestraTest(unittest.TestCase): self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) fragment = '0xabcdef0123456789 0XABCDEF' tokens = [ - (Number.Hex, u'0xabcdef0123456789'), + (Keyword.Type, u'0x'), + (Number.Hex, u'abcdef0123456789'), (Text, u' '), - (Number.Hex, u'0XABCDEF'), + (Keyword.Type, u'0X'), + (Number.Hex, u'ABCDEF'), (Text, u'\n') ] self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) @@ -436,18 +438,21 @@ class CsoundOrchestraTest(unittest.TestCase): self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) def testFunctionLikeMacros(self): - fragment = '$MACRO.(((x\\))\' "x)\\)x\\))"# {{x\\))x)\\)}})' + fragment = "$MACRO.(((x#y\\)))' \"(#'x)\\)x\\))\"# {{x\\))x)\\)(#'}});" tokens = [ (Comment.Preproc, u'$MACRO.'), (Punctuation, u'('), (Comment.Preproc, u'('), (Comment.Preproc, u'('), - (Comment.Preproc, u'x'), - (Comment.Preproc, u'\\)'), - (Error, u')'), + (Comment.Preproc, u'x#y\\)'), + (Comment.Preproc, u')'), + (Comment.Preproc, u')'), (Punctuation, u"'"), (Comment.Preproc, u' '), (String, u'"'), + (Error, u'('), + (Error, u'#'), + (Error, u"'"), (String, u'x'), (Error, u')'), (Comment.Preproc, u'\\)'), @@ -464,8 +469,12 @@ class CsoundOrchestraTest(unittest.TestCase): (String, u'x'), (Error, u')'), (Comment.Preproc, u'\\)'), + (Error, u'('), + (Error, u'#'), + (Error, u"'"), (String, u'}}'), (Punctuation, u')'), + (Comment.Single, u';'), (Text, u'\n') ] self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) -- cgit v1.2.1 From 2a2b6104c3d391ac5d391e754516c6046afe08e6 Mon Sep 17 00:00:00 2001 From: Brian Tiffin Date: Thu, 31 Aug 2017 04:27:22 +0000 Subject: example.icon created online with Bitbucket --- tests/examplefiles/example.icon | 381 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 381 insertions(+) create mode 100644 tests/examplefiles/example.icon (limited to 'tests') diff --git a/tests/examplefiles/example.icon b/tests/examplefiles/example.icon new file mode 100644 index 00000000..29bc548b --- /dev/null +++ b/tests/examplefiles/example.icon @@ -0,0 +1,381 @@ +############################################################################ +# +# File: kaleid.icn +# +# Subject: Program to produce kaleidoscope +# +# Author: Stephen B. Wampler +# +# Date: May 2, 2001 +# +############################################################################ +# +# This file is in the public domain. +# +############################################################################ +# +# Lots of options, most easily set by with the interface after +# startup. The only one that isn't set that way is -wn where 'n' is +# the size of the kaleidoscope window (default is 600 square). +# +# Terminology (and options): +# +# Window_size (-wN): How big of a display window to use. +# At the current time, this can only be set via a +# command line argument. +# +# Density (-dN): How many circles per octant to keep on display +# at any one time. There is NO LIMIT to the density. +# +# Duration (-lN): How long to keep drawing circles (measured in +# in circles) once the density is reached. There is NO LIMIT +# to the duration. +# +# MaxRadius (-MN): Maximum radius of any circle. +# +# MinRadius (-mN): Preferred minimum radius. Circles with centers +# near the edge have their radii forced down to fit entirely +# on the display +# +# MaxOffset (-XN): Maximum offset from center of display (may wrap). +# +# MinOffset (-xN): Minimum offset +# +# Skew (-sN): Shift probability of placing a circle at a 'typical' +# offset. +# +# Fill (-F): Turns off filling the circles. +# +# Clear (-C): After the duration, reduces density back to 0 before +# quitting. +# +# Random Seed: (-rN): Sets the random number seed. +# +# Thanks to Jon Lipp for help on using vidgets, and to Mary Camaron +# for her Interface Builder. +# +############################################################################ +# +# Requires: Version 9 graphics +# +############################################################################ +# +# Links: vidgets, vslider, vtext, vbuttons, vradio, wopen, xcompat +# +############################################################################ + +link vidgets +link vslider +link vtext +link vbuttons +link vradio +link wopen +link xcompat + +global Clear, fill, duration, density, maxoff, minoff +global maxradius, minradius, r_seed, skew, win_size, mid_win +global root, check1, mainwin, use_dialog +global draw_circle + +global du_v, de_v, rs_v, sk_v + +procedure main (args) + + draw_circle := DrawCircle + + init_globs() + process_args(args) + + if \use_dialog then { # have vidgets, so use them for args. + mainwin := WOpen("label=Kaleidoscope", "width=404", "height=313", + "font=6x12") | + stop ("bad mainwin") + root := ui (mainwin) + GetEvents (root, quit) + } + else { # just rely on command line arguments + kaleidoscope(r_seed) + } + +end + +procedure init_globs() + + duration := 500 # set default characteristics + density := 30 + win_size := 600 + minoff := 1 + maxradius := 150 + minradius := 1 + skew := 1 + fill := "On" + draw_circle := FillCircle + Clear := "Off" + r_seed := map("HhMmYy", "Hh:Mm:Yy", &clock) + # See if the Vidget library is available or not + if \VSet then use_dialog := "yes" + else use_dialog := &null + +end + +procedure process_args(args) + local arg + + # really only needed if you don't use the dialog box + every arg := !args do case arg[1+:2] of { + "-w" : win_size := integer(arg[3:0]) # window size + "-d" : density := integer(arg[3:0]) # density of circles + "-l" : duration := integer(arg[3:0]) # duration + "-M" : maxradius := integer(arg[3:0]) # maximum radius + "-m" : minradius := integer(arg[3:0]) # minimum radius + "-X" : maxoff := integer(arg[3:0]) # maximum offset + "-x" : minoff := integer(arg[3:0]) # minimum offset + "-s" : skew := numeric(arg[3:0]) # set skewedness + "-F" : fill := &null # turn off fill + "-C" : Clear := "yes" # turn on clear mode + "-r" : r_seed := integer(arg[3:0]) # random seed + "-h" : stop("usage: kal [-wn] [-dn] [-ln] [-Mn] [-mn] [-Xn] [-xn] _ + [-sn] [-F] [-C] [-rn]") + } + # adjust parameters that depend on the window size... + mid_win := win_size/2 + maxoff := win_size-1 +end + +# Lorraine Callahan's kaleidoscope program, translated into icon. +# (some of the things she did were too sophisticated for me +# to spend time to figure out, so the output is square instead of +# round), and I use 'xor' to draw instead of writing to separate +# bit planes. + +global putcircle, clrcircle + +procedure kaleidoscope(r) + local colors + + # What colors to use? This can be changed to whatever! + colors := ["red","green","blue","cyan","magenta","yellow"] + + &window := WOpen("label=Kaleidoscope: 'q' quits", "width="||win_size, + "height="||win_size, "bg=black") + WAttrib("drawop=xor") + + # Create two *indentical* sequences of circles, one to use when + # when drawing, one for erasing. (Since 'xor' is used to + # place them, these both just draw the circles!) + + putcircle := create { # draws sequence of circles + &random :=: r + |{ + Fg(?colors) + outcircle() + &random <-> r + } + } + + clrcircle := create { # erases sequence of circles + &random :=: r + |{ + Fg(?colors) + outcircle() + &random <-> r + } + } + + every 1 to density do @putcircle # fill screen to density + + every 1 to duration do { # maintain steady state + @putcircle + @clrcircle + if *Pending(&window) > 0 then break + } + + every (Clear == "On") & 1 to density do @clrcircle + + close(&window) +end + + +procedure outcircle() # select a circle at random, +local radius, xoff, yoff # draw it in kaleidoscopic form + + # get a random center point and radius + xoff := (?(maxoff - minoff) + minoff) % mid_win + yoff := (?(maxoff - minoff) + minoff) % mid_win + radius := ?0 ^ skew + # force radius to 'fit' + radius := ((maxradius-minradius) * radius + minradius) % + (mid_win - ((xoff < yoff)|xoff)) + + # put into all 8 octants + draw_circle(mid_win+xoff, mid_win+yoff, radius) + draw_circle(mid_win+xoff, mid_win-yoff, radius) + draw_circle(mid_win-xoff, mid_win+yoff, radius) + draw_circle(mid_win-xoff, mid_win-yoff, radius) + + draw_circle(mid_win+yoff, mid_win+xoff, radius) + draw_circle(mid_win+yoff, mid_win-xoff, radius) + draw_circle(mid_win-yoff, mid_win+xoff, radius) + draw_circle(mid_win-yoff, mid_win-xoff, radius) + + return +end + + +############################################################################ +# +# Vidget-based user interface -- developed originally using Mary +# Camaron's XIB program. Don't expect this to be very readable - +# you should have to play with it! +# +############################################################################ +procedure ui (win) + local cv1, cv2, cv3, cv4 + local + radio_button2, + radio_button1, + text_input6, + text_input5, + slider4, + slider3, + text_input4, + text_input3, + slider2, + slider1 + + /win := WOpen("label=ui", "width=404", "height=313", "font=6x12") | + stop ("bad win") + root := Vroot_frame (win) + + VInsert (root, Vmessage(win, win_size/2), 168, 98) + VInsert (root, Vmessage(win, "1"), 108, 97) + + VInsert (root, sk_v := Vtext(win,"Skew:\\=1",get_skew,,6), 280, 39) + + VInsert (root, du_v := Vtext(win, "Duration:\\="||duration, get_duration,,9), + 237, 15) + + VInsert (root, Vmessage(win, "Clear at end?"), 232, 145) + VInsert (root, Vmessage(win, "Fill?"), 105, 142) + VInsert (root, Vmessage(win,"Quit?"), 267, 259) + VInsert (root, Vmessage(win,"Display it?"), 26, 260) + + VInsert (root, Vcheckbox(win, do_quit, "check2",20), 305, 255, 20, 20) + + VInsert (root, check1:=Vcheckbox(win, do_display, "check1",20), + 106, 258, 20, 20) + + radio_button2 := Vradio_buttons (win, ["On", "Off"], get_clear, , V_CIRCLE) + VSet(radio_button2,Clear) + VInsert (root, radio_button2, 253, 165) + + radio_button1 := Vradio_buttons (win, ["On", "Off"], get_fill, , V_CIRCLE) + VSet(radio_button1,fill) + VInsert (root, radio_button1, 99, 165) + + cv1 := Vcoupler() + VAddClient(cv1, get_max_offset) + text_input6 := Vtext (win, "Max Offset:\\="||(win_size-1), cv1, , 3) + VAddClient(cv1, text_input6) + slider4 := Vhoriz_slider (win, cv1, "slider4", 70, 12, 0, + win_size-1, win_size-1, ) + VAddClient(cv1, slider4) + VInsert (root, text_input6, 196, 103) + VInsert (root, slider4, 306, 106) + + cv2 := Vcoupler() + VAddClient(cv2, get_min_offset) + text_input5 := Vtext (win, "Min Offset\\=1", cv2, , 3) + VAddClient(cv2, text_input5) + slider3 := Vhoriz_slider (win, cv2, "slider3", 70, 12, 1, win_size-1, 1, ) + VAddClient(cv2, slider3) + VInsert (root, text_input5, 201, 80) + VInsert (root, slider3, 307, 82) + + cv3 := Vcoupler() + VAddClient(cv3, get_max_radius) + text_input4 := Vtext (win, "Max Radius\\="||(win_size/4), cv3, , 3) + VAddClient(cv3, text_input4) + slider2 := Vhoriz_slider (win, cv3, "slider2", 70, 12, 1, win_size/2, + win_size/4, ) + VAddClient(cv3, slider2) + VInsert (root, text_input4, 10, 104) + VInsert (root, slider2, 110, 108) + + cv4 := Vcoupler() + VAddClient(cv4, get_min_radius) + text_input3 := Vtext (win, "Min Radius\\=1", cv4, , 3) + VAddClient(cv4, text_input3) + slider1 := Vhoriz_slider (win, cv4, "slider1", 70, 12, 1, win_size/2, 1, ) + VAddClient(cv4, slider1) + VInsert (root, text_input3, 10, 81) + VInsert (root, slider1, 110, 84) + + VInsert (root, rs_v := Vtext(win,"Random Seed:\\="||r_seed, get_random,, 11), + 30, 41) + VInsert (root, de_v := Vtext(win,"Density:\\="||density, get_density,,8), + 71, 16) + + VResize (root) + return root +end + +procedure get_skew (wit, value) + skew := value +end + +procedure get_duration (wit, value) + duration := value +end + +procedure do_quit (wit, value) + stop() +end + +procedure do_display (wit, value) + r_seed := numeric(rs_v.data) + duration := integer(du_v.data) + density := integer(de_v.data) + skew := integer(sk_v.data) + kaleidoscope(r_seed) + wit.callback.value := &null + VDraw(check1) +end + +procedure get_clear (wit, value) + Clear := value +end + +procedure get_fill (wit, value) + fill := value + if fill == "Off" then draw_circle := DrawCircle + else draw_circle := FillCircle +end + +procedure get_max_offset (wit, value) + maxoff := value +end + +procedure get_min_offset (wit, value) + minoff := value +end + +procedure get_max_radius (wit, value) + maxradius := value +end + +procedure get_min_radius (wit, value) + minradius := value +end + +procedure get_random (wit, value) + r_seed := integer(value) +end + +procedure get_density (wit, value) + density := integer(value) +end + +procedure quit(e) + if e === "q" then stop ("Exiting Kaleidoscope") +end -- cgit v1.2.1 From 0fe8a0744d6c2cfa5c23ebd3164d6c3712e04391 Mon Sep 17 00:00:00 2001 From: Brian Tiffin Date: Thu, 31 Aug 2017 04:29:00 +0000 Subject: example.u created online with Bitbucket --- tests/examplefiles/example.u | 659 ++++++++----------------------------------- 1 file changed, 111 insertions(+), 548 deletions(-) (limited to 'tests') diff --git a/tests/examplefiles/example.u b/tests/examplefiles/example.u index 42c85902..92c45365 100644 --- a/tests/examplefiles/example.u +++ b/tests/examplefiles/example.u @@ -1,548 +1,111 @@ - // This is a one line comment. - /* an inner comment */ - - /* nested /* comments */ */ - - /* - /* - Multi-line. - */ - */ - -// Binary blob escape. -//"some text \B(3)("\") ouhyeah" == "\"\\\""; -"some text \B(3)("\") ouhyeah" == "\"\\\""; -'some text \B(3)('\') ouhyeah' == '\'\\\''; - -//"\B(4)()"'()"; -"\B(4)()"'()"; -'\B(4)()'"()'; - -//blob size limits -"hey ! \B(0)() oh !" - -//blob format is wrong -"hey ! \B(2)(aaa) oh !" -"hey ! \B(100)(aaa) oh !" - -//multiple blob in a string -"hey ! \B(3)(aaa) hey ! \B(3)(aaa) oh !" - -// multiple digits blob size -"hey ! \B(10)(aaaaaaaaaa) !" -"hey ! \B(10)(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) !" -"hey ! \B(100)(a) !" - -// multiple digits blob size -"hey ! \B(007)(aaaaaaa) !" -"hey ! \B(007)(aa) !" -"hey ! \B(007)(aaaaaaaaaaaaaaaaaa) !" - -// deprecated and restricted keyworks -emit Event.new; -static int main(); - -loopn (2) {echo("a");}; - -foreach (var i : [1,2,3,4]) { - echo(i); -}; - -function() {}; - -var 'if'; -var this.'else'; - -var '%x'; -var '1 2 3'; -var this.'[]'; - -// angles -pi == 180deg; -pi == 200grad; - -// Dictionary -[ => ]; // The empty dictionary - -// duration -1d == 24h; -0.5d == 12h; -1h == 60min; -1min == 60s; -1s == 1000ms; - -1s == 1; -1s 2s 3s == 6; -1s 1ms == 1.001; -1ms 1s == 1.001; - - - 1 == 1; - 1 == 1.0; - 1.2 == 1.2000; - 1.234e6 == 1234000; - 1e+11 == 1E+11; - 1e10 == 10000000000; - 1e30 == 1e10 * 1e10 * 1e10; - - -0.000001; - -0.0000001; - -0.00000000001; - -1e+3; - -1E-5; - - -1.; -// [00004701:error] !!! syntax error: unexpected ; - - 0x2a == 42; - 0x2A == 42; - 0xabcdef == 11259375; - 0xABCDEF == 11259375; -0xFFFFFFFF == 4294967295; - - -//123foo; -//[00005658:error] !!! syntax error: invalid token: '123foo' -//12.3foo; -//[00018827:error] !!! syntax error: invalid token: '12.3foo' -0xabcdef; -//[00060432] 11259375 -//0xabcdefg; -//[00061848:error] !!! syntax error: invalid token: '0xabcdefg' - - -[]; // The empty list -[1, 2, 3]; - -// Special characters. -"\"" == "\""; -"\\" == "\\"; - -// ASCII characters. -"\a" == "\007"; "\a" == "\x07"; -"\b" == "\010"; "\b" == "\x08"; -"\f" == "\014"; "\f" == "\x0c"; -"\n" == "\012"; "\n" == "\x0a"; -"\r" == "\015"; "\r" == "\x0d"; -"\t" == "\011"; "\t" == "\x09"; -"\v" == "\013"; "\v" == "\x0b"; - -// Octal escapes. -"\0" == "\00"; "\0" == "\000"; -"\0000" == "\0""0"; -"\062\063" == "23"; - -// Hexadecimal escapes. -"\x00" == "\0"; -"\x32\x33" == "23"; - - - -"foo" "bar" "baz" == "foobarbaz"; - -// Tuples -(); -[00000000] () -(1,); -[00000000] (1,) -(1, 2); -[00000000] (1, 2) -(1, 2, 3, 4,); -[00000000] (1, 2, 3, 4) - -function Global.verboseId(var x) -{ - echo(x) | x -}|; -class verboseId(Global).math : verboseId(Math) -{ -}; - -{ - for (3) - { - sleep(1s); - echo("ping"); - }, - sleep(0.5s); - for (3) - { - sleep(1s); - echo("pong"); - }, -}; - - 1 + 1 == 2; - 1 - 2 == -1; - 2 * 3 == 6; - 10 / 2 == 5; - 2 ** 10 == 1024; - -(1 + 2) == -3; - 1 + 2 * 3 == 7; - (1 + 2) * 3 == 9; - -2 ** 2 == -4; - - - - - 1 == 1; - -a = b -a += b -a -= b -a *= b -a /= b -a %= b -a ^= b - - -var value = 0|; -var valueAlias = value|; -value += 10; -valueAlias; -var myList = []|; -var myList.specialFeature = 42|; -myList += [1, 2, 3]; -myList.specialFeature; -var myOtherList = myList + [4, 5]; -myOtherList.specialFeature; -var something = []|; -var somethingElse = something|; -something += [1, 2]; -somethingElse += [3, 4]; -something; - - -class Counter -{ - var count = 0; - function init (n) { var this.count = n }; - // Display the value, and the identity. - function asString() { "%s @ %s" % [count, uid ] }; - function '+'(var n) { new(count + n) }; - function '-'(var n) { new(count - n) }; -}|; - - -class ImmutableCounter : Counter -{ - function '+='(var n) { this + n }; - function '-='(var n) { this - n }; -}|; - -var ic1 = ImmutableCounter.new(0); -var ic2 = ic1; - -ic1 += 1; -ic1; -ic2; - - -a << b -a >> b -a ^ b - -4 << 2 == 16; -4 >> 2 == 1; - -!a -a && b -a || b - -true && true; -true || false; -!true == false; -true || (1 / 0); -(false && (1 / 0)) == false; - -a == b -a != b -a === b -a !== b -a ~= b -a =~= b -a < b -a <= b -a > b -a >= b - -assert{ - ! (0 < 0); - 0 <= 0; - 0 == 0; - 0 !== 0; -}; - -a in b -a not in b -a[args] -a[args] = v - -1 in [0, 1, 2]; -3 not in [0, 1, 2]; - -"one" in ["zero" => 0, "one" => 1, "two" => 2]; -"three" not in ["zero" => 0, "one" => 1, "two" => 2]; - -a.b -a.b(args) -a->b -a->b = v -a.&b - -var obj = Object.new|; -function obj.f() { 24 }|; - - -var f = function(a, b) { - echo(b + a); -}| -f(1, 0); - - -function g3() -{ - return; // Stop execution at this point and return void - echo(0); // This is not executed -}| - -Object.setProperty, to define/set a property. -Object.getProperty, to get a property. -Object.removeProperty, to delete a property. -Object.hasProperty, to test for the existence of a property. -Object.properties, to get all the properties of a slot. - -enum Suit -{ - hearts, - diamonds, - clubs, - spades, // Last comma is optional -}; - -for (var suit in Suit) - echo("%s the ace of %s." % [find_ace(suit), suit]); - -switch ( ("foo", [1, 2]) ) -{ - // The pattern does not match the values of the list. - case ("foo", [2, 1]): - echo("fail"); - - // The pattern does not match the tuple. - case ["foo", [1, 2]]: - echo("fail"); - - // The pattern matches and binds the variable "l" - // but the condition is not verified. - case ("foo", var l) if l.size == 0: - echo("fail"); - - // The pattern matches. - case ("foo", [var a, var b]): - echo("foo(%s, %s)" % [a, b]); -}; -//[00000000] *** foo(1, 2) - -{ - ["b" => var b, "a" => var a] = ["a" => 1, "b" => 2, "c" => 3]; - echo("a = %d, b = %d" % [a, b]); -}; -//[00000000] *** a = 1, b = 2 - - -switch (["speed" => 2, "time" => 6s]) -{ - case ["speed" => var s] if s > 3: - echo("Too fast"); - case ["speed" => var s, "time" => var t] if s * t > 10: - echo("Too far"); -}; -//[00000000] *** Too far - - -try -{ - throw ("message", 0) -} -catch (var e if e.isA(Exception)) -{ - echo(e.message) -} -catch ((var msg, var value) if value.isA(Float)) -{ - echo("%s: %d" % [msg, value]) -}; -//[00000000] *** message: 0 - - -{ - var e = Event.new; - at (e?(var msg, var value) if value % 2 == 0) - echo("%s: %d" % [msg, value]); - - // Does not trigger the "at" because the guard is not verified. - e!("message", 1); - - // Trigger the "at". - e!("message", 2); -}; -//[00000000] *** message: 2 - -for (var i = 0; i < 8; i++) -{ - if (i % 2 != 0) - continue; - echo(i); -}; - -do (1024) -{ - assert(this == 1024); - assert(sqrt == 32); - setSlot("y", 23); -}.y; - -{ - var n = 10|; - var res = []|; - loop;{ - n--; - res << n; - if (n == 0) - break - }; - res -} - - -{ - var n = 10|; - var res = []|; - loop|{ - n--; - res << n; - if (n == 0) - break - }; - res -} - - -var j = 3| -while (0 < j) -{ - echo(j); - j--; -}; - - -{ - var i = 4| - while| (true) - { - i -= 1; - echo ("in: " + i); - if (i == 1) - break - else if (i == 2) - continue; - echo ("out: " + i); - }; -}; - - - -function test(e) -{ - try - { throw e; } - catch (0) - { echo("zero") } - catch ([var x, var y]) - { echo(x + y) } -} | {}; - -try { echo("try") } -catch { echo("catch")} -else { echo("else")}; - - -try -{ - echo("inside"); -} -finally -{ - echo("finally"); -}; -//[00000001] *** inside -//[00000002] *** finally - -at (e?(var start) ~ 1s) - echo("in : %s" % (time - start).round) -onleave - echo("out: %s" % (time - start).round); - -// This emission is too short to trigger the at. -e!(time); - -// This one is long enough. -// The body triggers 1s after the emission started. -e!(time) ~ 2s; -//[00001000] *** in : 1 -//[00002000] *** out: 2 - - -timeout (2.1s) - every (1s) - echo("Are you still there?"); -//[00000000] *** Are you still there? -//[00001000] *** Are you still there? -//[00002000] *** Are you still there? - - every| (1s) - { - echo("aba"); - }; - -for, (var i = 3; 0 < i; i -= 1) -{ - echo (i); -}; - - -for& (var i: [0, 1, 2]) -{ - echo (i * i); -}; - -loop,{ -}; - - -waituntil (e?(1, var b)); - -whenever (e?("arg", var arg) if arg % 2) - echo("e (%s) on" % arg) -else - echo("e off"); - - - while, (i) - { - var j = i -= 1; - }| - - -var y = 0; -{ - sleep(0.5s); - y = 100 smooth:3s, -}, - - - - +version U12.1.00 +uid version.u1-1494453463-0 +impl local +global 1 + 0,000005,version,0 + + +proc version + local 0,000000,tab + local 1,000000,find + local 2,000000,many + con 0,010000,8,126,145,162,163,151,157,156,040 + con 1,002000,1,8 + con 2,020000,11,060,061,062,063,064,065,066,067,070,071,056 + con 3,002000,1,1 + declend + filen version.icn + line 23 + colm 11 + synt any + mark L1 + line 25 + colm 4 + synt any + keywd version + line 25 + colm 13 + synt any + bscan + mark L2 + mark L3 + var 0 + pnull + var 1 + str 0 + line 26 + colm 15 + synt any + invoke 1 + int 1 + line 26 + colm 28 + synt any + plus + line 26 + colm 10 + synt any + invoke 1 + line 26 + colm 33 + synt any + esusp + goto L4 +lab L3 + line 26 + colm 35 + synt any + pfail +lab L4 + unmark +lab L2 + var 0 + var 2 + cset 2 + line 27 + colm 15 + synt any + invoke 1 + line 27 + colm 10 + synt any + invoke 1 + line 27 + colm 32 + synt any + bscan + mark L5 + var 0 + pnull + int 3 + line 27 + colm 45 + synt any + neg + line 27 + colm 44 + synt any + invoke 1 + line 27 + colm 34 + synt any + pret +lab L5 + synt any + pfail + line 27 + colm 32 + synt any + escan + line 25 + colm 13 + synt any + escan + unmark +lab L1 + pnull + line 30 + colm 1 + synt any + pfail + end \ No newline at end of file -- cgit v1.2.1 From 84baa921c15946d7dc692f5bdfa20a5050e572cd Mon Sep 17 00:00:00 2001 From: Brian Tiffin Date: Thu, 31 Aug 2017 05:04:49 +0000 Subject: example.u edited online with Bitbucket --- tests/examplefiles/example.u | 658 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 547 insertions(+), 111 deletions(-) (limited to 'tests') diff --git a/tests/examplefiles/example.u b/tests/examplefiles/example.u index 92c45365..8c6686eb 100644 --- a/tests/examplefiles/example.u +++ b/tests/examplefiles/example.u @@ -1,111 +1,547 @@ -version U12.1.00 -uid version.u1-1494453463-0 -impl local -global 1 - 0,000005,version,0 - - -proc version - local 0,000000,tab - local 1,000000,find - local 2,000000,many - con 0,010000,8,126,145,162,163,151,157,156,040 - con 1,002000,1,8 - con 2,020000,11,060,061,062,063,064,065,066,067,070,071,056 - con 3,002000,1,1 - declend - filen version.icn - line 23 - colm 11 - synt any - mark L1 - line 25 - colm 4 - synt any - keywd version - line 25 - colm 13 - synt any - bscan - mark L2 - mark L3 - var 0 - pnull - var 1 - str 0 - line 26 - colm 15 - synt any - invoke 1 - int 1 - line 26 - colm 28 - synt any - plus - line 26 - colm 10 - synt any - invoke 1 - line 26 - colm 33 - synt any - esusp - goto L4 -lab L3 - line 26 - colm 35 - synt any - pfail -lab L4 - unmark -lab L2 - var 0 - var 2 - cset 2 - line 27 - colm 15 - synt any - invoke 1 - line 27 - colm 10 - synt any - invoke 1 - line 27 - colm 32 - synt any - bscan - mark L5 - var 0 - pnull - int 3 - line 27 - colm 45 - synt any - neg - line 27 - colm 44 - synt any - invoke 1 - line 27 - colm 34 - synt any - pret -lab L5 - synt any - pfail - line 27 - colm 32 - synt any - escan - line 25 - colm 13 - synt any - escan - unmark -lab L1 - pnull - line 30 - colm 1 - synt any - pfail - end \ No newline at end of file + // This is a one line comment. + /* an inner comment */ + + /* nested /* comments */ */ + + /* + /* + Multi-line. + */ + */ + +// Binary blob escape. +//"some text \B(3)("\") ouhyeah" == "\"\\\""; +"some text \B(3)("\") ouhyeah" == "\"\\\""; +'some text \B(3)('\') ouhyeah' == '\'\\\''; + +//"\B(4)()"'()"; +"\B(4)()"'()"; +'\B(4)()'"()'; + +//blob size limits +"hey ! \B(0)() oh !" + +//blob format is wrong +"hey ! \B(2)(aaa) oh !" +"hey ! \B(100)(aaa) oh !" + +//multiple blob in a string +"hey ! \B(3)(aaa) hey ! \B(3)(aaa) oh !" + +// multiple digits blob size +"hey ! \B(10)(aaaaaaaaaa) !" +"hey ! \B(10)(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) !" +"hey ! \B(100)(a) !" + +// multiple digits blob size +"hey ! \B(007)(aaaaaaa) !" +"hey ! \B(007)(aa) !" +"hey ! \B(007)(aaaaaaaaaaaaaaaaaa) !" + +// deprecated and restricted keyworks +emit Event.new; +static int main(); + +loopn (2) {echo("a");}; + +foreach (var i : [1,2,3,4]) { + echo(i); +}; + +function() {}; + +var 'if'; +var this.'else'; + +var '%x'; +var '1 2 3'; +var this.'[]'; + +// angles +pi == 180deg; +pi == 200grad; + +// Dictionary +[ => ]; // The empty dictionary + +// duration +1d == 24h; +0.5d == 12h; +1h == 60min; +1min == 60s; +1s == 1000ms; + +1s == 1; +1s 2s 3s == 6; +1s 1ms == 1.001; +1ms 1s == 1.001; + + + 1 == 1; + 1 == 1.0; + 1.2 == 1.2000; + 1.234e6 == 1234000; + 1e+11 == 1E+11; + 1e10 == 10000000000; + 1e30 == 1e10 * 1e10 * 1e10; + + +0.000001; + +0.0000001; + +0.00000000001; + +1e+3; + +1E-5; + + +1.; +// [00004701:error] !!! syntax error: unexpected ; + + 0x2a == 42; + 0x2A == 42; + 0xabcdef == 11259375; + 0xABCDEF == 11259375; +0xFFFFFFFF == 4294967295; + + +//123foo; +//[00005658:error] !!! syntax error: invalid token: '123foo' +//12.3foo; +//[00018827:error] !!! syntax error: invalid token: '12.3foo' +0xabcdef; +//[00060432] 11259375 +//0xabcdefg; +//[00061848:error] !!! syntax error: invalid token: '0xabcdefg' + + +[]; // The empty list +[1, 2, 3]; + +// Special characters. +"\"" == "\""; +"\\" == "\\"; + +// ASCII characters. +"\a" == "\007"; "\a" == "\x07"; +"\b" == "\010"; "\b" == "\x08"; +"\f" == "\014"; "\f" == "\x0c"; +"\n" == "\012"; "\n" == "\x0a"; +"\r" == "\015"; "\r" == "\x0d"; +"\t" == "\011"; "\t" == "\x09"; +"\v" == "\013"; "\v" == "\x0b"; + +// Octal escapes. +"\0" == "\00"; "\0" == "\000"; +"\0000" == "\0""0"; +"\062\063" == "23"; + +// Hexadecimal escapes. +"\x00" == "\0"; +"\x32\x33" == "23"; + + + +"foo" "bar" "baz" == "foobarbaz"; + +// Tuples +(); +[00000000] () +(1,); +[00000000] (1,) +(1, 2); +[00000000] (1, 2) +(1, 2, 3, 4,); +[00000000] (1, 2, 3, 4) + +function Global.verboseId(var x) +{ + echo(x) | x +}|; +class verboseId(Global).math : verboseId(Math) +{ +}; + +{ + for (3) + { + sleep(1s); + echo("ping"); + }, + sleep(0.5s); + for (3) + { + sleep(1s); + echo("pong"); + }, +}; + + 1 + 1 == 2; + 1 - 2 == -1; + 2 * 3 == 6; + 10 / 2 == 5; + 2 ** 10 == 1024; + -(1 + 2) == -3; + 1 + 2 * 3 == 7; + (1 + 2) * 3 == 9; + -2 ** 2 == -4; + - - - - 1 == 1; + +a = b +a += b +a -= b +a *= b +a /= b +a %= b +a ^= b + + +var value = 0|; +var valueAlias = value|; +value += 10; +valueAlias; +var myList = []|; +var myList.specialFeature = 42|; +myList += [1, 2, 3]; +myList.specialFeature; +var myOtherList = myList + [4, 5]; +myOtherList.specialFeature; +var something = []|; +var somethingElse = something|; +something += [1, 2]; +somethingElse += [3, 4]; +something; + + +class Counter +{ + var count = 0; + function init (n) { var this.count = n }; + // Display the value, and the identity. + function asString() { "%s @ %s" % [count, uid ] }; + function '+'(var n) { new(count + n) }; + function '-'(var n) { new(count - n) }; +}|; + + +class ImmutableCounter : Counter +{ + function '+='(var n) { this + n }; + function '-='(var n) { this - n }; +}|; + +var ic1 = ImmutableCounter.new(0); +var ic2 = ic1; + +ic1 += 1; +ic1; +ic2; + + +a << b +a >> b +a ^ b + +4 << 2 == 16; +4 >> 2 == 1; + +!a +a && b +a || b + +true && true; +true || false; +!true == false; +true || (1 / 0); +(false && (1 / 0)) == false; + +a == b +a != b +a === b +a !== b +a ~= b +a =~= b +a < b +a <= b +a > b +a >= b + +assert{ + ! (0 < 0); + 0 <= 0; + 0 == 0; + 0 !== 0; +}; + +a in b +a not in b +a[args] +a[args] = v + +1 in [0, 1, 2]; +3 not in [0, 1, 2]; + +"one" in ["zero" => 0, "one" => 1, "two" => 2]; +"three" not in ["zero" => 0, "one" => 1, "two" => 2]; + +a.b +a.b(args) +a->b +a->b = v +a.&b + +var obj = Object.new|; +function obj.f() { 24 }|; + + +var f = function(a, b) { + echo(b + a); +}| +f(1, 0); + + +function g3() +{ + return; // Stop execution at this point and return void + echo(0); // This is not executed +}| + +Object.setProperty, to define/set a property. +Object.getProperty, to get a property. +Object.removeProperty, to delete a property. +Object.hasProperty, to test for the existence of a property. +Object.properties, to get all the properties of a slot. + +enum Suit +{ + hearts, + diamonds, + clubs, + spades, // Last comma is optional +}; + +for (var suit in Suit) + echo("%s the ace of %s." % [find_ace(suit), suit]); + +switch ( ("foo", [1, 2]) ) +{ + // The pattern does not match the values of the list. + case ("foo", [2, 1]): + echo("fail"); + + // The pattern does not match the tuple. + case ["foo", [1, 2]]: + echo("fail"); + + // The pattern matches and binds the variable "l" + // but the condition is not verified. + case ("foo", var l) if l.size == 0: + echo("fail"); + + // The pattern matches. + case ("foo", [var a, var b]): + echo("foo(%s, %s)" % [a, b]); +}; +//[00000000] *** foo(1, 2) + +{ + ["b" => var b, "a" => var a] = ["a" => 1, "b" => 2, "c" => 3]; + echo("a = %d, b = %d" % [a, b]); +}; +//[00000000] *** a = 1, b = 2 + + +switch (["speed" => 2, "time" => 6s]) +{ + case ["speed" => var s] if s > 3: + echo("Too fast"); + case ["speed" => var s, "time" => var t] if s * t > 10: + echo("Too far"); +}; +//[00000000] *** Too far + + +try +{ + throw ("message", 0) +} +catch (var e if e.isA(Exception)) +{ + echo(e.message) +} +catch ((var msg, var value) if value.isA(Float)) +{ + echo("%s: %d" % [msg, value]) +}; +//[00000000] *** message: 0 + + +{ + var e = Event.new; + at (e?(var msg, var value) if value % 2 == 0) + echo("%s: %d" % [msg, value]); + + // Does not trigger the "at" because the guard is not verified. + e!("message", 1); + + // Trigger the "at". + e!("message", 2); +}; +//[00000000] *** message: 2 + +for (var i = 0; i < 8; i++) +{ + if (i % 2 != 0) + continue; + echo(i); +}; + +do (1024) +{ + assert(this == 1024); + assert(sqrt == 32); + setSlot("y", 23); +}.y; + +{ + var n = 10|; + var res = []|; + loop;{ + n--; + res << n; + if (n == 0) + break + }; + res +} + + +{ + var n = 10|; + var res = []|; + loop|{ + n--; + res << n; + if (n == 0) + break + }; + res +} + + +var j = 3| +while (0 < j) +{ + echo(j); + j--; +}; + + +{ + var i = 4| + while| (true) + { + i -= 1; + echo ("in: " + i); + if (i == 1) + break + else if (i == 2) + continue; + echo ("out: " + i); + }; +}; + + + +function test(e) +{ + try + { throw e; } + catch (0) + { echo("zero") } + catch ([var x, var y]) + { echo(x + y) } +} | {}; + +try { echo("try") } +catch { echo("catch")} +else { echo("else")}; + + +try +{ + echo("inside"); +} +finally +{ + echo("finally"); +}; +//[00000001] *** inside +//[00000002] *** finally + +at (e?(var start) ~ 1s) + echo("in : %s" % (time - start).round) +onleave + echo("out: %s" % (time - start).round); + +// This emission is too short to trigger the at. +e!(time); + +// This one is long enough. +// The body triggers 1s after the emission started. +e!(time) ~ 2s; +//[00001000] *** in : 1 +//[00002000] *** out: 2 + + +timeout (2.1s) + every (1s) + echo("Are you still there?"); +//[00000000] *** Are you still there? +//[00001000] *** Are you still there? +//[00002000] *** Are you still there? + + every| (1s) + { + echo("aba"); + }; + +for, (var i = 3; 0 < i; i -= 1) +{ + echo (i); +}; + + +for& (var i: [0, 1, 2]) +{ + echo (i * i); +}; + +loop,{ +}; + + +waituntil (e?(1, var b)); + +whenever (e?("arg", var arg) if arg % 2) + echo("e (%s) on" % arg) +else + echo("e off"); + + + while, (i) + { + var j = i -= 1; + }| + + +var y = 0; +{ + sleep(0.5s); + y = 100 smooth:3s, +}, + + + -- cgit v1.2.1 From da8371503a37d730192221e9098728935b488aed Mon Sep 17 00:00:00 2001 From: Brian Tiffin Date: Thu, 31 Aug 2017 05:07:12 +0000 Subject: example.u1 created online with Bitbucket --- tests/examplefiles/example.u1 | 111 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/examplefiles/example.u1 (limited to 'tests') diff --git a/tests/examplefiles/example.u1 b/tests/examplefiles/example.u1 new file mode 100644 index 00000000..92c45365 --- /dev/null +++ b/tests/examplefiles/example.u1 @@ -0,0 +1,111 @@ +version U12.1.00 +uid version.u1-1494453463-0 +impl local +global 1 + 0,000005,version,0 + + +proc version + local 0,000000,tab + local 1,000000,find + local 2,000000,many + con 0,010000,8,126,145,162,163,151,157,156,040 + con 1,002000,1,8 + con 2,020000,11,060,061,062,063,064,065,066,067,070,071,056 + con 3,002000,1,1 + declend + filen version.icn + line 23 + colm 11 + synt any + mark L1 + line 25 + colm 4 + synt any + keywd version + line 25 + colm 13 + synt any + bscan + mark L2 + mark L3 + var 0 + pnull + var 1 + str 0 + line 26 + colm 15 + synt any + invoke 1 + int 1 + line 26 + colm 28 + synt any + plus + line 26 + colm 10 + synt any + invoke 1 + line 26 + colm 33 + synt any + esusp + goto L4 +lab L3 + line 26 + colm 35 + synt any + pfail +lab L4 + unmark +lab L2 + var 0 + var 2 + cset 2 + line 27 + colm 15 + synt any + invoke 1 + line 27 + colm 10 + synt any + invoke 1 + line 27 + colm 32 + synt any + bscan + mark L5 + var 0 + pnull + int 3 + line 27 + colm 45 + synt any + neg + line 27 + colm 44 + synt any + invoke 1 + line 27 + colm 34 + synt any + pret +lab L5 + synt any + pfail + line 27 + colm 32 + synt any + escan + line 25 + colm 13 + synt any + escan + unmark +lab L1 + pnull + line 30 + colm 1 + synt any + pfail + end \ No newline at end of file -- cgit v1.2.1 From 6736da739ef32a255d544508bb44905da086dd35 Mon Sep 17 00:00:00 2001 From: Brian Tiffin Date: Thu, 31 Aug 2017 05:10:31 +0000 Subject: example.icn created online with Bitbucket --- tests/examplefiles/example.icn | 283 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 tests/examplefiles/example.icn (limited to 'tests') diff --git a/tests/examplefiles/example.icn b/tests/examplefiles/example.icn new file mode 100644 index 00000000..c8fcf335 --- /dev/null +++ b/tests/examplefiles/example.icn @@ -0,0 +1,283 @@ +# +# $Id: button.icn,v 1.7 2006-07-09 23:43:07 rparlett Exp $ +# +# This file is in the public domain. +# +# Author: Robert Parlett (parlett@dial.pipex.com) +# + +package gui +link graphics + +$include "guih.icn" + + +# +# This is the parent class of the button classes, including +# checkboxes. +# +# A {Button} produces a BUTTON_PRESS_EVENT when the button is +# depressed, and code BUTTON_RELEASE_EVENT when it is released, +# as well as an ACTION_EVENT. +# +# By default, when a button holds the keyboard focus a dashed +# line appears just within the button. Then, when return is +# pressed an ACTION_EVENT is generated. The method +# {Dialog.set_initial_focus()} can be used to have the button +# have the focus when the dialog is first displayed. +# +# Buttons also repeatedly produce a BUTTON_HELD_EVENT whilst they +# are held down, rather like a repeating keyboard press. The +# delay between the initial repeat event and subsequent repeat +# events is set in the parent dialog (see above). +# +class Button : Toggle : Component( + is_down, # + is_held, # + is_checked_flag, # + label, + img_up, # + img_down, # + img_w, # + img_h, # + parent_check_box_group, # + parent_button_group, # + repeat_delay, + no_keyboard_flag, # + toggles_flag + ) + + method set_parent_button_group(x) + return self.parent_button_group := x + end + + # + # Invoking this method disables the keyboard control over the + # button described above. No dashed line will ever appear in + # the button display and return will have no effect on the + # button even if it has the focus. + # + method set_no_keyboard() + self.no_keyboard_flag := 1 + self.accepts_focus_flag := &null + end + + # + # Clear the no keyboard behaviour (the default) + # + method clear_no_keyboard() + self.no_keyboard_flag := &null + self.accepts_focus_flag := 1 + end + + method tick() + if dispatcher.curr_time_of_day() > self.repeat_delay then + fire(BUTTON_HELD_EVENT) + end + + method go_down() + self.is_down := 1 + set_ticker(self.parent_dialog.repeat_rate) + end + + method go_up() + self.is_down := &null + stop_ticker() + end + + method handle_press(e) + local b + if self.in_region() then { + go_down() + self.repeat_delay := dispatcher.curr_time_of_day() + self.parent_dialog.repeat_delay + self.is_held := 1 + every b := !(\self.parent_button_group).buttons do { + if b.is_unhidden() then { + b.is_held := 1 + b.repeat_delay := self.repeat_delay + } + } + self.invalidate() + fire(BUTTON_PRESS_EVENT, e) + } + end + + method handle_drag(e) + if \self.is_held then { + # + # Button held down; toggle on/off as it goes over the button + # + if self.in_region() then { + if /self.is_down then { + go_down() + invalidate() + } + } else { + if \self.is_down then { + go_up() + invalidate() + } + } + } + end + + method handle_release(e) + if \self.is_held then { + self.is_held := &null + if \self.is_down then { + go_up() + fire(BUTTON_RELEASE_EVENT, e) + on_action(e) + } + } + end + + method on_action(e) + if \self.toggles_flag then { + if \self.parent_check_box_group then + self.parent_check_box_group.set_which_one(self) + else + self.toggle_is_checked() + } + self.invalidate() + fire(ACTION_EVENT, e) + end + + method handle_accel(e) + self.Component.handle_accel(e) + on_action(e) + end + + method handle_default(e) + if \self.has_focus then { + if /self.no_keyboard_flag & e == ("\r" | "\l" | " ") then { + on_action(e) + } + } + end + + method handle_event(e) + if e === (&lpress | &rpress | &mpress) then { + handle_press(e) + } else if e === (&ldrag | &rdrag | &mdrag) then { + handle_drag(e) + } else if e === (&lrelease | &rrelease | &mrelease) then { + handle_release(e) + } else + handle_default(e) + end + + # + # Set the up/down images (if any) to the strings provided, + # which should be in Icon image format. + # The two images must have the same dimensions. + # @param x The up image + # @param y The down image + # + method set_imgs(x, y) + self.img_up := x + self.img_w := img_width(x) = img_width(y) | fatal("Image widths differ") + self.img_h := img_height(x) = img_height(y) | fatal("Image heights differ") + + self.img_down := y + + return + end + + # + # Set the image (if any) to the given string, which should be in Icon image + # format. + # @param x The image + # + method set_img(x) + self.img_up := self.img_down := x + self.img_w := img_width(x) + self.img_h := img_height(x) + return x + end + + # + # Toggle the checked status of the button. This method, and + # the following two methods, may be + # inappropriate for non-toggle styles of button. + # + method toggle_is_checked() + self.Toggle.toggle_is_checked() + self.invalidate() + end + + # + # Set the status to checked. + # + method set_is_checked() + self.Toggle.set_is_checked() + self.invalidate() + end + + # + # Set the status to unchecked. + # + method clear_is_checked() + self.Toggle.clear_is_checked() + self.invalidate() + end + + # + # Set the button so that when it is pressed, it toggles + # between two states, as indicated by the is_checked + # flag. + # + # Instances of Checkbox have this flag on by default, but + # TextButton and IconButton do not. When the flag is on, + # the latter classes indicate their checked status by + # showing the button as being "down". + # + method set_toggles() + self.toggles_flag := 1 + self.invalidate() + end + + # + # Clear the toggles flag. + # + method clear_toggles() + self.toggles_flag := &null + self.invalidate() + end + + # + # Set the label of the button, if any. + # @param x The label + # + method set_label(x) + self.label := x + self.invalidate() + return x + end + + method set_one(attr, val) + case attr of { + "label" : set_label(string_val(attr, val)) + "is_checked" : + if test_flag(attr, val) then + set_is_checked() + else + clear_is_checked() + "toggles" : + if test_flag(attr, val) then + set_toggles() + else + clear_toggles() + "no_keyboard" : + if test_flag(attr, val) then + set_no_keyboard() + else + clear_no_keyboard() + default: self.Component.set_one(attr, val) + } + end + + initially() + self.Component.initially() + self.accepts_focus_flag := 1 +end \ No newline at end of file -- cgit v1.2.1 From b60aca2cefb7cecfebf1834b4adf52e7a33f070b Mon Sep 17 00:00:00 2001 From: mppf5 Date: Mon, 25 Sep 2017 15:57:19 -0400 Subject: Updating Chapel highlighter * include new error handling keywords * fix problems with 1-character procs * include Type.method in method name * highlight iterators in addition to procs --- tests/examplefiles/99_bottles_of_beer.chpl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/99_bottles_of_beer.chpl b/tests/examplefiles/99_bottles_of_beer.chpl index cdc1e650..80d2a89e 100644 --- a/tests/examplefiles/99_bottles_of_beer.chpl +++ b/tests/examplefiles/99_bottles_of_beer.chpl @@ -177,3 +177,23 @@ private module M3 { private var x: int; } +prototype module X { + + proc f() throws { + throw new Error(); + } + + proc g() { + try { + f(); + try! f(); + } catch e { + writeln("Caught ", e); + } + } + + proc int.add() { } + + g(); +} + -- cgit v1.2.1 From 47fd1dc317a09cce2e16b8ccd8e52cd7dd5b37d9 Mon Sep 17 00:00:00 2001 From: Fredrik Larsen Date: Fri, 10 Nov 2017 17:22:12 +0100 Subject: Fix issue with markdown lexer code fences Fixes the bug reported in #1389, where the markdown lexer will not issue a token for the closing code fence. Issue: #1389 --- tests/test_markdown_lexer.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_markdown_lexer.py (limited to 'tests') diff --git a/tests/test_markdown_lexer.py b/tests/test_markdown_lexer.py new file mode 100644 index 00000000..16d1f28d --- /dev/null +++ b/tests/test_markdown_lexer.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +""" + Pygments regex lexer tests + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import unittest + +from pygments.lexers.markup import MarkdownLexer + + +class SameTextTests(unittest.TestCase): + + lexer = MarkdownLexer() + + def assert_same_text(self, text): + """Show that lexed markdown does not remove any content. """ + tokens = list(self.lexer.get_tokens_unprocessed(text)) + output = ''.join(t[2] for t in tokens) + self.assertEqual(text, output) + + def test_code_fence(self): + self.assert_same_text(r'```\nfoo\n```\n') + + def test_code_fence_gsm(self): + self.assert_same_text(r'```markdown\nfoo\n```\n') + + def test_code_fence_gsm_with_no_lexer(self): + self.assert_same_text(r'```invalid-lexer\nfoo\n```\n') -- cgit v1.2.1 From 6037043e01b2a096d39883f9f7dd27cdcfe8d0ab Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 22 Feb 2018 14:15:07 +0000 Subject: Markdown: add support for reference-style links --- tests/examplefiles/example.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/example.md b/tests/examplefiles/example.md index 2befb107..e2bbacf1 100644 --- a/tests/examplefiles/example.md +++ b/tests/examplefiles/example.md @@ -46,6 +46,9 @@ this sentence @tweets a person about a #topic. [google](https://google.com/some/path.html) ![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png) +[reference link][id] +[id]: http://example.com/ + ``` * this is just unformated __text__ -- cgit v1.2.1 From 9ddc62fd449592eaee42b4026884b976b2fb3b64 Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Sat, 4 Aug 2018 19:43:17 +0200 Subject: Change ansi color names to more saying names The ansi color names are changed to names which are easier to understand and align with color names of other projects and terminals. (e.g. ``#ansifuchsia`` to ``ansibrightmagenta``) This also drops the # prefix to the color names. Hashtag # is usually used for hex colors and the names are already prefixed with `ansi`. Furthermore, it allows the new and old set of names to be exclusive. --- tests/test_terminal_formatter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_terminal_formatter.py b/tests/test_terminal_formatter.py index ee0ac380..1f44807d 100644 --- a/tests/test_terminal_formatter.py +++ b/tests/test_terminal_formatter.py @@ -61,10 +61,10 @@ class TerminalFormatterTest(unittest.TestCase): class MyStyle(Style): styles = { - Token.Comment: '#ansidarkgray', - Token.String: '#ansiblue bg:#ansidarkred', - Token.Number: '#ansigreen bg:#ansidarkgreen', - Token.Number.Hex: '#ansidarkgreen bg:#ansired', + Token.Comment: 'ansibrightblack', + Token.String: 'ansibrightblue bg:ansired', + Token.Number: 'ansibrightgreen bg:ansigreen', + Token.Number.Hex: 'ansigreen bg:ansibrightred', } @@ -90,7 +90,7 @@ async def function(a,b,c, *d, **kwarg:Bool)->Bool: def test_256esc_seq(self): """ - test that a few escape sequences are actualy used when using #ansi<> color codes + test that a few escape sequences are actualy used when using ansi<> color codes """ def termtest(x): return highlight(x, Python3Lexer(), -- cgit v1.2.1 From cda7b0a58d2b80293e365de9ccd38dadeb957720 Mon Sep 17 00:00:00 2001 From: mppf5 Date: Mon, 10 Sep 2018 14:48:28 -0400 Subject: example shows new keywords --- tests/examplefiles/99_bottles_of_beer.chpl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/examplefiles/99_bottles_of_beer.chpl b/tests/examplefiles/99_bottles_of_beer.chpl index 80d2a89e..ff50b294 100644 --- a/tests/examplefiles/99_bottles_of_beer.chpl +++ b/tests/examplefiles/99_bottles_of_beer.chpl @@ -195,5 +195,12 @@ prototype module X { proc int.add() { } g(); + + override proc test() throws { + var a = new borrowed IntPair(); + var b = new owned IntPair(); + var c = new shared IntPair(); + throw new unmanaged Error(); + } } -- cgit v1.2.1 From 473d784cddb1c6907d6d01f437b2934d48e63fe2 Mon Sep 17 00:00:00 2001 From: "Stephane\"" Date: Sun, 21 Oct 2018 17:25:33 +0200 Subject: Add SGF lexer --- tests/examplefiles/example.sgf | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/examplefiles/example.sgf (limited to 'tests') diff --git a/tests/examplefiles/example.sgf b/tests/examplefiles/example.sgf new file mode 100644 index 00000000..024a461e --- /dev/null +++ b/tests/examplefiles/example.sgf @@ -0,0 +1,35 @@ +(;FF[4]GM[1]SZ[19]FG[257:Figure 1]PM[1] +PB[Takemiya Masaki]BR[9 dan]PW[Cho Chikun] +WR[9 dan]RE[W+Resign]KM[5.5]TM[28800]DT[1996-10-18,19] +EV[21st Meijin]RO[2 (final)]SO[Go World #78]US[Arno Hollosi] +;B[pd];W[dp];B[pp];W[dd];B[pj];W[nc];B[oe];W[qc];B[pc];W[qd] +(;B[qf];W[rf];B[rg];W[re];B[qg];W[pb];B[ob];W[qb] +(;B[mp];W[fq];B[ci];W[cg];B[dl];W[cn];B[qo];W[ec];B[jp];W[jd] +;B[ei];W[eg];B[kk]LB[qq:a][dj:b][ck:c][qp:d]N[Figure 1] + +;W[me]FG[257:Figure 2];B[kf];W[ke];B[lf];W[jf];B[jg] +(;W[mf];B[if];W[je];B[ig];W[mg];B[mj];W[mq];B[lq];W[nq] +(;B[lr];W[qq];B[pq];W[pr];B[rq];W[rr];B[rp];W[oq];B[mr];W[oo];B[mn] +(;W[nr];B[qp]LB[kd:a][kh:b]N[Figure 2] + +;W[pk]FG[257:Figure 3];B[pm];W[oj];B[ok];W[qr];B[os];W[ol];B[nk];W[qj] +;B[pi];W[pl];B[qm];W[ns];B[sr];W[om];B[op];W[qi];B[oi] +(;W[rl];B[qh];W[rm];B[rn];W[ri];B[ql];W[qk];B[sm];W[sk];B[sh];W[og] +;B[oh];W[np];B[no];W[mm];B[nn];W[lp];B[kp];W[lo];B[ln];W[ko];B[mo] +;W[jo];B[km]N[Figure 3]) + +(;W[ql]VW[ja:ss]FG[257:Dia. 6]MN[1];B[rm];W[ph];B[oh];W[pg];B[og];W[pf] +;B[qh];W[qe];B[sh];W[of];B[sj]TR[oe][pd][pc][ob]LB[pe:a][sg:b][si:c] +N[Diagram 6])) + +(;W[no]VW[jj:ss]FG[257:Dia. 5]MN[1];B[pn]N[Diagram 5])) + +(;B[pr]FG[257:Dia. 4]MN[1];W[kq];B[lp];W[lr];B[jq];W[jr];B[kp];W[kr];B[ir] +;W[hr]LB[is:a][js:b][or:c]N[Diagram 4])) + +(;W[if]FG[257:Dia. 3]MN[1];B[mf];W[ig];B[jh]LB[ki:a]N[Diagram 3])) + +(;W[oc]VW[aa:sk]FG[257:Dia. 2]MN[1];B[md];W[mc];B[ld]N[Diagram 2])) + +(;B[qe]VW[aa:sj]FG[257:Dia. 1]MN[1];W[re];B[qf];W[rf];B[qg];W[pb];B[ob] +;W[qb]LB[rg:a]N[Diagram 1])) -- cgit v1.2.1 From c1255470b48207d060454abcf2a0b3709db5904b Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Fri, 16 Nov 2018 18:11:03 -0800 Subject: Add support for the Fennel programming language This is a pretty straightforward language in the lisp family with a small number of special forms. Since Fennel runs on the Lua runtime, the list of builtins is the same as that of Lua, so it might be possible to re-use the definition from the Lua lexer, but since I don't know Python I couldn't figure out how that would work; maybe someone else could add that. --- tests/examplefiles/fennelview.fnl | 156 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 tests/examplefiles/fennelview.fnl (limited to 'tests') diff --git a/tests/examplefiles/fennelview.fnl b/tests/examplefiles/fennelview.fnl new file mode 100644 index 00000000..fd0fc648 --- /dev/null +++ b/tests/examplefiles/fennelview.fnl @@ -0,0 +1,156 @@ +;; A pretty-printer that outputs tables in Fennel syntax. +;; Loosely based on inspect.lua: http://github.com/kikito/inspect.lua + +(local quote (fn [str] (.. '"' (: str :gsub '"' '\\"') '"'))) + +(local short-control-char-escapes + {"\a" "\\a" "\b" "\\b" "\f" "\\f" "\n" "\\n" + "\r" "\\r" "\t" "\\t" "\v" "\\v"}) + +(local long-control-char-esapes + (let [long {}] + (for [i 0 31] + (let [ch (string.char i)] + (when (not (. short-control-char-escapes ch)) + (tset short-control-char-escapes ch (.. "\\" i)) + (tset long ch (: "\\%03d" :format i))))) + long)) + +(fn escape [str] + (let [str (: str :gsub "\\" "\\\\") + str (: str :gsub "(%c)%f[0-9]" long-control-char-esapes)] + (: str :gsub "%c" short-control-char-escapes))) + +(fn sequence-key? [k len] + (and (= (type k) "number") + (<= 1 k) + (<= k len) + (= (math.floor k) k))) + +(local type-order {:number 1 :boolean 2 :string 3 :table 4 + :function 5 :userdata 6 :thread 7}) + +(fn sort-keys [a b] + (let [ta (type a) tb (type b)] + (if (and (= ta tb) (~= ta "boolean") + (or (= ta "string") (= ta "number"))) + (< a b) + (let [dta (. type-order a) + dtb (. type-order b)] + (if (and dta dtb) + (< dta dtb) + dta true + dtb false + :else (< ta tb)))))) + +(fn get-sequence-length [t] + (var len 1) + (each [i (ipairs t)] (set len i)) + len) + +(fn get-nonsequential-keys [t] + (let [keys {} + sequence-length (get-sequence-length t)] + (each [k (pairs t)] + (when (not (sequence-key? k sequence-length)) + (table.insert keys k))) + (table.sort keys sort-keys) + (values keys sequence-length))) + +(fn count-table-appearances [t appearances] + (if (= (type t) "table") + (when (not (. appearances t)) + (tset appearances t 1) + (each [k v (pairs t)] + (count-table-appearances k appearances) + (count-table-appearances v appearances))) + (when (and t (= t t)) ; no nans please + (tset appearances t (+ (or (. appearances t) 0) 1)))) + appearances) + + + +(var put-value nil) ; mutual recursion going on; defined below + +(fn puts [self ...] + (each [_ v (ipairs [...])] + (table.insert self.buffer v))) + +(fn tabify [self] (puts self "\n" (: self.indent :rep self.level))) + +(fn already-visited? [self v] (~= (. self.ids v) nil)) + +(fn get-id [self v] + (var id (. self.ids v)) + (when (not id) + (let [tv (type v)] + (set id (+ (or (. self.max-ids tv) 0) 1)) + (tset self.max-ids tv id) + (tset self.ids v id))) + (tostring id)) + +(fn put-sequential-table [self t length] + (puts self "[") + (set self.level (+ self.level 1)) + (for [i 1 length] + (puts self " ") + (put-value self (. t i))) + (set self.level (- self.level 1)) + (puts self " ]")) + +(fn put-key [self k] + (if (and (= (type k) "string") + (: k :find "^[-%w?\\^_`!#$%&*+./@~:|<=>]+$")) + (puts self ":" k) + (put-value self k))) + +(fn put-kv-table [self t] + (puts self "{") + (set self.level (+ self.level 1)) + (each [k v (pairs t)] + (tabify self) + (put-key self k) + (puts self " ") + (put-value self v)) + (set self.level (- self.level 1)) + (tabify self) + (puts self "}")) + +(fn put-table [self t] + (if (already-visited? self t) + (puts self "#") + (>= self.level self.depth) + (puts self "{...}") + :else + (let [(non-seq-keys length) (get-nonsequential-keys t) + id (get-id self t)] + (if (> (. self.appearances t) 1) + (puts self "#<" id ">") + (and (= (# non-seq-keys) 0) (= (# t) 0)) + (puts self "{}") + (= (# non-seq-keys) 0) + (put-sequential-table self t length) + :else + (put-kv-table self t))))) + +(set put-value (fn [self v] + (let [tv (type v)] + (if (= tv "string") + (puts self (quote (escape v))) + (or (= tv "number") (= tv "boolean") (= tv "nil")) + (puts self (tostring v)) + (= tv "table") + (put-table self v) + :else + (puts self "#<" (tostring v) ">"))))) + + + +(fn fennelview [root options] + (let [options (or options {}) + inspector {:appearances (count-table-appearances root {}) + :depth (or options.depth 128) + :level 0 :buffer {} :ids {} :max-ids {} + :indent (or options.indent " ")}] + (put-value inspector root) + (table.concat inspector.buffer))) -- cgit v1.2.1 From 7fa421fd738fb31a4fb7148f089251fb55a21583 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 25 Nov 2018 10:41:28 +0100 Subject: Clean lexer: better support for qualified imports; add tests --- tests/examplefiles/StdGeneric.icl | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/examplefiles/StdGeneric.icl b/tests/examplefiles/StdGeneric.icl index 2e6c3931..891b510a 100644 --- a/tests/examplefiles/StdGeneric.icl +++ b/tests/examplefiles/StdGeneric.icl @@ -1,5 +1,13 @@ implementation module StdGeneric +/** + * NOTE: this is a collection of different tricky parts of Clean modules (even + * though the file is simply called StdGeneric.icl). The code is taken from: + * + * - StdGeneric (StdEnv) + * - Graphics.Scalable.Image (Platform) + */ + import StdInt, StdMisc, StdClass, StdFunc generic bimap a b :: Bimap .a .b @@ -89,4 +97,38 @@ where = [ ConsLeft : doit i (n/2) ] | otherwise = [ ConsRight : doit (i - (n/2)) (n - (n/2)) ] - \ No newline at end of file + +:: NoAttr m = NoAttr +:: DashAttr m = { dash :: ![Int] } +:: FillAttr m = { fill :: !SVGColor } +:: LineEndMarker m = { endmarker :: !Image m } +:: LineMidMarker m = { midmarker :: !Image m } +:: LineStartMarker m = { startmarker :: !Image m } +:: MaskAttr m = { mask :: !Image m } +:: OpacityAttr m = { opacity :: !Real } +:: StrokeAttr m = { stroke :: !SVGColor } +:: StrokeWidthAttr m = { strokewidth :: !Span } +:: XRadiusAttr m = { xradius :: !Span } +:: YRadiusAttr m = { yradius :: !Span } + + +instance tuneImage NoAttr where tuneImage image _ = image +instance tuneImage DashAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgDashAttr attr.DashAttr.dash)) image +instance tuneImage FillAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgFillAttr attr.FillAttr.fill)) image +instance tuneImage LineEndMarker where tuneImage image attr = Attr` (LineMarkerAttr` {LineMarkerAttr | markerImg = attr.LineEndMarker.endmarker, markerPos = LineMarkerEnd}) image +instance tuneImage LineMidMarker where tuneImage image attr = Attr` (LineMarkerAttr` {LineMarkerAttr | markerImg = attr.LineMidMarker.midmarker, markerPos = LineMarkerMid}) image +instance tuneImage LineStartMarker where tuneImage image attr = Attr` (LineMarkerAttr` {LineMarkerAttr | markerImg = attr.LineStartMarker.startmarker, markerPos = LineMarkerStart}) image +instance tuneImage MaskAttr where tuneImage image attr = Attr` (MaskAttr` attr.MaskAttr.mask) image +instance tuneImage OpacityAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgFillOpacityAttr attr.OpacityAttr.opacity)) image +instance tuneImage StrokeAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgStrokeAttr attr.StrokeAttr.stroke)) image +instance tuneImage StrokeWidthAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgStrokeWidthAttr attr.StrokeWidthAttr.strokewidth)) image +instance tuneImage XRadiusAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgXRadiusAttr attr.XRadiusAttr.xradius)) image +instance tuneImage YRadiusAttr where tuneImage image attr = Attr` (BasicImageAttr` (BasicImgYRadiusAttr attr.YRadiusAttr.yradius)) image + +instance tuneImage DraggableAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerDraggableAttr attr)) image +instance tuneImage OnClickAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnClickAttr attr)) image +instance tuneImage OnMouseDownAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseDownAttr attr)) image +instance tuneImage OnMouseMoveAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseMoveAttr attr)) image +instance tuneImage OnMouseOutAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseOutAttr attr)) image +instance tuneImage OnMouseOverAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseOverAttr attr)) image +instance tuneImage OnMouseUpAttr where tuneImage image attr = Attr` (HandlerAttr` (ImgEventhandlerOnMouseUpAttr attr)) image -- cgit v1.2.1 From 075938a7748906f9d20981b90d07cab30b3a3121 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Nov 2018 05:54:28 +0100 Subject: Handle regex syntax FutureWarnings. Make sure they are converted to errors in test runs, to catch new introductions immediately. --- tests/run.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index 07665b2a..bdaceb7e 100644 --- a/tests/run.py +++ b/tests/run.py @@ -16,6 +16,7 @@ from __future__ import print_function import os import sys +import warnings # only find tests in this directory if os.path.dirname(__file__): @@ -31,6 +32,9 @@ except ImportError: # make sure the current source is first on sys.path sys.path.insert(0, '..') +# make FutureWarnings (coming from Regex syntax most likely) an error +warnings.filterwarnings("error", category=FutureWarning) + if '--with-coverage' not in sys.argv: # if running with coverage, pygments should not be imported before coverage # is started, otherwise it will count already executed lines as uncovered -- cgit v1.2.1 From cdb2a89a25131f46a09a5497e56196c2fe69e184 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Nov 2018 15:49:16 +0100 Subject: Fix invalid escapes due to missing raw string prefix. --- tests/run.py | 6 ++++++ tests/test_html_formatter.py | 4 ++-- tests/test_rtf_formatter.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/run.py b/tests/run.py index 07665b2a..41279bef 100644 --- a/tests/run.py +++ b/tests/run.py @@ -16,6 +16,7 @@ from __future__ import print_function import os import sys +import warnings # only find tests in this directory if os.path.dirname(__file__): @@ -31,6 +32,11 @@ except ImportError: # make sure the current source is first on sys.path sys.path.insert(0, '..') +# make FutureWarnings (coming from Regex syntax most likely) and +# DeprecationWarnings (coming from invalid escapes due to non-raw strings) +# an error +warnings.filterwarnings("error", category=DeprecationWarning) + if '--with-coverage' not in sys.argv: # if running with coverage, pygments should not be imported before coverage # is started, otherwise it will count already executed lines as uncovered diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py index 79990edd..10450c56 100644 --- a/tests/test_html_formatter.py +++ b/tests/test_html_formatter.py @@ -100,7 +100,7 @@ class HtmlFormatterTest(unittest.TestCase): fmt = HtmlFormatter(**optdict) fmt.format(tokensource, outfile) html = outfile.getvalue() - self.assertTrue(re.search("
\s+1\s+2\s+3", html))
+        self.assertTrue(re.search(r"
\s+1\s+2\s+3", html))
 
     def test_linenos_with_startnum(self):
         optdict = dict(linenos=True, linenostart=5)
@@ -108,7 +108,7 @@ class HtmlFormatterTest(unittest.TestCase):
         fmt = HtmlFormatter(**optdict)
         fmt.format(tokensource, outfile)
         html = outfile.getvalue()
-        self.assertTrue(re.search("
\s+5\s+6\s+7", html))
+        self.assertTrue(re.search(r"
\s+5\s+6\s+7", html))
 
     def test_lineanchors(self):
         optdict = dict(lineanchors="foo")
diff --git a/tests/test_rtf_formatter.py b/tests/test_rtf_formatter.py
index 756c03a9..44da5768 100644
--- a/tests/test_rtf_formatter.py
+++ b/tests/test_rtf_formatter.py
@@ -80,7 +80,7 @@ class RtfFormatterTest(StringTests, unittest.TestCase):
         self.assertEndsWith(result, expected+self.foot, msg)
 
     def test_escape_characters(self):
-        t = u'\ {{'
+        t = u'\\ {{'
         result = self.format_rtf(t)
         expected = (r'\\ \{\{')
         if not result.endswith(self.foot):
-- 
cgit v1.2.1


From cd850106ed356cd56c2bf19e0eebd75c42780556 Mon Sep 17 00:00:00 2001
From: Georg Brandl 
Date: Wed, 28 Nov 2018 16:42:15 +0100
Subject: Fix more instances of invalid string escapes

Also, raise on warnings from Pygments only.
---
 tests/run.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

(limited to 'tests')

diff --git a/tests/run.py b/tests/run.py
index 161e5c04..2e962f2f 100644
--- a/tests/run.py
+++ b/tests/run.py
@@ -22,6 +22,13 @@ import warnings
 if os.path.dirname(__file__):
     os.chdir(os.path.dirname(__file__))
 
+# make FutureWarnings (coming from Regex syntax most likely) and
+# DeprecationWarnings due to non-raw strings an error
+warnings.filterwarnings("error", module=r"pygments\..*",
+                        category=FutureWarning)
+warnings.filterwarnings("error", module=r".*pygments.*",
+                        category=DeprecationWarning)
+
 
 try:
     import nose
@@ -32,12 +39,6 @@ except ImportError:
 # make sure the current source is first on sys.path
 sys.path.insert(0, '..')
 
-# make FutureWarnings (coming from Regex syntax most likely) and
-# DeprecationWarnings (coming from invalid escapes due to non-raw strings)
-# an error
-warnings.filterwarnings("error", category=FutureWarning)
-warnings.filterwarnings("error", category=DeprecationWarning)
-
 if '--with-coverage' not in sys.argv:
     # if running with coverage, pygments should not be imported before coverage
     # is started, otherwise it will count already executed lines as uncovered
-- 
cgit v1.2.1


From 86d2528cee60fd6e0e7a94bbac797eefeafec6eb Mon Sep 17 00:00:00 2001
From: James Edwards 
Date: Wed, 5 Dec 2018 00:46:05 +0000
Subject: Added newer Terraform keywords.

---
 tests/examplefiles/example.tf | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

(limited to 'tests')

diff --git a/tests/examplefiles/example.tf b/tests/examplefiles/example.tf
index 5a85dbee..50082616 100644
--- a/tests/examplefiles/example.tf
+++ b/tests/examplefiles/example.tf
@@ -23,6 +23,14 @@ variable "aws_amis" {
 }
 
 
+resource "aws_internet_gateway" "base_igw" {
+  vpc_id = "${aws_vpc.something.id}"
+  tags {
+    Name = "igw-${var.something}-${var.something}"
+  }
+}
+
+
 
 
 
@@ -170,3 +178,30 @@ resource "aws_instance" "web" {
   }
 }
 
+
+
+resource "aws_autoscaling_group" "bar" {
+  name                 = "terraform-asg-example"
+  launch_configuration = "${aws_launch_configuration.as_conf.name}"
+  min_size             = 1
+  max_size             = 2
+
+  lifecycle {
+    create_before_destroy = true
+  }
+}
+
+
+resource "aws_db_instance" "timeout_example" {
+  allocated_storage = 10
+  engine            = "mysql"
+  engine_version    = "5.6.17"
+  instance_class    = "db.t1.micro"
+  name              = "mydb"
+  timeouts {
+    create = "60m"
+    delete = "2h"
+  }
+}
+
+
-- 
cgit v1.2.1


From 78d3f931c52041d71120ba8b8b02972b2fc8b4f4 Mon Sep 17 00:00:00 2001
From: James Edwards 
Date: Wed, 5 Dec 2018 01:06:25 +0000
Subject: Fixed typos in terraform lexer

---
 tests/examplefiles/example.tf | 1 +
 1 file changed, 1 insertion(+)

(limited to 'tests')

diff --git a/tests/examplefiles/example.tf b/tests/examplefiles/example.tf
index 50082616..4cbef52c 100644
--- a/tests/examplefiles/example.tf
+++ b/tests/examplefiles/example.tf
@@ -198,6 +198,7 @@ resource "aws_db_instance" "timeout_example" {
   engine_version    = "5.6.17"
   instance_class    = "db.t1.micro"
   name              = "mydb"
+
   timeouts {
     create = "60m"
     delete = "2h"
-- 
cgit v1.2.1


From 76621e29863a35fb4381f0db9d6c84f1417930a5 Mon Sep 17 00:00:00 2001
From: "Matth?us G. Chajdas" 
Date: Mon, 17 Dec 2018 19:36:35 +0100
Subject: Add FloScript sample file, update mappings & changes.

---
 tests/examplefiles/example.flo | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 tests/examplefiles/example.flo

(limited to 'tests')

diff --git a/tests/examplefiles/example.flo b/tests/examplefiles/example.flo
new file mode 100644
index 00000000..2d4ab5e7
--- /dev/null
+++ b/tests/examplefiles/example.flo
@@ -0,0 +1,40 @@
+#example mission box1.flo
+#from: https://github.com/ioflo/ioflo
+
+house box1
+
+   framer vehiclesim be active first vehicle_run
+      frame vehicle_run
+         do simulator motion uuv
+
+   framer mission be active first northleg
+      frame northleg
+         set elapsed with 20.0
+         set heading with 0.0
+         set depth with 5.0
+         set speed with 2.5
+         go next if elapsed >= goal
+
+      frame eastleg
+         set heading with 90.0
+         go next if elapsed >= goal
+
+      frame southleg
+         set heading with 180.0
+         go next if elapsed >= goal
+
+      frame westleg
+         set heading with 270.0
+         go next if elapsed >= goal
+
+      frame mission_stop
+         bid stop vehiclesim
+         bid stop autopilot
+         bid stop me
+
+   framer autopilot be active first autopilot_run
+      frame autopilot_run
+         do controller pid speed
+         do controller pid heading
+         do controller pid depth
+         do controller pid pitch
\ No newline at end of file
-- 
cgit v1.2.1


From 6c9c585cc788aceb6798e059cfe1a0820577a3d6 Mon Sep 17 00:00:00 2001
From: "Matth?us G. Chajdas" 
Date: Fri, 21 Dec 2018 17:34:15 +0100
Subject: Small cleanups to the Slurm lexer.

Remove debug output, add a test file for the Slurm lexer.
---
 tests/examplefiles/example.sl | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 tests/examplefiles/example.sl

(limited to 'tests')

diff --git a/tests/examplefiles/example.sl b/tests/examplefiles/example.sl
new file mode 100644
index 00000000..5fb430de
--- /dev/null
+++ b/tests/examplefiles/example.sl
@@ -0,0 +1,6 @@
+#!/bin/bash
+#SBATCH --partition=part
+#SBATCH --job-name=job
+#SBATCH --mem=1G
+#SBATCH --cpus-per-task=8
+srun /usr/bin/sleep
\ No newline at end of file
-- 
cgit v1.2.1


From 899884637800cbe1b2c913647016bf98a54cbb20 Mon Sep 17 00:00:00 2001
From: "Matth?us G. Chajdas" 
Date: Sun, 23 Dec 2018 13:37:14 +0100
Subject: Fix Stan lexer changes eating whitespace, fix typos in example file.

---
 tests/examplefiles/example.stan | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'tests')

diff --git a/tests/examplefiles/example.stan b/tests/examplefiles/example.stan
index 69c9ac70..03b7b1b5 100644
--- a/tests/examplefiles/example.stan
+++ b/tests/examplefiles/example.stan
@@ -16,7 +16,7 @@ functions {
 data {
   // valid name
   int abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abc;
-  // all types should be highlighed
+  // all types should be highlighted
   int a3;
   real foo[2];
   vector[3] bar;
@@ -48,7 +48,7 @@ transformed data {
   thud <- -12309865;
   // ./ and .* should be recognized as operators
   grault2 <- grault .* garply ./ garply;
-  // ' and \ should be regognized as operators
+  // ' and \ should be recognized as operators
   qux2 <- qux' \ bar;
   
 }
-- 
cgit v1.2.1


From 810e049f65b44e06dbfd7c8800750a6230f93b39 Mon Sep 17 00:00:00 2001
From: Micka?l Schoentgen 
Date: Mon, 7 Jan 2019 18:20:59 +0100
Subject: Fix ResourceWarning: unclosed file

Also uniformize usage of the 'with' contact manager to prevent resource leaks.
---
 tests/test_html_formatter.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

(limited to 'tests')

diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py
index 10450c56..670a5be9 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -132,9 +132,8 @@ class HtmlFormatterTest(unittest.TestCase):
                             outencoding='utf-8')
 
         handle, pathname = tempfile.mkstemp('.html')
-        tfile = os.fdopen(handle, 'w+b')
-        fmt.format(tokensource, tfile)
-        tfile.close()
+        with os.fdopen(handle, 'w+b') as tfile:
+            fmt.format(tokensource, tfile)
         catname = os.path.join(TESTDIR, 'dtds', 'HTML4.soc')
         try:
             import subprocess
@@ -173,9 +172,8 @@ class HtmlFormatterTest(unittest.TestCase):
                             cssstyles=u'div:before { content: \'bäz\' }',
                             encoding='utf-8')
         handle, pathname = tempfile.mkstemp('.html')
-        tfile = os.fdopen(handle, 'w+b')
-        fmt.format(tokensource, tfile)
-        tfile.close()
+        with os.fdopen(handle, 'w+b') as tfile:
+            fmt.format(tokensource, tfile)
 
     def test_ctags(self):
         try:
-- 
cgit v1.2.1


From af0e2a48443e501d1eebfc69e92b35f36752a951 Mon Sep 17 00:00:00 2001
From: Nikolay Orlyuk 
Date: Thu, 17 Jan 2019 23:30:33 +0100
Subject: Use unicode literals in docstrings as well

Resolves #1492
---
 tests/test_cmdline.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

(limited to 'tests')

diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 1500c875..a55e30ec 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -28,6 +28,13 @@ def func(args):
 '''
 
 
+def _decode_output(text):
+    try:
+        return text.decode('utf-8')
+    except UnicodeEncodeError:  # implicit encode on Python 2 with data loss
+        return text
+
+
 def run_cmdline(*args, **kwds):
     saved_stdin = sys.stdin
     saved_stdout = sys.stdout
@@ -53,9 +60,9 @@ def run_cmdline(*args, **kwds):
         sys.stderr = saved_stderr
     new_stdout.flush()
     new_stderr.flush()
-    out, err = stdout_buffer.getvalue().decode('utf-8'), \
-        stderr_buffer.getvalue().decode('utf-8')
-    return (ret, out, err)
+    out, err = stdout_buffer.getvalue(), \
+        stderr_buffer.getvalue()
+    return (ret, _decode_output(out), _decode_output(err))
 
 
 class CmdLineTest(unittest.TestCase):
-- 
cgit v1.2.1


From 53a39c2b6dc9d2e7b73943c842f698ce8f60258d Mon Sep 17 00:00:00 2001
From: "Matth?us G. Chajdas" 
Date: Tue, 12 Feb 2019 16:28:16 +0100
Subject: Improve CSound name handling.

This should fix the last of the spurious errors we're seeing in CI.
---
 tests/test_csound.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

(limited to 'tests')

diff --git a/tests/test_csound.py b/tests/test_csound.py
index 4d10c267..d493bd04 100644
--- a/tests/test_csound.py
+++ b/tests/test_csound.py
@@ -478,3 +478,14 @@ class CsoundOrchestraTest(unittest.TestCase):
             (Text, u'\n')
         ]
         self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+
+    def testName(self):
+        fragment = 'kG:V'
+        tokens = [
+            (Keyword.Type, 'k'),
+            (Name, 'G'),
+            (Punctuation, ':'),
+            (Name, 'V'),
+            (Text, '\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
-- 
cgit v1.2.1


From a3a6f24f62652d7eee55bd5fb557d631c5adf69d Mon Sep 17 00:00:00 2001
From: Matthias Diener 
Date: Tue, 12 Feb 2019 09:35:54 -0600
Subject: Add test for the Charmci lexer

---
 tests/examplefiles/Charmci.ci | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 tests/examplefiles/Charmci.ci

(limited to 'tests')

diff --git a/tests/examplefiles/Charmci.ci b/tests/examplefiles/Charmci.ci
new file mode 100644
index 00000000..2e5cd5c6
--- /dev/null
+++ b/tests/examplefiles/Charmci.ci
@@ -0,0 +1,20 @@
+module CkCallback {
+	readonly CProxy_ckcallback_group _ckcallbackgroup;
+	message CkCcsRequestMsg {
+		char data[];
+ 	};
+	message CkDataMsg {
+		char data[];
+	};
+	
+	mainchare ckcallback_main {
+		entry ckcallback_main(CkArgMsg *m);
+	};
+	group [migratable] ckcallback_group : IrrGroup {
+		entry ckcallback_group();
+		entry void registerCcsCallback(char name[strlen(name)+1],
+			CkCallback cb);
+		entry void call(CkCallback c,CkMarshalledMessage msg);
+		entry void call(CkCallback c, int length, char data[length]);
+	};
+};
-- 
cgit v1.2.1


From 665f287849402bdf05ef636e77989104e6cf8e9e Mon Sep 17 00:00:00 2001
From: Charles Ferguson 
Date: Thu, 14 Mar 2019 22:24:08 +0000
Subject: Create a Lexer class for BBC Basic files.

The Lexer class for BBC Basic handles both the numbered lines, and
unnumbered lines, of the detokenised (text) format of BBC BASIC.
The tokeniser copes, in a naive manner, with the orignal versions,
and BASIC V. It does not handle other extensions at this time, nor
does it handle inline assembler. This should be sufficient for most
cases where code needs to be presented in a colourful manner.
---
 tests/examplefiles/example.bbc | 156 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 tests/examplefiles/example.bbc

(limited to 'tests')

diff --git a/tests/examplefiles/example.bbc b/tests/examplefiles/example.bbc
new file mode 100644
index 00000000..ebdb8537
--- /dev/null
+++ b/tests/examplefiles/example.bbc
@@ -0,0 +1,156 @@
+10REM >EIRC
+20REM The simplest IRC client you can write. Maybe.
+30REM (C) Justin Fletcher, 1998
+40:
+50END=PAGE+1024*16
+60REM Change these if you wish
+70host$="irc.stealth.net"
+80port=6667
+90nick$="eirc"
+100ourchan$="#acorn"
+110:
+120REM Start connecting to a host
+130SYS "ESocket_ConnectToHost",host$,port TO handle
+140REPEAT
+150 SYS "ESocket_CheckState",handle TO state
+160 IF state<-1 THENSYS "ESocket_Forget",handle:SYS "ESocket_DecodeState",state TO a$:ERROR 1,"Failed ("+a$+")"
+170UNTIL state=4
+180:
+190REM We are now connected
+200PRINT"Connected"
+210:
+220REM Log on to the server
+230SYS "ESocket_SendLine",handle,"USER "+nick$+" x x :"+nick$
+240SYS "ESocket_SendLine",handle,"NICK "+nick$
+250SYS "ESocket_SendLine",handle,"JOIN "+ourchan$
+260REM Install a monitor so that we don't waste time
+270SYS "ESocket_Monitor",0,handle TO monitor
+280SYS "ESocket_ResetMonitor",monitor,0 TO polladdr%
+290:
+300REM If we crash, we should tidy up after ourselves
+310ON ERROR SYS "XESocket_Forget",handle:SYS "XESocket_Forget",monitor:ERROR EXT ERR,REPORT$+" at line "+STR$ERL
+320:
+330REM Memory buffer for our data
+340bufsize%=1024
+350DIM buf% bufsize%
+360:
+370input$="":REM The input line
+380REPEAT
+390 REM In a taskwindow we should yield until there is data
+400 SYS "OS_UpCall",6,polladdr%
+410 IF !polladdr%<>0 THEN
+420  REM Reset the monitor for the time being
+430  SYS "ESocket_ResetMonitor",monitor,0 TO polladdr%
+440  REPEAT
+450   REM Read lines from the connection until this buffer is empty
+460   SYS "ESocket_ReadLine",handle,buf%,bufsize%,%100 TO ,str,len
+470   IF str<>0 AND $str<>"" THEN
+480    line$=$str
+490    IF LEFT$(line$,4)="PING" THEN
+500     REM Ping's must be replied to immediately
+510     SYS "ESocket_SendLine",handle,"PONG "+MID$(line$,6)
+520    ELSE
+530     REM Extract source info
+540     from$=MID$(LEFT$(line$,INSTR(line$+" "," ")-1),2)
+550     line$=MID$(line$,INSTR(line$+" "," ")+1)
+560     uid$=LEFT$(from$,INSTR(from$+"!","!")-1)
+570     com$=LEFT$(line$,INSTR(line$+" "," ")-1)
+580     line$=MID$(line$,INSTR(line$+" "," ")+1)
+590     REM remove the input line
+600     IF input$<>"" THENFORI=1TOLEN(input$):VDU127:NEXT
+610     CASE FNupper(com$) OF
+620      WHEN "PRIVMSG"
+630       REM Extract the destination
+640       chan$=LEFT$(line$,INSTR(line$+" "," ")-1)
+650       line$=MID$(line$,INSTR(line$+" "," ")+2):REM Skip :
+660       IF LEFT$(line$,1)=CHR$1 THEN
+670        REM CTCP, so respond to it
+680        line$=MID$(line$,2,LEN(line$)-2)
+690        com$=LEFT$(line$,INSTR(line$+" "," ")-1)
+700        line$=MID$(line$,INSTR(line$+" "," ")+1)
+710        CASE FNupper(com$) OF
+720         WHEN "PING"
+730          REM Ping lag timing
+740          line$="PONG "+line$
+750          PRINTuid$;" pinged us"
+760         WHEN "VERSION"
+770          REM Version checking
+780          line$="VERSION EIRC 1.00 (c) Justin Fletcher"
+790          PRINTuid$;" wanted our version"
+800         WHEN "ACTION"
+810          PRINT"* ";uid$;" ";line$
+820          line$=""
+830         OTHERWISE
+840          REM everything else is an error
+850          line$="ERRMSG "+com$+" not understood"
+860          PRINT"CTCP '";com$;"' from ";uid$;" (";line$;")"
+870        ENDCASE
+880        IF line$<>"" THEN
+890         SYS "ESocket_SendLine",handle,"NOTICE "+uid$+" :"+CHR$1+line$+CHR$1
+900        ENDIF
+910       ELSE
+920        REM Somebody said something...
+930        PRINT"<";uid$;"> ";FNsafe(line$)
+940       ENDIF
+950      WHEN "JOIN"
+960       REM We (or someone else) has joined the channel
+970       chan$=LEFT$(line$,INSTR(line$+" "," ")):REM Skip :
+980       IF LEFT$(chan$,1)=":" THENchan$=MID$(chan$,2)
+990       PRINTuid$;" has joined ";chan$
+1000      WHEN "PART"
+1010       REM Someone else has left the channel
+1020       chan$=LEFT$(line$,INSTR(line$+" "," ")-1)
+1030       IF LEFT$(chan$,1)=":" THENchan$=MID$(chan$,2)
+1040       PRINTuid$;" has left ";chan$
+1050      WHEN "QUIT"
+1060       REM Someone else has quit IRC
+1070       PRINTuid$;" quit IRC"
+1080      OTHERWISE
+1090       REM Some unknown command
+1100       PRINTuid$;":";com$;":";FNsafe(line$)
+1110     ENDCASE
+1120     REM Re-display our input line
+1130     PRINTinput$;
+1140    ENDIF
+1150   ENDIF
+1160  UNTIL str=0
+1170 ENDIF
+1180 b$=INKEY$(0)
+1190 IF b$<>"" THEN
+1200  CASE b$ OF
+1210   WHEN CHR$13
+1220    SYS "ESocket_SendLine",handle,"PRIVMSG "+ourchan$+" :"+input$
+1230    REM Remove the line
+1240    IF input$<>"" THENFORI=1TOLEN(input$):VDU127:NEXT
+1250    REM We said it...
+1260    PRINT"<"+nick$+"> ";input$
+1270    input$=""
+1280   WHEN CHR$127,CHR$8
+1290    REM Backspace
+1300    IF input$<>"" THENVDU127
+1310    input$=LEFT$(input$)
+1320   OTHERWISE
+1330    REM Ad to current input
+1340    input$+=b$
+1350    PRINTb$;
+1360  ENDCASE
+1370 ENDIF
+1380 REM Has the socket closed
+1390 SYS "ESocket_Closed",handle,%0 TO closed
+1400UNTIL closed
+1410SYS "ESocket_Forget",handle
+1420SYS "ESocket_Forget",monitor
+1430END
+1440:
+1450DEFFNupper(a$):LOCAL c$,b$,I
+1460FORI=1TOLEN(a$)
+1470c$=MID$(a$,I,1):IF c$>="a"ANDc$<="z"THENc$=CHR$(ASC(c$)-32)
+1480b$+=c$:NEXT:=b$
+1490
+1500REM Remove control codes
+1510DEFFNsafe(line$)
+1520LOCAL I
+1530FORI=1TOLEN(line$)
+1540 IF MID$(line$,I,1)<" " THENMID$(line$,I,1)="*"
+1550NEXT
+1560=line$
-- 
cgit v1.2.1


From 0de93e092cd1e7d14a5d2c360b680f2724d98185 Mon Sep 17 00:00:00 2001
From: nimmajbb 
Date: Mon, 1 Apr 2019 17:15:14 +0100
Subject: some fixes to the kotlin lexer to work with the corda kolin codebase

---
 tests/test_kotlin.py | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 tests/test_kotlin.py

(limited to 'tests')

diff --git a/tests/test_kotlin.py b/tests/test_kotlin.py
new file mode 100644
index 00000000..7c733ad9
--- /dev/null
+++ b/tests/test_kotlin.py
@@ -0,0 +1,131 @@
+# -*- coding: utf-8 -*-
+"""
+    Basic JavaLexer Test
+    ~~~~~~~~~~~~~~~~~~~~
+
+    :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+    :license: BSD, see LICENSE for details.
+"""
+
+import unittest
+
+from pygments.token import Text, Name, Operator, Keyword, Number, Punctuation, String
+from pygments.lexers import KotlinLexer
+
+class KotlinTest(unittest.TestCase):
+
+    def setUp(self):
+        self.lexer = KotlinLexer()
+        self.maxDiff = None
+    
+    def testCanCopeWithBackTickNamesInFunctions(self):
+        fragment = u'fun `wo bble`'
+        tokens = [
+            (Keyword, u'fun'),
+            (Text, u' '),
+            (Name.Function, u'`wo bble`'),
+            (Text, u'\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+
+    def testCanCopeWithCommasAndDashesInBackTickNames(self):
+        fragment = u'fun `wo,-bble`'
+        tokens = [
+            (Keyword, u'fun'),
+            (Text, u' '),
+            (Name.Function, u'`wo,-bble`'),
+            (Text, u'\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+    
+    def testCanCopeWithDestructuring(self):
+        fragment = u'val (a, b) = '
+        tokens = [
+            (Keyword, u'val'),
+            (Text, u' '),
+            (Punctuation, u'('),
+            (Name.Property, u'a'),
+            (Punctuation, u','),
+            (Text, u' '),
+            (Name.Property, u'b'),
+            (Punctuation, u')'),
+            (Text, u' '),
+            (Punctuation, u'='),
+            (Text, u' '),
+            (Text, u'\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+    
+    def testCanCopeGenericsInDestructuring(self):
+        fragment = u'val (a: List, b: Set) ='
+        tokens = [
+            (Keyword, u'val'),
+            (Text, u' '),
+            (Punctuation, u'('),
+            (Name.Property, u'a'),
+            (Punctuation, u':'),
+            (Text, u' '),
+            (Name.Property, u'List'),
+            (Punctuation, u'<'),
+            (Name, u'Something'),
+            (Punctuation, u'>'),
+            (Punctuation, u','),
+            (Text, u' '),
+            (Name.Property, u'b'),
+            (Punctuation, u':'),
+            (Text, u' '),
+            (Name.Property, u'Set'),
+            (Punctuation, u'<'),
+            (Name, u'Wobble'),
+            (Punctuation, u'>'),
+            (Punctuation, u')'),
+            (Text, u' '),
+            (Punctuation, u'='),
+            (Text, u'\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+
+    def testCanCopeWithGenerics(self):
+        fragment = u'inline fun  VaultService.queryBy(): Vault.Page {'
+        tokens = [
+            (Keyword, u'inline fun'),
+            (Text, u' '),
+            (Punctuation, u'<'),
+            (Keyword, u'reified'),
+            (Text, u' '),
+            (Name, u'T'),
+            (Text, u' '),
+            (Punctuation, u':'),
+            (Text, u' '),
+            (Name, u'ContractState'),
+            (Punctuation, u'>'),
+            (Text, u' '),
+            (Name.Class, u'VaultService'),
+            (Punctuation, u'.'),
+            (Name.Function, u'queryBy'),
+            (Punctuation, u'('),
+            (Punctuation, u')'),
+            (Punctuation, u':'),
+            (Text, u' '),
+            (Name, u'Vault'),
+            (Punctuation, u'.'),
+            (Name, u'Page'),
+            (Punctuation, u'<'),
+            (Name, u'T'),
+            (Punctuation, u'>'),
+            (Text, u' '),
+            (Punctuation, u'{'),
+            (Text, u'\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+
+    def testShouldCopeWithMultilineComments(self):
+        fragment = u'"""\nthis\nis\na\ncomment"""'
+        tokens = [
+            (String, u'"""\nthis\nis\na\ncomment"""'), 
+            (Text, u'\n')
+        ]
+        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+
+if __name__ == '__main__':
+    unittest.main()
-- 
cgit v1.2.1


From 7cd2a4447b61034aa5fcc4fd01c4271968cf6713 Mon Sep 17 00:00:00 2001
From: "Frederik ?Freso? S. Olesen" 
Date: Mon, 1 Apr 2019 18:40:12 +0200
Subject: Add example TOML file

Based on https://github.com/toml-lang/toml/blob/master/README.md
---
 tests/examplefiles/example.toml | 181 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 181 insertions(+)
 create mode 100644 tests/examplefiles/example.toml

(limited to 'tests')

diff --git a/tests/examplefiles/example.toml b/tests/examplefiles/example.toml
new file mode 100644
index 00000000..9c60c79f
--- /dev/null
+++ b/tests/examplefiles/example.toml
@@ -0,0 +1,181 @@
+# This is a TOML document comment
+
+title = "TOML example file" # This is an inline comment
+
+[examples]
+# Examples taken from https://github.com/toml-lang/toml/blob/master/README.md
+key = "value"
+bare_key = "value"
+bare-key = "value"
+1234 = "value"
+"127.0.0.1" = "value"
+"character encoding" = "value"
+"ʎǝʞ" = "value"
+'key2' = "value"
+'quoted "value"' = "value"
+name = "Orange"
+physical.color = "orange"
+physical.shape = "round"
+site."google.com" = true
+a.b.c = 1
+a.d = 2
+
+[strings]
+str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
+str1 = """
+Roses are red
+Violets are blue"""
+str2 = "Roses are red\nViolets are blue"
+str3 = "Roses are red\r\nViolets are blue"
+
+  [strings.equivalents]
+  str1 = "The quick brown fox jumps over the lazy dog."
+  str2 = """
+The quick brown \
+
+
+    fox jumps over \
+      the lazy dog."""
+  str3 = """\
+         The quick brown \
+         fox jumps over \
+         the lazy dog.\
+         """
+
+  [strings.literal]
+  winpath  = 'C:\Users\nodejs\templates'
+  winpath2 = '\\ServerX\admin$\system32\'
+  quoted   = 'Tom "Dubs" Preston-Werner'
+  regex    = '<\i\c*\s*>'
+
+  [strings.multiline]
+  regex2 = '''I [dw]on't need \d{2} apples'''
+  lines  = '''
+The first newline is
+trimmed in raw strings.
+   All other whitespace
+   is preserved.
+'''
+
+[integers]
+int1 = +99
+int2 = 42
+int3 = 0
+int4 = -17
+int5 = 1_000
+int6 = 5_349_221
+int7 = 1_2_3_4_5 # discouraged format
+# hexadecimal with prefix `0x`
+hex1 = 0xDEADBEEF
+hex2 = 0xdeadbeef
+hex3 = 0xdead_beef
+# octal with prefix `0o`
+oct1 = 0o01234567
+oct2 = 0o755 # useful for Unix file permissions
+# binary with prefix `0b`
+bin1 = 0b11010110
+
+[floats]
+# fractional
+flt1 = +1.0
+flt2 = 3.1415
+flt3 = -0.01
+# exponent
+flt4 = 5e+22
+flt5 = 1e6
+flt6 = -2E-2
+# both
+flt7 = 6.626e-34
+# with underscores, for readability
+flt8 = 224_617.445_991_228
+# infinity
+sf1 = inf  # positive infinity
+sf2 = +inf # positive infinity
+sf3 = -inf # negative infinity
+# not a number
+sf4 = nan  # actual sNaN/qNaN encoding is implementation specific
+sf5 = +nan # same as `nan`
+sf6 = -nan # valid, actual encoding is implementation specific
+# plus/minus zero
+sf0_1 = +0.0
+sf0_2 = -0.0
+
+[booleans]
+bool1 = true
+bool2 = false
+
+[datetime.offset]
+odt1 = 1979-05-27T07:32:00Z
+odt2 = 1979-05-27T00:32:00-07:00
+odt3 = 1979-05-27T00:32:00.999999-07:00
+odt4 = 1979-05-27 07:32:00Z
+
+[datetime.local]
+ldt1 = 1979-05-27T07:32:00
+ldt2 = 1979-05-27T00:32:00.999999
+
+[date.local]
+ld1 = 1979-05-27
+
+[time.local]
+lt1 = 07:32:00
+lt2 = 00:32:00.999999
+
+[arrays]
+arr1 = [ 1, 2, 3 ]
+arr2 = [ "red", "yellow", "green" ]
+arr3 = [ [ 1, 2 ], [3, 4, 5] ]
+arr4 = [ "all", 'strings', """are the same""", '''type''']
+arr5 = [ [ 1, 2 ], ["a", "b", "c"] ]
+arr6 = [ 1, 2.0 ] # INVALID
+arr7 = [
+  1, 2, 3
+]
+arr8 = [
+  1,
+  2, # this is ok
+]
+
+["inline tables"]
+name = { first = "Tom", last = "Preston-Werner" }
+point = { x = 1, y = 2 }
+animal = { type.name = "pug" }
+
+["arrays of tables"]
+points = [ { x = 1, y = 2, z = 3 },
+           { x = 7, y = 8, z = 9 },
+           { x = 2, y = 4, z = 8 } ]
+
+  [products]
+
+    [[products]]
+    name = "Hammer"
+    sku = 738594937
+
+    [[products]]
+
+    [[products]]
+    name = "Nail"
+    sku = 284758393
+    color = "gray"
+
+  [fruits]
+
+    [[fruit]]
+      name = "apple"
+
+      [fruit.physical]
+        color = "red"
+        shape = "round"
+
+      [[fruit.variety]]
+        name = "red delicious"
+
+      [[fruit.variety]]
+        name = "granny smith"
+
+    [[fruit]]
+      name = "banana"
+
+      [[fruit.variety]]
+        name = "plantain"
-- 
cgit v1.2.1


From 075e65ed4e4424c121f7c70e0db9d2ff9e7895f8 Mon Sep 17 00:00:00 2001
From: "Matth?us G. Chajdas" 
Date: Sun, 28 Apr 2019 17:14:55 +0200
Subject: Add TOML example file and improve the lexer a bit.

---
 tests/examplefiles/example.toml | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 tests/examplefiles/example.toml

(limited to 'tests')

diff --git a/tests/examplefiles/example.toml b/tests/examplefiles/example.toml
new file mode 100644
index 00000000..40832c22
--- /dev/null
+++ b/tests/examplefiles/example.toml
@@ -0,0 +1,15 @@
+name = "TOML sample file"
+
+[section]
+key = "value"
+literal_string = 'C:\test'
+other_string = '''value'''
+list = [1, 2, 3]
+nested_list = [ [1, 2], [3, 4] ]
+float_variable = 13.37
+
+  [section.nested]
+  boolean_variable = false
+  date_variable = 1969-97-24T16:50:35-00:00
+
+# Comment
\ No newline at end of file
-- 
cgit v1.2.1