Commits

Takayuki Shimizukawa committed 9477ea8

add tests for "multiple cross references in the same line return the same link". refs #1090, #1193

Comments (0)

Files changed (4)

sphinx/transforms.py

             if len(old_refs) != len(new_refs):
                 env.warn_node('inconsistent term references in '
                               'translated message', node)
-            def get_key(node):
-                key = node["refdomain"], node["reftype"]
-                if key == ('std', 'term'):
-                    key = None
-                elif key == ('std', 'ref'):
-                    key += (node['reftarget'],)
-                elif key == ('', 'doc'):
-                    key += (node['reftarget'],)
+            def get_ref_key(node):
+                case = node["refdomain"], node["reftype"]
+                if case == ('std', 'term'):
+                    return None
                 else:
-                    pass
-                return key
+                    return (
+                        node["refdomain"],
+                        node["reftype"],
+                        node['reftarget'],)
 
             for old in old_refs:
-                key = get_key(old)
+                key = get_ref_key(old)
                 if key:
                     xref_reftarget_map[key] = old["reftarget"]
             for new in new_refs:
-                key = get_key(new)
+                key = get_ref_key(new)
                 if key in xref_reftarget_map:
                     new['reftarget'] = xref_reftarget_map[key]
 

tests/roots/test-intl/role_xref.po

 msgid "link to :doc:`contents` and :doc:`glossary_terms`."
 msgstr "LINK TO :doc:`glossary_terms` AND :doc:`contents`."
 
+msgid "link to :option:`-m` and :option:`--module`."
+msgstr "LINK TO :option:`--module` AND :option:`-m`."
+
+msgid "link to :envvar:`env1` and :envvar:`env2`."
+msgstr "LINK TO :envvar:`env2` AND :envvar:`env1`."
+
+msgid "link to :token:`token1` and :token:`token2`."
+msgstr "LINK TO :token:`token2` AND :token:`token1`."
+
+msgid "link to :keyword:`i18n-role-xref` and :keyword:`same-type-links`."
+msgstr "LINK TO :keyword:`same-type-links` AND :keyword:`i18n-role-xref`."

tests/roots/test-intl/role_xref.txt

 link to :ref:`i18n-role-xref` and :ref:`same-type-links`.
 
 link to :doc:`contents` and :doc:`glossary_terms`.
+
+link to :option:`-m` and :option:`--module`.
+
+link to :envvar:`env1` and :envvar:`env2`.
+
+link to :token:`token1` and :token:`token2`.
+
+link to :keyword:`i18n-role-xref` and :keyword:`same-type-links`.
+
+
+.. option:: -m <module>
+
+.. option:: --module <module>
+
+.. envvar:: env1
+
+.. envvar:: env2
+
+.. productionlist::
+   token_stmt: `token1` ":" `token2`
+

tests/test_intl.py

              'contents',
              'glossary_terms#term-some-new-term'])
 
-    para21, para22, para23 = sec2.findall('paragraph')
+    para2 = sec2.findall('paragraph')
     assert_text_refs(
-            para21,
+            para2[0],
             ['LINK TO', 'SOME OTHER NEW TERM', 'AND', 'SOME NEW TERM', '.'],
             ['glossary_terms#term-some-other-new-term',
              'glossary_terms#term-some-new-term'])
     assert_text_refs(
-            para22,
+            para2[1],
             ['LINK TO', 'SAME TYPE LINKS', 'AND', "I18N ROCK'N ROLE XREF", '.'],
             ['same-type-links', 'i18n-role-xref'])
     assert_text_refs(
-            para23,
+            para2[2],
             ['LINK TO', 'I18N WITH GLOSSARY TERMS', 'AND', 'CONTENTS', '.'],
             ['glossary_terms', 'contents'])
+    assert_text_refs(
+            para2[3],
+            ['LINK TO', '--module', 'AND', '-m', '.'],
+            ['cmdoption--module', 'cmdoption-m'])
+    assert_text_refs(
+            para2[4],
+            ['LINK TO', 'env2', 'AND', 'env1', '.'],
+            ['envvar-env2', 'envvar-env1'])
+    assert_text_refs(
+            para2[5],
+            ['LINK TO', 'token2', 'AND', 'token1', '.'],
+            [])  #TODO: how do I link token role to productionlist?
+    assert_text_refs(
+            para2[6],
+            ['LINK TO', 'same-type-links', 'AND', "i18n-role-xref", '.'],
+            ['same-type-links', 'i18n-role-xref'])
 
     #warnings
     warnings = warnfile.getvalue().replace(os.sep, '/')