pygments.rb 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/lib/pygments/version.rb +1 -1
  2. data/vendor/pygments-main/AUTHORS +14 -0
  3. data/vendor/pygments-main/CHANGES +34 -3
  4. data/vendor/pygments-main/Makefile +1 -1
  5. data/vendor/pygments-main/docs/generate.py +1 -1
  6. data/vendor/pygments-main/external/markdown-processor.py +1 -1
  7. data/vendor/pygments-main/external/moin-parser.py +1 -1
  8. data/vendor/pygments-main/external/rst-directive-old.py +1 -1
  9. data/vendor/pygments-main/external/rst-directive.py +1 -1
  10. data/vendor/pygments-main/pygments/__init__.py +1 -1
  11. data/vendor/pygments-main/pygments/cmdline.py +4 -1
  12. data/vendor/pygments-main/pygments/console.py +1 -1
  13. data/vendor/pygments-main/pygments/filter.py +1 -1
  14. data/vendor/pygments-main/pygments/filters/__init__.py +1 -1
  15. data/vendor/pygments-main/pygments/formatter.py +1 -1
  16. data/vendor/pygments-main/pygments/formatters/__init__.py +1 -1
  17. data/vendor/pygments-main/pygments/formatters/_mapping.py +1 -1
  18. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
  19. data/vendor/pygments-main/pygments/formatters/html.py +2 -2
  20. data/vendor/pygments-main/pygments/formatters/img.py +1 -1
  21. data/vendor/pygments-main/pygments/formatters/latex.py +3 -2
  22. data/vendor/pygments-main/pygments/formatters/other.py +1 -1
  23. data/vendor/pygments-main/pygments/formatters/rtf.py +1 -1
  24. data/vendor/pygments-main/pygments/formatters/svg.py +1 -1
  25. data/vendor/pygments-main/pygments/formatters/terminal.py +5 -2
  26. data/vendor/pygments-main/pygments/formatters/terminal256.py +5 -2
  27. data/vendor/pygments-main/pygments/lexer.py +29 -10
  28. data/vendor/pygments-main/pygments/lexers/__init__.py +14 -11
  29. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
  30. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +1 -1
  31. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +1 -1
  32. data/vendor/pygments-main/pygments/lexers/_mapping.py +41 -23
  33. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1 -1
  34. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +1 -1
  35. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
  36. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -3
  37. data/vendor/pygments-main/pygments/lexers/agile.py +148 -443
  38. data/vendor/pygments-main/pygments/lexers/asm.py +5 -3
  39. data/vendor/pygments-main/pygments/lexers/compiled.py +298 -294
  40. data/vendor/pygments-main/pygments/lexers/dotnet.py +40 -34
  41. data/vendor/pygments-main/pygments/lexers/functional.py +723 -4
  42. data/vendor/pygments-main/pygments/lexers/hdl.py +228 -6
  43. data/vendor/pygments-main/pygments/lexers/jvm.py +678 -0
  44. data/vendor/pygments-main/pygments/lexers/math.py +65 -2
  45. data/vendor/pygments-main/pygments/lexers/other.py +875 -481
  46. data/vendor/pygments-main/pygments/lexers/parsers.py +1 -1
  47. data/vendor/pygments-main/pygments/lexers/shell.py +360 -0
  48. data/vendor/pygments-main/pygments/lexers/special.py +1 -1
  49. data/vendor/pygments-main/pygments/lexers/sql.py +565 -0
  50. data/vendor/pygments-main/pygments/lexers/templates.py +1 -1
  51. data/vendor/pygments-main/pygments/lexers/text.py +237 -100
  52. data/vendor/pygments-main/pygments/lexers/web.py +146 -10
  53. data/vendor/pygments-main/pygments/plugin.py +1 -1
  54. data/vendor/pygments-main/pygments/scanner.py +1 -1
  55. data/vendor/pygments-main/pygments/style.py +1 -1
  56. data/vendor/pygments-main/pygments/styles/__init__.py +2 -1
  57. data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
  58. data/vendor/pygments-main/pygments/styles/borland.py +1 -1
  59. data/vendor/pygments-main/pygments/styles/bw.py +1 -1
  60. data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
  61. data/vendor/pygments-main/pygments/styles/default.py +1 -1
  62. data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
  63. data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
  64. data/vendor/pygments-main/pygments/styles/fruity.py +1 -2
  65. data/vendor/pygments-main/pygments/styles/manni.py +1 -1
  66. data/vendor/pygments-main/pygments/styles/monokai.py +1 -1
  67. data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
  68. data/vendor/pygments-main/pygments/styles/native.py +1 -1
  69. data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
  70. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
  71. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  72. data/vendor/pygments-main/pygments/styles/tango.py +1 -1
  73. data/vendor/pygments-main/pygments/styles/trac.py +1 -1
  74. data/vendor/pygments-main/pygments/styles/vim.py +1 -1
  75. data/vendor/pygments-main/pygments/styles/vs.py +1 -1
  76. data/vendor/pygments-main/pygments/token.py +1 -1
  77. data/vendor/pygments-main/pygments/unistring.py +1 -1
  78. data/vendor/pygments-main/pygments/util.py +2 -2
  79. data/vendor/pygments-main/scripts/check_sources.py +2 -2
  80. data/vendor/pygments-main/scripts/find_codetags.py +1 -1
  81. data/vendor/pygments-main/scripts/find_error.py +5 -2
  82. data/vendor/pygments-main/scripts/get_vimkw.py +9 -4
  83. data/vendor/pygments-main/setup.py +1 -1
  84. data/vendor/pygments-main/tests/examplefiles/classes.dylan +16 -0
  85. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  86. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  87. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  88. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  89. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  90. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  91. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  92. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  93. data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
  94. data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
  95. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  96. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  97. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +4 -2
  98. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  99. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  100. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  101. data/vendor/pygments-main/tests/examplefiles/test.cs +23 -0
  102. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  103. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  104. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  105. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  106. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  107. data/vendor/pygments-main/tests/old_run.py +1 -1
  108. data/vendor/pygments-main/tests/run.py +1 -1
  109. data/vendor/pygments-main/tests/test_basic_api.py +4 -3
  110. data/vendor/pygments-main/tests/test_clexer.py +1 -1
  111. data/vendor/pygments-main/tests/test_cmdline.py +1 -1
  112. data/vendor/pygments-main/tests/test_examplefiles.py +4 -3
  113. data/vendor/pygments-main/tests/test_html_formatter.py +33 -1
  114. data/vendor/pygments-main/tests/test_latex_formatter.py +1 -1
  115. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  116. data/vendor/pygments-main/tests/test_regexlexer.py +1 -1
  117. data/vendor/pygments-main/tests/test_token.py +1 -1
  118. data/vendor/pygments-main/tests/test_using_api.py +1 -1
  119. data/vendor/pygments-main/tests/test_util.py +35 -5
  120. metadata +30 -4
