From b82317034f4c3c8912beb3a5f5b16ace6c36c201 Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Tue, 22 Mar 2016 22:52:18 +0100 Subject: Fixed broken test case by properly naming Transact-SQL example file to prevent ResourceLexer from attempting to lex it. --- tests/examplefiles/test_transact-sql.txt | 70 -------------------------------- tests/examplefiles/tsql_example.sql | 70 ++++++++++++++++++++++++++++++++ tests/test_sql.py | 13 +----- 3 files changed, 71 insertions(+), 82 deletions(-) delete mode 100644 tests/examplefiles/test_transact-sql.txt create mode 100644 tests/examplefiles/tsql_example.sql diff --git a/tests/examplefiles/test_transact-sql.txt b/tests/examplefiles/test_transact-sql.txt deleted file mode 100644 index 5e737ff4..00000000 --- a/tests/examplefiles/test_transact-sql.txt +++ /dev/null @@ -1,70 +0,0 @@ --- Example Transact-SQL file. --- --- We cannot use "*.sql" as file suffix because then the automatic tests for --- the ANSI SQL lexer would attempt to read it and in turn detect errors in --- it which would cause a test case to fail. - --- Single line comment -/* A comment - * spawning two lines. */ - /* An indented comment - * spawning multiple - * lines. */ -/* A /* nested */ comment. */ - -select - left(emp.firstname, 1) + '.' + [emp.surname] as "Name", - dep.name as [Department] -into - #temp_employee -from - employee as emp - inner join department as dep on - dep.ident_code = emp.department_id -where - emp.date_of_birth >= '1990-01-01'; -go - -declare @TextToFind nvarchar(100) = N'some -text across -multiple lines'; - -set @TextToFind varchar(32) = 'hello' + ' world'; -set @TextTiFind += '!'; - -declare @Count int = 17 * (3 - 5); - -delete from - [server].[database].[schema].[table] -where - [Text] = @TextToFind and author Not LIKE '%some%'; - -goto overthere; -overthere: - -select - 123 as "int 1", - +123 as "int 2", - -123 as "int 3", - 0x20 as "hex int", - 123.45 as "float 1", - -1.23e45 as "float 2" - +1.23E+45 as "float 3", - -1.23e-45 as "float 4"; - -Select @@Error, $PARTITion.RangePF1(10); - -select top 3 Ähnliches from Müll; - --- Example transaction -BEGIN TRAN - -BEGIN TRY - INSERT INTO #temp_employe(Name, Department) VALUES ('L. Miller', 'Sales') - iNsErT inTO #temp_employe(Name, Department) VaLuEs ('M. Webster', 'Helpdesk') - COMMIT TRAN -END TRY -BEGIN CATCH - print 'cannot perform transaction; rolling back'; - ROLLBACK TRAN -END CATCH diff --git a/tests/examplefiles/tsql_example.sql b/tests/examplefiles/tsql_example.sql new file mode 100644 index 00000000..5e737ff4 --- /dev/null +++ b/tests/examplefiles/tsql_example.sql @@ -0,0 +1,70 @@ +-- Example Transact-SQL file. +-- +-- We cannot use "*.sql" as file suffix because then the automatic tests for +-- the ANSI SQL lexer would attempt to read it and in turn detect errors in +-- it which would cause a test case to fail. + +-- Single line comment +/* A comment + * spawning two lines. */ + /* An indented comment + * spawning multiple + * lines. */ +/* A /* nested */ comment. */ + +select + left(emp.firstname, 1) + '.' + [emp.surname] as "Name", + dep.name as [Department] +into + #temp_employee +from + employee as emp + inner join department as dep on + dep.ident_code = emp.department_id +where + emp.date_of_birth >= '1990-01-01'; +go + +declare @TextToFind nvarchar(100) = N'some +text across +multiple lines'; + +set @TextToFind varchar(32) = 'hello' + ' world'; +set @TextTiFind += '!'; + +declare @Count int = 17 * (3 - 5); + +delete from + [server].[database].[schema].[table] +where + [Text] = @TextToFind and author Not LIKE '%some%'; + +goto overthere; +overthere: + +select + 123 as "int 1", + +123 as "int 2", + -123 as "int 3", + 0x20 as "hex int", + 123.45 as "float 1", + -1.23e45 as "float 2" + +1.23E+45 as "float 3", + -1.23e-45 as "float 4"; + +Select @@Error, $PARTITion.RangePF1(10); + +select top 3 Ähnliches from Müll; + +-- Example transaction +BEGIN TRAN + +BEGIN TRY + INSERT INTO #temp_employe(Name, Department) VALUES ('L. Miller', 'Sales') + iNsErT inTO #temp_employe(Name, Department) VaLuEs ('M. Webster', 'Helpdesk') + COMMIT TRAN +END TRY +BEGIN CATCH + print 'cannot perform transaction; rolling back'; + ROLLBACK TRAN +END CATCH diff --git a/tests/test_sql.py b/tests/test_sql.py index 37a81ff8..f4016918 100644 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -6,12 +6,10 @@ :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -import io -import os.path import unittest from pygments.lexers.sql import TransactSqlLexer -from pygments.token import Comment, Error, Name, Number, Whitespace +from pygments.token import Comment, Name, Number, Whitespace class TransactSqlLexerTest(unittest.TestCase): @@ -65,12 +63,3 @@ class TransactSqlLexerTest(unittest.TestCase): (Comment.Multiline, '*/'), (Comment.Multiline, '*/'), )) - - def test_can_lex_example_file(self): - tests_path = os.path.dirname(__file__) - example_path = os.path.join(tests_path, 'examplefiles', 'test_transact-sql.txt') - - with io.open(example_path, 'r', encoding='utf-8') as example_file: - example_code = example_file.read() - for token_type, token_value in self.lexer.get_tokens(example_code): - self.assertNotEqual(Error, token_type, 'token_value=%r' % token_value) -- cgit v1.2.1