testing.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. """
  2. pygments.lexers.testing
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for testing languages.
  5. :copyright: Copyright 2006-2024 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 syntax.
  14. """
  15. name = 'Gherkin'
  16. aliases = ['gherkin', 'cucumber']
  17. filenames = ['*.feature']
  18. mimetypes = ['text/x-gherkin']
  19. url = 'https://cucumber.io/docs/gherkin'
  20. version_added = '1.2'
  21. 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)(:)(.*)$'
  22. 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)(:)(.*)$'
  23. 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)(:)(.*)$'
  24. 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 |\\* )'
  25. tokens = {
  26. 'comments': [
  27. (r'^\s*#.*$', Comment),
  28. ],
  29. 'feature_elements': [
  30. (step_keywords, Keyword, "step_content_stack"),
  31. include('comments'),
  32. (r"(\s|.)", Name.Function),
  33. ],
  34. 'feature_elements_on_stack': [
  35. (step_keywords, Keyword, "#pop:2"),
  36. include('comments'),
  37. (r"(\s|.)", Name.Function),
  38. ],
  39. 'examples_table': [
  40. (r"\s+\|", Keyword, 'examples_table_header'),
  41. include('comments'),
  42. (r"(\s|.)", Name.Function),
  43. ],
  44. 'examples_table_header': [
  45. (r"\s+\|\s*$", Keyword, "#pop:2"),
  46. include('comments'),
  47. (r"\\\|", Name.Variable),
  48. (r"\s*\|", Keyword),
  49. (r"[^|]", Name.Variable),
  50. ],
  51. 'scenario_sections_on_stack': [
  52. (feature_element_keywords,
  53. bygroups(Name.Function, Keyword, Keyword, Name.Function),
  54. "feature_elements_on_stack"),
  55. ],
  56. 'narrative': [
  57. include('scenario_sections_on_stack'),
  58. include('comments'),
  59. (r"(\s|.)", Name.Function),
  60. ],
  61. 'table_vars': [
  62. (r'(<[^>]+>)', Name.Variable),
  63. ],
  64. 'numbers': [
  65. (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', String),
  66. ],
  67. 'string': [
  68. include('table_vars'),
  69. (r'(\s|.)', String),
  70. ],
  71. 'py_string': [
  72. (r'"""', Keyword, "#pop"),
  73. include('string'),
  74. ],
  75. 'step_content_root': [
  76. (r"$", Keyword, "#pop"),
  77. include('step_content'),
  78. ],
  79. 'step_content_stack': [
  80. (r"$", Keyword, "#pop:2"),
  81. include('step_content'),
  82. ],
  83. 'step_content': [
  84. (r'"', Name.Function, "double_string"),
  85. include('table_vars'),
  86. include('numbers'),
  87. include('comments'),
  88. (r'(\s|.)', Name.Function),
  89. ],
  90. 'table_content': [
  91. (r"\s+\|\s*$", Keyword, "#pop"),
  92. include('comments'),
  93. (r"\\\|", String),
  94. (r"\s*\|", Keyword),
  95. include('string'),
  96. ],
  97. 'double_string': [
  98. (r'"', Name.Function, "#pop"),
  99. include('string'),
  100. ],
  101. 'root': [
  102. (r'\n', Name.Function),
  103. include('comments'),
  104. (r'"""', Keyword, "py_string"),
  105. (r'\s+\|', Keyword, 'table_content'),
  106. (r'"', Name.Function, "double_string"),
  107. include('table_vars'),
  108. include('numbers'),
  109. (r'(\s*)(@[^@\r\n\t ]+)', bygroups(Name.Function, Name.Tag)),
  110. (step_keywords, bygroups(Name.Function, Keyword),
  111. 'step_content_root'),
  112. (feature_keywords, bygroups(Keyword, Keyword, Name.Function),
  113. 'narrative'),
  114. (feature_element_keywords,
  115. bygroups(Name.Function, Keyword, Keyword, Name.Function),
  116. 'feature_elements'),
  117. (examples_keywords,
  118. bygroups(Name.Function, Keyword, Keyword, Name.Function),
  119. 'examples_table'),
  120. (r'(\s|.)', Name.Function),
  121. ]
  122. }
  123. def analyse_text(self, text):
  124. return
  125. class TAPLexer(RegexLexer):
  126. """
  127. For Test Anything Protocol (TAP) output.
  128. """
  129. name = 'TAP'
  130. url = 'https://testanything.org/'
  131. aliases = ['tap']
  132. filenames = ['*.tap']
  133. version_added = '2.1'
  134. tokens = {
  135. 'root': [
  136. # A TAP version may be specified.
  137. (r'^TAP version \d+\n', Name.Namespace),
  138. # Specify a plan with a plan line.
  139. (r'^1\.\.\d+', Keyword.Declaration, 'plan'),
  140. # A test failure
  141. (r'^(not ok)([^\S\n]*)(\d*)',
  142. bygroups(Generic.Error, Text, Number.Integer), 'test'),
  143. # A test success
  144. (r'^(ok)([^\S\n]*)(\d*)',
  145. bygroups(Keyword.Reserved, Text, Number.Integer), 'test'),
  146. # Diagnostics start with a hash.
  147. (r'^#.*\n', Comment),
  148. # TAP's version of an abort statement.
  149. (r'^Bail out!.*\n', Generic.Error),
  150. # TAP ignores any unrecognized lines.
  151. (r'^.*\n', Text),
  152. ],
  153. 'plan': [
  154. # Consume whitespace (but not newline).
  155. (r'[^\S\n]+', Text),
  156. # A plan may have a directive with it.
  157. (r'#', Comment, 'directive'),
  158. # Or it could just end.
  159. (r'\n', Comment, '#pop'),
  160. # Anything else is wrong.
  161. (r'.*\n', Generic.Error, '#pop'),
  162. ],
  163. 'test': [
  164. # Consume whitespace (but not newline).
  165. (r'[^\S\n]+', Text),
  166. # A test may have a directive with it.
  167. (r'#', Comment, 'directive'),
  168. (r'\S+', Text),
  169. (r'\n', Text, '#pop'),
  170. ],
  171. 'directive': [
  172. # Consume whitespace (but not newline).
  173. (r'[^\S\n]+', Comment),
  174. # Extract todo items.
  175. (r'(?i)\bTODO\b', Comment.Preproc),
  176. # Extract skip items.
  177. (r'(?i)\bSKIP\S*', Comment.Preproc),
  178. (r'\S+', Comment),
  179. (r'\n', Comment, '#pop:2'),
  180. ],
  181. }