summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2017-04-23 01:02:29 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2017-04-23 16:31:33 +0900
commit96fa6d2972ea7c77525607ec490daed9e303535d (patch)
tree610c22b6788db2b6c5449cf4819fa5ac190e30d6
parentdb377ceb5524ec276ac6d18ed3206b8147800ae7 (diff)
downloadsphinx-git-96fa6d2972ea7c77525607ec490daed9e303535d.tar.gz
Implement get_full_qualified_name() to JavascriptDomain (refs: #3630)
-rw-r--r--sphinx/domains/javascript.py10
-rw-r--r--tests/test_domain_js.py32
-rw-r--r--tests/test_ext_intersphinx.py24
-rw-r--r--tests/test_util_inventory.py4
4 files changed, 70 insertions, 0 deletions
diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py
index 9d6bf1908..9ecf4a4b0 100644
--- a/sphinx/domains/javascript.py
+++ b/sphinx/domains/javascript.py
@@ -398,6 +398,16 @@ class JavaScriptDomain(Domain):
yield refname, refname, type, docname, \
refname.replace('$', '_S_'), 1
+ def get_full_qualified_name(self, node):
+ # type: (nodes.Node) -> unicode
+ modname = node.get('js:module')
+ prefix = node.get('js:object')
+ target = node.get('reftarget')
+ if target is None:
+ return None
+ else:
+ return '.'.join(filter(None, [modname, prefix, target]))
+
def setup(app):
# type: (Sphinx) -> Dict[unicode, Any]
diff --git a/tests/test_domain_js.py b/tests/test_domain_js.py
index e521d00c3..a3915c563 100644
--- a/tests/test_domain_js.py
+++ b/tests/test_domain_js.py
@@ -10,7 +10,11 @@
"""
import pytest
+from mock import Mock
+from docutils import nodes
+
from sphinx import addnodes
+from sphinx.domains.javascript import JavaScriptDomain
from util import assert_node
@@ -133,3 +137,31 @@ def test_domain_js_find_obj(app, status, warning):
( u'module_a.submodule.ModTopLevel.mod_child_2', (u'module', u'method')))
assert (find_obj(u'module_b.submodule', u'ModTopLevel', u'module_a.submodule', u'mod') ==
( u'module_a.submodule', (u'module', u'module')))
+
+
+def test_get_full_qualified_name():
+ env = Mock(domaindata={})
+ domain = JavaScriptDomain(env)
+
+ # non-js references
+ node = nodes.reference()
+ assert domain.get_full_qualified_name(node) is None
+
+ # simple reference
+ node = nodes.reference(reftarget='func')
+ assert domain.get_full_qualified_name(node) == 'func'
+
+ # with js:module context
+ kwargs = {'js:module': 'module1'}
+ node = nodes.reference(reftarget='func', **kwargs)
+ assert domain.get_full_qualified_name(node) == 'module1.func'
+
+ # with js:object context
+ kwargs = {'js:object': 'Class'}
+ node = nodes.reference(reftarget='func', **kwargs)
+ assert domain.get_full_qualified_name(node) == 'Class.func'
+
+ # with both js:module and js:object context
+ kwargs = {'js:module': 'module1', 'js:object': 'Class'}
+ node = nodes.reference(reftarget='func', **kwargs)
+ assert domain.get_full_qualified_name(node) == 'module1.Class.func'
diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py
index 0fa6c93b7..4774604e8 100644
--- a/tests/test_ext_intersphinx.py
+++ b/tests/test_ext_intersphinx.py
@@ -212,6 +212,30 @@ def test_missing_reference_stddomain(tempdir, app, status, warning):
assert rn.astext() == 'ls -l'
+def test_missing_reference_jsdomain(tempdir, app, status, warning):
+ inv_file = tempdir / 'inventory'
+ inv_file.write_bytes(inventory_v2)
+ app.config.intersphinx_mapping = {
+ 'https://docs.python.org/': inv_file,
+ }
+ app.config.intersphinx_cache_limit = 0
+
+ # load the inventory and check if it's done correctly
+ load_mappings(app)
+
+ # no context data
+ kwargs = {}
+ node, contnode = fake_node('js', 'meth', 'baz', 'baz()', **kwargs)
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn is None
+
+ # js:module and js:object context helps to search objects
+ kwargs = {'js:module': 'foo', 'js:object': 'bar'}
+ node, contnode = fake_node('js', 'meth', 'baz', 'baz()', **kwargs)
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'baz()'
+
+
def test_load_mappings_warnings(tempdir, app, status, warning):
"""
load_mappings issues a warning if new-style mapping
diff --git a/tests/test_util_inventory.py b/tests/test_util_inventory.py
index 747fe53cf..35f80d960 100644
--- a/tests/test_util_inventory.py
+++ b/tests/test_util_inventory.py
@@ -37,6 +37,10 @@ CFunc c:function 2 cfunc.html#CFunc -
a term std:term -1 glossary.html#term-a-term -
ls.-l std:cmdoption 1 index.html#cmdoption-ls-l -
docname std:doc -1 docname.html -
+foo js:module 1 index.html#foo -
+foo.bar js:class 1 index.html#foo.bar -
+foo.bar.baz js:method 1 index.html#foo.bar.baz -
+foo.bar.qux js:data 1 index.html#foo.bar.qux -
a term including:colon std:term -1 glossary.html#term-a-term-including-colon -
'''.encode('utf-8'))