testing.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. """
  2. pygments.lexers.testing
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for testing languages.
  5. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, include, bygroups
  9. from pygments.token import Comment, Keyword, Name, String, Number, Generic, Text
  10. __all__ = ['GherkinLexer', 'TAPLexer']
  11. class GherkinLexer(RegexLexer):
  12. """
  13. For `Gherkin <https://github.com/aslakhellesoy/gherkin/>` syntax.
  14. .. versionadded:: 1.2
  15. """
  16. name = 'Gherkin'
  17. aliases = ['gherkin', 'cucumber']
  18. filenames = ['*.feature']
  19. mimetypes = ['text/x-gherkin']
  20. feature_keywords = '^(기능|機能|功能|フィーチャ|خاصية|תכונה|Функціонал|Функционалност|Функционал|Фича|Особина|Могућност|Özellik|Właściwość|Tính năng|Trajto|Savybė|Požiadavka|Požadavek|Osobina|Ominaisuus|Omadus|OH HAI|Mogućnost|Mogucnost|Jellemző|Fīča|Funzionalità|Funktionalität|Funkcionalnost|Funkcionalitāte|Funcționalitate|Functionaliteit|Functionalitate|Funcionalitat|Funcionalidade|Fonctionnalité|Fitur|Feature|Egenskap|Egenskab|Crikey|Característica|Arwedd)(:)(.*)$'
  21. feature_element_keywords = '^(\\s*)(시나리오 개요|시나리오|배경|背景|場景大綱|場景|场景大纲|场景|劇本大綱|劇本|剧本大纲|剧本|テンプレ|シナリオテンプレート|シナリオテンプレ|シナリオアウトライン|シナリオ|سيناريو مخطط|سيناريو|الخلفية|תרחיש|תבנית תרחיש|רקע|Тарих|Сценарій|Сценарио|Сценарий структураси|Сценарий|Структура сценарію|Структура сценарија|Структура сценария|Скица|Рамка на сценарий|Пример|Предыстория|Предистория|Позадина|Передумова|Основа|Концепт|Контекст|Założenia|Wharrimean is|Tình huống|The thing of it is|Tausta|Taust|Tapausaihio|Tapaus|Szenariogrundriss|Szenario|Szablon scenariusza|Stsenaarium|Struktura scenarija|Skica|Skenario konsep|Skenario|Situācija|Senaryo taslağı|Senaryo|Scénář|Scénario|Schema dello scenario|Scenārijs pēc parauga|Scenārijs|Scenár|Scenaro|Scenariusz|Scenariul de şablon|Scenariul de sablon|Scenariu|Scenario Outline|Scenario Amlinellol|Scenario|Scenarijus|Scenarijaus šablonas|Scenarij|Scenarie|Rerefons|Raamstsenaarium|Primer|Pozadí|Pozadina|Pozadie|Plan du scénario|Plan du Scénario|Osnova scénáře|Osnova|Náčrt Scénáře|Náčrt Scenáru|Mate|MISHUN SRSLY|MISHUN|Kịch bản|Konturo de la scenaro|Kontext|Konteksts|Kontekstas|Kontekst|Koncept|Khung tình huống|Khung kịch bản|Háttér|Grundlage|Geçmiş|Forgatókönyv vázlat|Forgatókönyv|Fono|Esquema do Cenário|Esquema do Cenario|Esquema del escenario|Esquema de l\'escenari|Escenario|Escenari|Dis is what went down|Dasar|Contexto|Contexte|Contesto|Condiţii|Conditii|Cenário|Cenario|Cefndir|Bối cảnh|Blokes|Bakgrunn|Bakgrund|Baggrund|Background|B4|Antecedents|Antecedentes|All y\'all|Achtergrond|Abstrakt Scenario|Abstract Scenario)(:)(.*)$'
  22. examples_keywords = '^(\\s*)(예|例子|例|サンプル|امثلة|דוגמאות|Сценарији|Примери|Приклади|Мисоллар|Значения|Örnekler|Voorbeelden|Variantai|Tapaukset|Scenarios|Scenariji|Scenarijai|Příklady|Példák|Príklady|Przykłady|Primjeri|Primeri|Piemēri|Pavyzdžiai|Paraugs|Juhtumid|Exemplos|Exemples|Exemplele|Exempel|Examples|Esempi|Enghreifftiau|Ekzemploj|Eksempler|Ejemplos|EXAMPLZ|Dữ liệu|Contoh|Cobber|Beispiele)(:)(.*)$'
  23. step_keywords = '^(\\s*)(하지만|조건|먼저|만일|만약|단|그리고|그러면|那麼|那么|而且|當|当|前提|假設|假设|假如|假定|但是|但し|並且|并且|同時|同时|もし|ならば|ただし|しかし|かつ|و |متى |لكن |عندما |ثم |بفرض |اذاً |כאשר |וגם |בהינתן |אזי |אז |אבל |Якщо |Унда |То |Припустимо, що |Припустимо |Онда |Но |Нехай |Лекин |Когато |Када |Кад |К тому же |И |Задато |Задати |Задате |Если |Допустим |Дадено |Ва |Бирок |Аммо |Али |Але |Агар |А |І |Și |És |Zatati |Zakładając |Zadato |Zadate |Zadano |Zadani |Zadan |Youse know when youse got |Youse know like when |Yna |Ya know how |Ya gotta |Y |Wun |Wtedy |When y\'all |When |Wenn |WEN |Và |Ve |Und |Un |Thì |Then y\'all |Then |Tapi |Tak |Tada |Tad |Så |Stel |Soit |Siis |Si |Sed |Se |Quando |Quand |Quan |Pryd |Pokud |Pokiaľ |Però |Pero |Pak |Oraz |Onda |Ond |Oletetaan |Og |Och |O zaman |Når |När |Niin |Nhưng |N |Mutta |Men |Mas |Maka |Majd |Mais |Maar |Ma |Lorsque |Lorsqu\'|Kun |Kuid |Kui |Khi |Keď |Ketika |Když |Kaj |Kai |Kada |Kad |Jeżeli |Ja |Ir |I CAN HAZ |I |Ha |Givun |Givet |Given y\'all |Given |Gitt |Gegeven |Gegeben sei |Fakat |Eğer ki |Etant donné |Et |Então |Entonces |Entao |En |Eeldades |E |Duota |Dun |Donitaĵo |Donat |Donada |Do |Diyelim ki |Dengan |Den youse gotta |De |Dato |Dar |Dann |Dan |Dado |Dacă |Daca |DEN |Când |Cuando |Cho |Cept |Cand |Cal |But y\'all |But |Buh |Biết |Bet |BUT |Atès |Atunci |Atesa |Anrhegedig a |Angenommen |And y\'all |And |An |Ama |Als |Alors |Allora |Ali |Aleshores |Ale |Akkor |Aber |AN |A také |A |\\* )'
  24. tokens = {
  25. 'comments': [
  26. (r'^\s*#.*$', Comment),
  27. ],
  28. 'feature_elements': [
  29. (step_keywords, Keyword, "step_content_stack"),
  30. include('comments'),
  31. (r"(\s|.)", Name.Function),
  32. ],
  33. 'feature_elements_on_stack': [
  34. (step_keywords, Keyword, "#pop:2"),
  35. include('comments'),
  36. (r"(\s|.)", Name.Function),
  37. ],
  38. 'examples_table': [
  39. (r"\s+\|", Keyword, 'examples_table_header'),
  40. include('comments'),
  41. (r"(\s|.)", Name.Function),
  42. ],
  43. 'examples_table_header': [
  44. (r"\s+\|\s*$", Keyword, "#pop:2"),
  45. include('comments'),
  46. (r"\\\|", Name.Variable),
  47. (r"\s*\|", Keyword),
  48. (r"[^|]", Name.Variable),
  49. ],
  50. 'scenario_sections_on_stack': [
  51. (feature_element_keywords,
  52. bygroups(Name.Function, Keyword, Keyword, Name.Function),
  53. "feature_elements_on_stack"),
  54. ],
  55. 'narrative': [
  56. include('scenario_sections_on_stack'),
  57. include('comments'),
  58. (r"(\s|.)", Name.Function),
  59. ],
  60. 'table_vars': [
  61. (r'(<[^>]+>)', Name.Variable),
  62. ],
  63. 'numbers': [
  64. (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', String),
  65. ],
  66. 'string': [
  67. include('table_vars'),
  68. (r'(\s|.)', String),
  69. ],
  70. 'py_string': [
  71. (r'"""', Keyword, "#pop"),
  72. include('string'),
  73. ],
  74. 'step_content_root': [
  75. (r"$", Keyword, "#pop"),
  76. include('step_content'),
  77. ],
  78. 'step_content_stack': [
  79. (r"$", Keyword, "#pop:2"),
  80. include('step_content'),
  81. ],
  82. 'step_content': [
  83. (r'"', Name.Function, "double_string"),
  84. include('table_vars'),
  85. include('numbers'),
  86. include('comments'),
  87. (r'(\s|.)', Name.Function),
  88. ],
  89. 'table_content': [
  90. (r"\s+\|\s*$", Keyword, "#pop"),
  91. include('comments'),
  92. (r"\\\|", String),
  93. (r"\s*\|", Keyword),
  94. include('string'),
  95. ],
  96. 'double_string': [
  97. (r'"', Name.Function, "#pop"),
  98. include('string'),
  99. ],
  100. 'root': [
  101. (r'\n', Name.Function),
  102. include('comments'),
  103. (r'"""', Keyword, "py_string"),
  104. (r'\s+\|', Keyword, 'table_content'),
  105. (r'"', Name.Function, "double_string"),
  106. include('table_vars'),
  107. include('numbers'),
  108. (r'(\s*)(@[^@\r\n\t ]+)', bygroups(Name.Function, Name.Tag)),
  109. (step_keywords, bygroups(Name.Function, Keyword),
  110. 'step_content_root'),
  111. (feature_keywords, bygroups(Keyword, Keyword, Name.Function),
  112. 'narrative'),
  113. (feature_element_keywords,
  114. bygroups(Name.Function, Keyword, Keyword, Name.Function),
  115. 'feature_elements'),
  116. (examples_keywords,
  117. bygroups(Name.Function, Keyword, Keyword, Name.Function),
  118. 'examples_table'),
  119. (r'(\s|.)', Name.Function),
  120. ]
  121. }
  122. class TAPLexer(RegexLexer):
  123. """
  124. For Test Anything Protocol (TAP) output.
  125. .. versionadded:: 2.1
  126. """
  127. name = 'TAP'
  128. aliases = ['tap']
  129. filenames = ['*.tap']
  130. tokens = {
  131. 'root': [
  132. # A TAP version may be specified.
  133. (r'^TAP version \d+\n', Name.Namespace),
  134. # Specify a plan with a plan line.
  135. (r'^1\.\.\d+', Keyword.Declaration, 'plan'),
  136. # A test failure
  137. (r'^(not ok)([^\S\n]*)(\d*)',
  138. bygroups(Generic.Error, Text, Number.Integer), 'test'),
  139. # A test success
  140. (r'^(ok)([^\S\n]*)(\d*)',
  141. bygroups(Keyword.Reserved, Text, Number.Integer), 'test'),
  142. # Diagnostics start with a hash.
  143. (r'^#.*\n', Comment),
  144. # TAP's version of an abort statement.
  145. (r'^Bail out!.*\n', Generic.Error),
  146. # TAP ignores any unrecognized lines.
  147. (r'^.*\n', Text),
  148. ],
  149. 'plan': [
  150. # Consume whitespace (but not newline).
  151. (r'[^\S\n]+', Text),
  152. # A plan may have a directive with it.
  153. (r'#', Comment, 'directive'),
  154. # Or it could just end.
  155. (r'\n', Comment, '#pop'),
  156. # Anything else is wrong.
  157. (r'.*\n', Generic.Error, '#pop'),
  158. ],
  159. 'test': [
  160. # Consume whitespace (but not newline).
  161. (r'[^\S\n]+', Text),
  162. # A test may have a directive with it.
  163. (r'#', Comment, 'directive'),
  164. (r'\S+', Text),
  165. (r'\n', Text, '#pop'),
  166. ],
  167. 'directive': [
  168. # Consume whitespace (but not newline).
  169. (r'[^\S\n]+', Comment),
  170. # Extract todo items.
  171. (r'(?i)\bTODO\b', Comment.Preproc),
  172. # Extract skip items.
  173. (r'(?i)\bSKIP\S*', Comment.Preproc),
  174. (r'\S+', Comment),
  175. (r'\n', Comment, '#pop:2'),
  176. ],
  177. }