From 2ac807a0668bb90aa653da86bd51f86e9824b8a3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 9 Aug 2009 22:44:41 +0200 Subject: [PATCH] Add more tests for markup. --- sphinx/directives/other.py | 2 +- sphinx/roles.py | 2 +- tests/root/desc.txt | 6 +++ tests/root/markup.txt | 94 +++++++++++++++++++++++--------------- tests/test_build.py | 45 +++++++++++++++--- 5 files changed, 104 insertions(+), 45 deletions(-) diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 977b16919..ed42e3d23 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -260,7 +260,7 @@ class SeeAlso(Directive): return ret -token_re = re.compile('`([a-z_]+)`') +token_re = re.compile('`([a-z_][a-z0-9_]*)`') def token_xrefs(text, env): retnodes = [] diff --git a/sphinx/roles.py b/sphinx/roles.py index d896641ad..db231463f 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -29,7 +29,7 @@ generic_docroles = { 'manpage' : addnodes.literal_emphasis, 'mimetype' : addnodes.literal_emphasis, 'newsgroup' : addnodes.literal_emphasis, - 'program' : nodes.strong, + 'program' : nodes.strong, # XXX should be an x-ref 'regexp' : nodes.literal, } diff --git a/tests/root/desc.txt b/tests/root/desc.txt index 3b225c78a..43519773e 100644 --- a/tests/root/desc.txt +++ b/tests/root/desc.txt @@ -54,6 +54,12 @@ C items .. c:var:: sphinx_global +References +========== + +:c:func:`CFunction`. :c:func:`!malloc`. + + Others ====== diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 86e039acd..3d328e8d3 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -5,6 +5,9 @@ Testing various markup ====================== +Meta markup +----------- + .. sectionauthor:: Georg Brandl .. contents:: TOC @@ -13,7 +16,11 @@ Testing various markup :author: Me :keywords: docs, sphinx -A |subst|. + +Generic reST +------------ + +A |subst| (the definition is in rst_epilog). .. _label: @@ -21,31 +28,14 @@ A |subst|. some code -Inline ------- +Option list: -Inline markup: - -* :pep:`8` -* :rfc:`1` -* :envvar:`HOME` - -Admonitions ------------ - -.. note:: Note - Note text. - -.. warning:: Warning - - Warning text. - -.. tip:: - Tip text. +-h help +--help also help Body directives ---------------- +^^^^^^^^^^^^^^^ .. topic:: Title @@ -78,7 +68,51 @@ Body directives b - + +Admonitions +^^^^^^^^^^^ + +.. admonition:: My Admonition + + Admonition text. + +.. note:: + Note text. + +.. warning:: + + Warning text. + +.. tip:: + Tip text. + + +Inline markup +------------- + +*Generic inline markup* + +* :command:`command` +* :dfn:`dfn` +* :guilabel:`guilabel` +* :kbd:`kbd` +* :mailheader:`mailheader` +* :makevar:`makevar` +* :manpage:`manpage` +* :mimetype:`mimetype` +* :newsgroup:`newsgroup` +* :program:`program` +* :regexp:`regexp` + +*Linking inline markup* + +* :pep:`8` +* :rfc:`1` +* :envvar:`HOME` + +Test :abbr:`abbr (abbreviation)` and another :abbr:`abbr (abbreviation)`. + + Tables ------ @@ -133,11 +167,6 @@ This is a side note. This tests :CLASS:`role names in uppercase`. -Option list: - --h help ---help also help - .. centered:: LICENSE AGREEMENT .. acks:: @@ -155,7 +184,7 @@ Option list: Particle with half-integer spin. .. productionlist:: - try_stmt: try1_stmt | try2_stmt + try_stmt: `try1_stmt` | `try2_stmt` try1_stmt: "try" ":" `suite` : ("except" [`expression` ["," `target`]] ":" `suite`)+ : ["else" ":" `suite`] @@ -163,7 +192,6 @@ Option list: try2_stmt: "try" ":" `suite` : "finally" ":" `suite` -Test :abbr:`abbr (abbreviation)` and another :abbr:`abbr (abbreviation)`. Index markup ------------ @@ -188,12 +216,6 @@ Invalid index markup... Testing öäü... -Object markup -------------- - -:c:func:`CFunction`. :c:func:`!malloc`. - - Only directive -------------- diff --git a/tests/test_build.py b/tests/test_build.py index 754805e98..1e36b12d3 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -84,20 +84,50 @@ HTML_XPATH = { ".//dd": r'Return spam\.', }, 'markup.html': { + ".//title": 'set by title directive', + # created by the meta directive ".//meta[@name='author'][@content='Me']": '', ".//meta[@name='keywords'][@content='docs, sphinx']": '', - ".//a[@href='contents.html#ref1']": '', + # a label created by ``.. _label:`` ".//div[@id='label']": '', + # code with standard code blocks + ".//pre": '^some code$', + # an option list ".//span[@class='option']": '--help', + # admonitions + ".//p[@class='first admonition-title']": 'My Admonition', + ".//p[@class='last']": 'Note text.', + ".//p[@class='last']": 'Warning text.', + # inline markup + ".//li/strong": '^command$', + ".//li/strong": '^program$', + ".//li/em": '^dfn$', + ".//li/tt/span[@class='pre']": '^kbd$', + ".//a[@href='desc.html#envvar-HOME']/tt/span[@class='pre']": 'HOME', + ".//a[@href='http://www.python.org/dev/peps/pep-0008']/strong": 'PEP 8', + ".//a[@href='http://tools.ietf.org/html/rfc1.html']/strong": 'RFC 1', + # abbreviations + ".//abbr[@title='abbreviation']": '^abbr$', + # version stuff + ".//span[@class='versionmodified']": 'New in version 0.6', + # footnote reference + ".//a[@class='footnote-reference']": r'\[1\]', + # created by reference lookup + ".//a[@href='contents.html#ref1']": '', + # a ``hlist`` directive + ".//table[@class='hlist']/tr/td/ul/li": '^This$', + # a ``centered`` directive + ".//p[@class='centered']/strong": 'LICENSE', + # a glossary + ".//dl/dt[@id='term-boson']": 'boson', + # a production list + ".//pre/strong": 'try_stmt', + ".//pre/a[@href='grammar-token-try1_stmt']/tt/span": 'try1_stmt', + # tests for ``only`` directive ".//p": 'A global substitution.', ".//p": 'In HTML.', ".//p": 'In both.', ".//p": 'Always present', - ".//title": 'set by title directive', - ".//span[@class='pre']": 'CFunction()', - ".//a[@href='desc.html#envvar-HOME']/tt/span[@class='pre']": 'HOME', - ".//a[@href='http://www.python.org/dev/peps/pep-0008']/strong": 'PEP 8', - ".//a[@href='http://tools.ietf.org/html/rfc1.html']/strong": 'RFC 1', }, 'desc.html': { ".//dt[@id='mod.Cls.meth1']": '', @@ -106,6 +136,7 @@ HTML_XPATH = { ".//dl[@class='userdesc']": '', ".//dt[@id='userdescrole-myobj']": '', ".//a[@href='#userdescrole-myobj']": '', + ".//span[@class='pre']": 'CFunction()', }, 'contents.html': { ".//meta[@name='hc'][@content='hcval']": '', @@ -113,7 +144,7 @@ HTML_XPATH = { #".//td[@class='label']": r'\[Ref1\]', # docutils 0.5 only ".//td[@class='label']": '', ".//li[@class='toctree-l1']/a": 'Testing various markup', - ".//li[@class='toctree-l2']/a": 'Admonitions', + ".//li[@class='toctree-l2']/a": 'Inline markup', ".//title": 'Sphinx ', ".//div[@class='footer']": 'Georg Brandl & Team', ".//a[@href='http://python.org/']": '',