diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index 3fb77a3..39f690a 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -126,6 +126,27 @@ def test_unicode_completions(): nt.assert_true(isinstance(text, string_types)) nt.assert_true(isinstance(matches, list)) +@dec.onlyif(sys.version_info[0] >= 3, 'This test only applies in Py>=3') +def test_latex_completions(): + from IPython.core.latex_symbols import latex_symbols + import random + ip = get_ipython() + # Test some random unicode symbols + keys = random.sample(latex_symbols.keys(), 10) + for k in keys: + text, matches = ip.complete(k) + nt.assert_equal(len(matches),1) + nt.assert_equal(text, k) + mt.assert_equal(matches[0], latex_symbols[k]) + # Test a more complex line + text, matches = ip.complete(u'print(\\alpha') + nt.assert_equals(text, u'\\alpha') + nt.assert_equals(matches[0], latex_symbols['\\alpha']) + # Test multiple matching latex symbols + text, matches = ip.complete(u'\\al') + nt.assert_in('\\alpha', matches) + nt.assert_in('\\aleph', matches) + class CompletionSplitterTestCase(unittest.TestCase): def setUp(self): diff --git a/IPython/html/static/notebook/js/codemirror-ipython.js b/IPython/html/static/notebook/js/codemirror-ipython.js index 575abad..351c98f 100644 --- a/IPython/html/static/notebook/js/codemirror-ipython.js +++ b/IPython/html/static/notebook/js/codemirror-ipython.js @@ -15,7 +15,12 @@ CodeMirror.requireMode('python',function(){ } pythonConf.name = 'python'; pythonConf.singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]"); - pythonConf.identifiers = new RegExp("^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*"); + if (pythonConf.version === 3) { + console.log('setting up for python 3'); + pythonConf.identifiers = new RegExp("^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*"); + } else if (pythonConf.version === 2) { + pythonConf.identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*"); + } return CodeMirror.getMode(conf, pythonConf); }, 'python');