def test_tosexp_str_as(): yield (eq_, tosexp('a', str_as='symbol'), 'a') yield (eq_, tosexp(['a'], str_as='symbol'), '(a)') yield (eq_, tosexp('a'), '"a"') yield (eq_, tosexp(['a']), '("a")') yield (eq_, tosexp(Quoted('a')), '\'"a"') yield (eq_, tosexp(Quoted(['a']), str_as='symbol'), '\'(a)') yield (eq_, tosexp([Quoted('a')], str_as='symbol'), '(\'a)') yield (eq_, tosexp(Quoted('a'), str_as='symbol'), '\'a') yield (eq_, tosexp(Quoted(['a'])), '\'("a")') yield (eq_, tosexp([Quoted('a')]), '(\'"a")')
def ps(exp): if exp.op == 'lit': return sexpdata.tosexp(exp.args[0]) elif exp.op == 'var': return '(@%d %s)' % (i, exp.args[0]) elif exp.op in ['apply', 'exists']: _printtree(indent, exp.args[0], m, buf) return sexpdata.tosexp(exp) else: return '(%s %s)' % (exp.op, ' '.join( _printscalar(indent, i, m, buf) for i in exp.args))
def test_dump_raw_utf8(self): """ Test that sexpdata supports dumping encoded (raw) string. See also: https://github.com/tkf/emacs-jedi/issues/43 """ ustr = self.ustr sexp = utf8('"{0}"').format(ustr) self.assertEqual(tosexp(ustr.encode('utf-8')), sexp)
def test_tosexp_tuple_as(): yield (eq_, tosexp(('a', 'b')), '("a" "b")') yield (eq_, tosexp(('a', 'b'), tuple_as='array'), '["a" "b"]') yield (eq_, tosexp([('a', 'b')]), '(("a" "b"))') yield (eq_, tosexp([('a', 'b')], tuple_as='array'), '(["a" "b"])') yield (eq_, tosexp(Quoted(('a', ))), '\'("a")') yield (eq_, tosexp(Quoted(('a', )), tuple_as='array'), '\'["a"]')
def test_tosexp_tuple_as(): yield (eq_, tosexp(('a', 'b')), '("a" "b")') yield (eq_, tosexp(('a', 'b'), tuple_as='array'), '["a" "b"]') yield (eq_, tosexp([('a', 'b')]), '(("a" "b"))') yield (eq_, tosexp([('a', 'b')], tuple_as='array'), '(["a" "b"])') yield (eq_, tosexp(Quoted(('a',))), '\'("a")') yield (eq_, tosexp(Quoted(('a',)), tuple_as='array'), '\'["a"]')
def to_sexp(self): sexp = [[ "caller", [["name", "\"{}\"".format(self.caller.name)], ["range", self.caller.range]] ], [ "inline", [["name", "\"{}\"".format(self.inline.name)], ["range", self.inline.range]] ], [ "callees", [["ranges", [callee.range for callee in self.callees]]] ]] return sexpdata.tosexp(sexp, str_as='symbol')
def to_sexp(t): if hasattr(t, 'to_sexp'): return t.to_sexp() return sexpdata.tosexp(t, str_as='symbol')
def check_identity(obj): eq_(parse(tosexp(obj))[0], obj)
def test_tosexp_value_errors(): tosexp((), tuple_as='') tosexp('', str_as='') tosexp(Parens())
def __repr__(self): return sexpdata.tosexp(dict(self))