@@ -0,0 +1,108 @@
1
+ <#
2
+ .SYNOPSIS
3
+ Runs a T-SQL Query and optional outputs results to a delimited file.
4
+ .DESCRIPTION
5
+ Invoke-Sql script will run a T-SQL query or stored procedure and optionally outputs a delimited file.
6
+ .EXAMPLE
7
+ PowerShell.exe -File "C:\Scripts\Invoke-Sql.ps1" -ServerInstance "Z003\sqlprod2" -Database orders -Query "EXEC usp_accounts '12445678'"
8
+ This example connects to Z003\sqlprod2.Orders and executes a stored procedure which does not return a result set
9
+ .EXAMPLE
10
+ PowerShell.exe -File "C:\Scripts\Invoke-Sql.ps1" -ServerInstance "Z003\sqlprod2" -Database orders -Query "SELECT * FROM dbo.accounts" -FilePath "C:\Scripts\accounts.txt" -Delimiter ","
11
+ This example connects to Z003\sqlprod2.Orders and selects the records from the accounts tables, the data is outputed to a CSV file
12
+ .NOTES
13
+ Version History
14
+ v1.0 - Chad Miller - 12/14/2010 - Initial release
15
+ IMPORTANT!!! The EventLog source which is set to the application needs to be registered with
16
+ the Event log:
17
+ New-EventLog -LogName Application -Source $Application
18
+ #>
19
+ param(
20
+ #ServerInstance is Mandatory!
21
+ [Parameter(Position=0, Mandatory=$false)] [string]$ServerInstance,
22
+ #Database is Mandatory!
23
+ [Parameter(Position=1, Mandatory=$false)] [string]$Database,
24
+ #Query is Mandatory!
25
+ [Parameter(Position=2, Mandatory=$false)] [string]$Query,
26
+ [Parameter(Position=3, Mandatory=$false)] [string]$Application="Invoke-Sql.ps1",
27
+ [Parameter(Position=4, Mandatory=$false)] [string]$FilePath,
28
+ [Parameter(Position=7, Mandatory=$false)] [string]$Delimiter="|",
29
+ #If UserName isn't supplied a trusted connection will be used
30
+ [Parameter(Position=5, Mandatory=$false)] [string]$UserName,
31
+ [Parameter(Position=6, Mandatory=$false)] [string]$Password,
32
+ [Parameter(Position=8, Mandatory=$false)] [Int32]$QueryTimeout=600,
33
+ [Parameter(Position=9, Mandatory=$false)] [Int32]$ConnectionTimeout=15
34
+ )
35
+
36
+
37
+ #This must be run as administrator on Windows 2008 and higher!
38
+ New-EventLog -LogName Application -Source $Application -EA SilentlyContinue
39
+ $Error.Clear()
40
+
41
+ #######################
42
+ function Invoke-SqlCmd2
43
+ {
44
+ param(
45
+ [Parameter(Position=0, Mandatory=$true)] [string]$ServerInstance,
46
+ [Parameter(Position=1, Mandatory=$true)] [string]$Database,
47
+ [Parameter(Position=2, Mandatory=$true)] [string]$Query,
48
+ [Parameter(Position=3, Mandatory=$false)] [string]$UserName,
49
+ [Parameter(Position=4, Mandatory=$false)] [string]$Password,
50
+ [Parameter(Position=5, Mandatory=$false)] [Int32]$QueryTimeout,
51
+ [Parameter(Position=6, Mandatory=$false)] [Int32]$ConnectionTimeout
52
+ )
53
+
54
+ try {
55
+ if ($Username)
56
+ { $ConnectionString = "Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;Connect Timeout={4}" -f $ServerInstance,$Database,$Username,$Password,$ConnectionTimeout }
57
+ else
58
+ { $ConnectionString = "Server={0};Database={1};Integrated Security=True;Connect Timeout={2}" -f $ServerInstance,$Database,$ConnectionTimeout }
59
+ $conn=new-object System.Data.SqlClient.SQLConnection
60
+ $conn.ConnectionString=$ConnectionString
61
+ $conn.Open()
62
+ $cmd=new-object system.Data.SqlClient.SqlCommand($Query,$conn)
63
+ $cmd.CommandTimeout=$QueryTimeout
64
+ $ds=New-Object system.Data.DataSet
65
+ $da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
66
+ [void]$da.fill($ds)
67
+ Write-Output ($ds.Tables[0])
68
+ }
69
+ finally {
70
+ $conn.Dispose()
71
+ }
72
+
73
+ } #Invoke-SqlCmd2
74
+
75
+ #######################
76
+ # MAIN #
77
+ #######################
78
+ if ($PSBoundParameters.Count -eq 0)
79
+ {
80
+ get-help $myInvocation.MyCommand.Path -full
81
+ break
82
+ }
83
+
84
+ try {
85
+ $msg = $null
86
+ $msg += "Application/Job Name: $Application`n"
87
+ $msg += "Query: $Query`n"
88
+ $msg += "ServerInstance: $ServerInstance`n"
89
+ $msg += "Database: $Database`n"
90
+ $msg += "FilePath: $FilePath`n"
91
+
92
+ Write-EventLog -LogName Application -Source "$Application" -EntryType Information -EventId 12345 -Message "Starting`n$msg"
93
+ $dt = Invoke-SqlCmd2 -ServerInstance $ServerInstance -Database $Database -Query $Query -UserName $UserName -Password $Password -QueryTimeOut $QueryTimeOut -ConnectionTimeout $ConnectionTimeout
94
+ if ($FilePath)
95
+ {
96
+ if ($dt)
97
+ { $dt | export-csv -Delimiter $Delimiter -Path $FilePath -NoTypeInformation }
98
+ else #Query Returned No Output!
99
+ {Write-EventLog -LogName Application -Source "$Application" -EntryType Warning -EventId 12345 -Message "NoOutput`n$msg" }
100
+ }
101
+
102
+ Write-EventLog -LogName Application -Source "$Application" -EntryType Information -EventId 12345 -Message "Completed`n$msg"
103
+ }
104
+ catch {
105
+ $Exception = "{0}, {1}" -f $_.Exception.GetType().FullName,$( $_.Exception.Message -replace "'" )
106
+ Write-EventLog -LogName Application -Source "$Application" -EntryType Error -EventId 12345 -Message "Error`n$msg`n$Exception"
107
+ throw
108
+ }
@@ -0,0 +1,161 @@
1
+ library ieee;
2
+ use ieee.std_logic_unsigned.all;
3
+ use ieee.std_logic_1164.all;
4
+ use ieee.numeric_std.all;
5
+
6
+
7
+ entity top_testbench is --test
8
+ generic ( -- test
9
+ n : integer := 8 -- test
10
+ ); -- test
11
+ end top_testbench; -- test
12
+
13
+
14
+ architecture top_testbench_arch of top_testbench is
15
+
16
+ component top is
17
+ generic (
18
+ n : integer
19
+ ) ;
20
+ port (
21
+ clk : in std_logic;
22
+ rst : in std_logic;
23
+ d1 : in std_logic_vector (n-1 downto 0);
24
+ d2 : in std_logic_vector (n-1 downto 0);
25
+ operation : in std_logic;
26
+ result : out std_logic_vector (2*n-1 downto 0)
27
+ );
28
+ end component;
29
+
30
+ signal clk : std_logic;
31
+ signal rst : std_logic;
32
+ signal operation : std_logic;
33
+ signal d1 : std_logic_vector (n-1 downto 0);
34
+ signal d2 : std_logic_vector (n-1 downto 0);
35
+ signal result : std_logic_vector (2*n-1 downto 0);
36
+
37
+ type test_type is ( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
38
+ attribute enum_encoding of my_state : type is "001 010 011 100 111";
39
+ begin
40
+
41
+ TESTUNIT : top generic map (n => n)
42
+ port map (clk => clk,
43
+ rst => rst,
44
+ d1 => d1,
45
+ d2 => d2,
46
+ operation => operation,
47
+ result => result);
48
+
49
+ clock_process : process
50
+ begin
51
+ clk <= '0';
52
+ wait for 5 ns;
53
+ clk <= '1';
54
+ wait for 5 ns;
55
+ end process;
56
+
57
+ data_process : process
58
+ begin
59
+
60
+ -- test case #1
61
+ operation <= '0';
62
+
63
+ rst <= '1';
64
+ wait for 5 ns;
65
+ rst <= '0';
66
+ wait for 5 ns;
67
+
68
+ d1 <= std_logic_vector(to_unsigned(60, d1'length));
69
+ d2 <= std_logic_vector(to_unsigned(12, d2'length));
70
+ wait for 360 ns;
71
+
72
+ assert (result = std_logic_vector(to_unsigned(720, result'length)))
73
+ report "Test case #1 failed" severity error;
74
+
75
+ -- test case #2
76
+ operation <= '0';
77
+
78
+ rst <= '1';
79
+ wait for 5 ns;
80
+ rst <= '0';
81
+ wait for 5 ns;
82
+
83
+ d1 <= std_logic_vector(to_unsigned(55, d1'length));
84
+ d2 <= std_logic_vector(to_unsigned(1, d2'length));
85
+ wait for 360 ns;
86
+
87
+ assert (result = std_logic_vector(to_unsigned(55, result'length)))
88
+ report "Test case #2 failed" severity error;
89
+
90
+ -- etc
91
+
92
+ end process;
93
+
94
+ end top_testbench_arch;
95
+
96
+
97
+ configuration testbench_for_top of top_testbench is
98
+ for top_testbench_arch
99
+ for TESTUNIT : top
100
+ use entity work.top(top_arch);
101
+ end for;
102
+ end for;
103
+ end testbench_for_top;
104
+
105
+
106
+ function compare(A: std_logic, B: std_Logic) return std_logic is
107
+ constant pi : real := 3.14159;
108
+ constant half_pi : real := pi / 2.0;
109
+ constant cycle_time : time := 2 ns;
110
+ constant N, N5 : integer := 5;
111
+ begin
112
+ if (A = '0' and B = '1') then
113
+ return B;
114
+ else
115
+ return A;
116
+ end if ;
117
+ end compare;
118
+
119
+
120
+ procedure print(P : std_logic_vector(7 downto 0);
121
+ U : std_logic_vector(3 downto 0)) is
122
+ variable my_line : line;
123
+ alias swrite is write [line, string, side, width] ;
124
+ begin
125
+ swrite(my_line, "sqrt( ");
126
+ write(my_line, P);
127
+ swrite(my_line, " )= ");
128
+ write(my_line, U);
129
+ writeline(output, my_line);
130
+ end print;
131
+
132
+
133
+ entity add32csa is -- one stage of carry save adder for multiplier
134
+ port(
135
+ b : in std_logic; -- a multiplier bit
136
+ a : in std_logic_vector(31 downto 0); -- multiplicand
137
+ sum_in : in std_logic_vector(31 downto 0); -- sums from previous stage
138
+ cin : in std_logic_vector(31 downto 0); -- carrys from previous stage
139
+ sum_out : out std_logic_vector(31 downto 0); -- sums to next stage
140
+ cout : out std_logic_vector(31 downto 0)); -- carrys to next stage
141
+ end add32csa;
142
+
143
+
144
+ ARCHITECTURE circuits of add32csa IS
145
+ SIGNAL zero : STD_LOGIC_VECTOR(31 downto 0) := X"00000000";
146
+ SIGNAL aa : std_logic_vector(31 downto 0) := X"00000000";
147
+
148
+ COMPONENT fadd -- duplicates entity port
149
+ PoRT(a : in std_logic;
150
+ b : in std_logic;
151
+ cin : in std_logic;
152
+ s : out std_logic;
153
+ cout : out std_logic);
154
+ end comPonent fadd;
155
+
156
+ begin -- circuits of add32csa
157
+ aa <= a when b='1' else zero after 1 ns;
158
+ stage: for I in 0 to 31 generate
159
+ sta: fadd port map(aa(I), sum_in(I), cin(I) , sum_out(I), cout(I));
160
+ end generate stage;
161
+ end architecture circuits; -- of add32csa
@@ -8,7 +8,7 @@
8
8
  python run.py [testfile ...]
9
9
 
10
10
 
11
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
11
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
12
12
  :license: BSD, see LICENSE for details.
13
13
  """
14
14
 
@@ -8,7 +8,7 @@
8
8
  python run.py [testfile ...]
9
9
 
10
10
 
11
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
11
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
12
12
  :license: BSD, see LICENSE for details.
13
13
  """
14
14
 
@@ -3,7 +3,7 @@
3
3
  Pygments basic API tests
4
4
  ~~~~~~~~~~~~~~~~~~~~~~~~
5
5
 
6
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
7
  :license: BSD, see LICENSE for details.
8
8
  """
9
9
 
@@ -57,7 +57,7 @@ def test_lexer_classes():
57
57
  assert 'root' in cls._tokens, \
58
58
  '%s has no root state' % cls
59
59
 
60
- if cls.name == 'XQuery': # XXX temporary
60
+ if cls.name in ['XQuery', 'Opa']: # XXX temporary
61
61
  return
62
62
 
63
63
  tokens = list(inst.get_tokens(test_content))
@@ -92,7 +92,8 @@ def test_lexer_options():
92
92
  if cls.__name__ not in (
93
93
  'PythonConsoleLexer', 'RConsoleLexer', 'RubyConsoleLexer',
94
94
  'SqliteConsoleLexer', 'MatlabSessionLexer', 'ErlangShellLexer',
95
- 'BashSessionLexer', 'LiterateHaskellLexer', 'PostgresConsoleLexer'):
95
+ 'BashSessionLexer', 'LiterateHaskellLexer', 'PostgresConsoleLexer',
96
+ 'ElixirConsoleLexer'):
96
97
  inst = cls(ensurenl=False)
97
98
  ensure(inst.get_tokens('a\nb'), 'a\nb')
98
99
  inst = cls(ensurenl=False, stripall=True)
@@ -3,7 +3,7 @@
3
3
  Basic CLexer Test
4
4
  ~~~~~~~~~~~~~~~~~
5
5
 
6
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
7
  :license: BSD, see LICENSE for details.
8
8
  """
9
9
 
@@ -3,7 +3,7 @@
3
3
  Command line test
4
4
  ~~~~~~~~~~~~~~~~~
5
5
 
6
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
7
  :license: BSD, see LICENSE for details.
8
8
  """
9
9
 
@@ -3,7 +3,7 @@
3
3
  Pygments tests with example files
4
4
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
 
6
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
7
  :license: BSD, see LICENSE for details.
8
8
  """
9
9
 
@@ -60,8 +60,9 @@ def check_lexer(lx, absfn, outfn):
60
60
  tokens = []
61
61
  for type, val in lx.get_tokens(text):
62
62
  ntext.append(val)
63
- assert type != Error, 'lexer %s generated error token for %s' % \
64
- (lx, absfn)
63
+ assert type != Error, \
64
+ 'lexer %s generated error token for %s: %r at position %d' % \
65
+ (lx, absfn, val, len(u''.join(ntext)))
65
66
  tokens.append((type, val))
66
67
  if u''.join(ntext) != text:
67
68
  print '\n'.join(difflib.unified_diff(u''.join(ntext).splitlines(),
@@ -3,7 +3,7 @@
3
3
  Pygments HTML formatter tests
4
4
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
 
6
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
7
  :license: BSD, see LICENSE for details.
8
8
  """
9
9
 
@@ -75,6 +75,38 @@ class HtmlFormatterTest(unittest.TestCase):
75
75
  fmt = HtmlFormatter(**optdict)
76
76
  fmt.format(tokensource, outfile)
77
77
 
78
+ def test_linenos(self):
79
+ optdict = dict(linenos=True)
80
+ outfile = StringIO.StringIO()
81
+ fmt = HtmlFormatter(**optdict)
82
+ fmt.format(tokensource, outfile)
83
+ html = outfile.getvalue()
84
+ self.assert_(re.search("<pre>\s+1\s+2\s+3", html))
85
+
86
+ def test_linenos_with_startnum(self):
87
+ optdict = dict(linenos=True, linenostart=5)
88
+ outfile = StringIO.StringIO()
89
+ fmt = HtmlFormatter(**optdict)
90
+ fmt.format(tokensource, outfile)
91
+ html = outfile.getvalue()
92
+ self.assert_(re.search("<pre>\s+5\s+6\s+7", html))
93
+
94
+ def test_lineanchors(self):
95
+ optdict = dict(lineanchors="foo")
96
+ outfile = StringIO.StringIO()
97
+ fmt = HtmlFormatter(**optdict)
98
+ fmt.format(tokensource, outfile)
99
+ html = outfile.getvalue()
100
+ self.assert_(re.search("<pre><a name=\"foo-1\">", html))
101
+
102
+ def test_lineanchors_with_startnum(self):
103
+ optdict = dict(lineanchors="foo", linenostart=5)
104
+ outfile = StringIO.StringIO()
105
+ fmt = HtmlFormatter(**optdict)
106
+ fmt.format(tokensource, outfile)
107
+ html = outfile.getvalue()
108
+ self.assert_(re.search("<pre><a name=\"foo-5\">", html))
109
+
78
110
  def test_valid_output(self):
79
111
  # test all available wrappers
80
112
  fmt = HtmlFormatter(full=True, linenos=True, noclasses=True,
@@ -3,7 +3,7 @@
3
3
  Pygments LaTeX formatter tests
4
4
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
 
6
- :copyright: Copyright 2006-2011 by the Pygments team, see AUTHORS.
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
7
  :license: BSD, see LICENSE for details.
8
8
  """
9
9
 
@@ -0,0 +1,137 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Pygments regex lexer tests
4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
7
+ :license: BSD, see LICENSE for details.
8
+ """
9
+
10
+ import time
11
+ import unittest
12
+
13
+ from pygments.token import String
14
+ from pygments.lexers.agile import PerlLexer
15
+
16
+
17
+ class RunawayRegexTest(unittest.TestCase):
18
+ # A previous version of the Perl lexer would spend a great deal of
19
+ # time backtracking when given particular strings. These tests show that
20
+ # the runaway backtracking doesn't happen any more (at least for the given
21
+ # cases).
22
+
23
+ lexer = PerlLexer()
24
+
25
+ ### Test helpers.
26
+
27
+ def assert_single_token(self, s, token):
28
+ """Show that a given string generates only one token."""
29
+ tokens = list(self.lexer.get_tokens_unprocessed(s))
30
+ self.assertEqual(len(tokens), 1, tokens)
31
+ self.assertEqual(s, tokens[0][2])
32
+ self.assertEqual(token, tokens[0][1])
33
+
34
+ def assert_tokens(self, strings, expected_tokens):
35
+ """Show that a given string generates the expected tokens."""
36
+ tokens = list(self.lexer.get_tokens_unprocessed(''.join(strings)))
37
+ self.assertEqual(len(tokens), len(expected_tokens), tokens)
38
+ for index, s in enumerate(strings):
39
+ self.assertEqual(s, tokens[index][2])
40
+ self.assertEqual(expected_tokens[index], tokens[index][1])
41
+
42
+ def assert_fast_tokenization(self, s):
43
+ """Show that a given string is tokenized quickly."""
44
+ start = time.time()
45
+ tokens = list(self.lexer.get_tokens_unprocessed(s))
46
+ end = time.time()
47
+ # Isn't 10 seconds kind of a long time? Yes, but we don't want false
48
+ # positives when the tests are starved for CPU time.
49
+ if end-start > 10:
50
+ self.fail('tokenization took too long')
51
+ return tokens
52
+
53
+ ### Strings.
54
+
55
+ def test_single_quote_strings(self):
56
+ self.assert_single_token(r"'foo\tbar\\\'baz'", String)
57
+ self.assert_fast_tokenization("'" + '\\'*999)
58
+
59
+ def test_double_quote_strings(self):
60
+ self.assert_single_token(r'"foo\tbar\\\"baz"', String)
61
+ self.assert_fast_tokenization('"' + '\\'*999)
62
+
63
+ def test_backtick_strings(self):
64
+ self.assert_single_token(r'`foo\tbar\\\`baz`', String.Backtick)
65
+ self.assert_fast_tokenization('`' + '\\'*999)
66
+
67
+ ### Regex matches with various delimiters.
68
+
69
+ def test_match(self):
70
+ self.assert_single_token(r'/aa\tbb/', String.Regex)
71
+ self.assert_fast_tokenization('/' + '\\'*999)
72
+
73
+ def test_match_with_slash(self):
74
+ self.assert_tokens(['m', '/\n\\t\\\\/'], [String.Regex, String.Regex])
75
+ self.assert_fast_tokenization('m/xxx\n' + '\\'*999)
76
+
77
+ def test_match_with_bang(self):
78
+ self.assert_tokens(['m', r'!aa\t\!bb!'], [String.Regex, String.Regex])
79
+ self.assert_fast_tokenization('m!' + '\\'*999)
80
+
81
+ def test_match_with_brace(self):
82
+ self.assert_tokens(['m', r'{aa\t\}bb}'], [String.Regex, String.Regex])
83
+ self.assert_fast_tokenization('m{' + '\\'*999)
84
+
85
+ def test_match_with_angle_brackets(self):
86
+ self.assert_tokens(['m', r'<aa\t\>bb>'], [String.Regex, String.Regex])
87
+ self.assert_fast_tokenization('m<' + '\\'*999)
88
+
89
+ def test_match_with_parenthesis(self):
90
+ self.assert_tokens(['m', r'(aa\t\)bb)'], [String.Regex, String.Regex])
91
+ self.assert_fast_tokenization('m(' + '\\'*999)
92
+
93
+ def test_match_with_at_sign(self):
94
+ self.assert_tokens(['m', r'@aa\t\@bb@'], [String.Regex, String.Regex])
95
+ self.assert_fast_tokenization('m@' + '\\'*999)
96
+
97
+ def test_match_with_percent_sign(self):
98
+ self.assert_tokens(['m', r'%aa\t\%bb%'], [String.Regex, String.Regex])
99
+ self.assert_fast_tokenization('m%' + '\\'*999)
100
+
101
+ def test_match_with_dollar_sign(self):
102
+ self.assert_tokens(['m', r'$aa\t\$bb$'], [String.Regex, String.Regex])
103
+ self.assert_fast_tokenization('m$' + '\\'*999)
104
+
105
+ ### Regex substitutions with various delimeters.
106
+
107
+ def test_substitution_with_slash(self):
108
+ self.assert_single_token('s/aaa/bbb/g', String.Regex)
109
+ self.assert_fast_tokenization('s/foo/' + '\\'*999)
110
+
111
+ def test_substitution_with_at_sign(self):
112
+ self.assert_single_token(r's@aaa@bbb@g', String.Regex)
113
+ self.assert_fast_tokenization('s@foo@' + '\\'*999)
114
+
115
+ def test_substitution_with_percent_sign(self):
116
+ self.assert_single_token(r's%aaa%bbb%g', String.Regex)
117
+ self.assert_fast_tokenization('s%foo%' + '\\'*999)
118
+
119
+ def test_substitution_with_brace(self):
120
+ self.assert_single_token(r's{aaa}', String.Regex)
121
+ self.assert_fast_tokenization('s{' + '\\'*999)
122
+
123
+ def test_substitution_with_angle_bracket(self):
124
+ self.assert_single_token(r's<aaa>', String.Regex)
125
+ self.assert_fast_tokenization('s<' + '\\'*999)
126
+
127
+ def test_substitution_with_angle_bracket(self):
128
+ self.assert_single_token(r's<aaa>', String.Regex)
129
+ self.assert_fast_tokenization('s<' + '\\'*999)
130
+
131
+ def test_substitution_with_square_bracket(self):
132
+ self.assert_single_token(r's[aaa]', String.Regex)
133
+ self.assert_fast_tokenization('s[' + '\\'*999)
134
+
135
+ def test_substitution_with_parenthesis(self):
136
+ self.assert_single_token(r's(aaa)', String.Regex)
137
+ self.assert_fast_tokenization('s(' + '\\'*999)