예제 #1
0
 def validate(input, quoted, expected):
     fragments = []
     pymacs.print_lisp(input, fragments.append, quoted)
     output = re.sub(r'\(pymacs-(defun|python) [0-9]*',
                     r'(pymacs-\1 0',
                     ''.join(fragments))
     assert output == expected, (output, expected)
예제 #2
0
def test_2():

    def validate(input, expected):
        output = setup.ask_emacs(
            input,
            '(lambda (expression)\n'
            '  (let ((pymacs-forget-mutability t))\n'
            '    (pymacs-print-for-eval expression)))\n')
        output = re.sub(r'\(pymacs-(defun|python) [0-9]*',
                        r'(pymacs-\1 0',
                        output)
        assert output == expected, (output, expected)

    for quotable, input, output in (
            (False, None, 'None'),
            (False, False, 'None'),
            (False, True, 'True'),
            (False, 3, '3'),
            (False, 0, '0'),
            (False, -3, '-3'),
            (False, 3., '3.0'),
            (False, 0., '0.0'),
            (False, -3., '-3.0'),
            (False, '', '""'),
            (False, 'a', '"a"'),
            (False, 'byz', '"byz"'),
            (False, 'c\'bz', '"c\'bz"'),
            (False, 'd"z', r'"d\"z"'),
            (False, 'e\\bz', r'"e\\bz"'),
            (False, 'f\bz', '"f\x08z"'),
            (False, 'g\fz', '"g\x0cz"'),
            (False, 'h\nz', r'"h\nz"'),
            (False, 'i\rz', '"i\rz"'),
            (False, 'j\r\nz', '"j\r\\nz"'),
            (False, 'k\tz', '"k\tz"'),
            (False, 'l\x1bz', '"l\x1bz"'),
            (False, (), '()'),
            (False, (0,), '(0,)'),
            (False, (0.0,), '(0.0,)'),
            (False, ('a',), '("a",)'),
            (False, (0, 0.0, "a"), '(0, 0.0, "a")'),
            (True, [], 'None'),
            (True, [0], '[0]'),
            (True, [0.0], '[0.0]'),
            (True, ['a'], '["a"]'),
            (True, [0, 0.0, "a"], '[0, 0.0, "a"]'),
            (False, lisp['nil'], 'None'),
            (True, lisp['t'], 'True'),
            (True, lisp['ab_cd'], 'lisp["ab_cd"]'),
            (True, lisp['ab-cd'], 'lisp["ab-cd"]'),
            (True, lisp['lambda'], 'lisp["lambda"]'),
            (False, lisp.nil, 'None'),
            (True, lisp.t, 'True'),
            (True, lisp.ab_cd, 'lisp["ab-cd"]'),
            # TODO: Lisp and derivatives
            ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, quotable)
        yield validate, ''.join(fragments), output
예제 #3
0
def test_2():
    def validate(input, expected):
        output = setup.ask_emacs(input, 'print-for-eval-expanded')
        output = re.sub(r'\(pymacs-(defun|python) [0-9]*', r'(pymacs-\1 0',
                        output)
        assert output == expected, (output, expected)

    for quotable, input, output in (
        (False, None, 'None'),
        (False, False, 'None'),
        (False, True, 'True'),
        (False, 3, '3'),
        (False, 0, '0'),
        (False, -3, '-3'),
        (False, 3., '3.0'),
        (False, 0., '0.0'),
        (False, -3., '-3.0'),
        (False, '', '""'),
        (False, 'a', '"a"'),
        (False, 'byz', '"byz"'),
        (False, 'c\'bz', '"c\'bz"'),
        (False, 'd"z', r'"d\"z"'),
        (False, 'e\\bz', r'"e\\bz"'),
        (False, 'f\bz', '"f\x08z"'),
        (False, 'g\fz', '"g\x0cz"'),
        (False, 'h\nz', r'"h\nz"'),
        (False, 'i\rz', '"i\rz"'),
        (False, 'j\r\nz', '"j\r\\nz"'),
        (False, 'k\tz', '"k\tz"'),
        (False, 'l\x1bz', '"l\x1bz"'),
        (False, (), '()'),
        (False, (0, ), '(0,)'),
        (False, (0.0, ), '(0.0,)'),
        (False, ('a', ), '("a",)'),
        (False, (0, 0.0, "a"), '(0, 0.0, "a")'),
        (True, [], 'None'),
        (True, [0], '[0]'),
        (True, [0.0], '[0.0]'),
        (True, ['a'], '["a"]'),
        (True, [0, 0.0, "a"], '[0, 0.0, "a"]'),
        (False, lisp['nil'], 'None'),
        (True, lisp['t'], 'True'),
        (True, lisp['ab_cd'], 'lisp["ab_cd"]'),
        (True, lisp['ab-cd'], 'lisp["ab-cd"]'),
        (True, lisp['lambda'], 'lisp["lambda"]'),
        (False, lisp.nil, 'None'),
        (True, lisp.t, 'True'),
        (True, lisp.ab_cd, 'lisp["ab-cd"]'),
            # TODO: Lisp and derivatives
    ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, quotable)
        yield validate, ''.join(fragments), output
예제 #4
0
def test_1():
    def validate(input, expected):
        output = setup.ask_emacs(input, 'prin1')
        output = re.sub(r'\(pymacs-(defun|python) [0-9]*', r'(pymacs-\1 0',
                        output)
        assert output == expected, (output, expected)

    if isinstance(bool, type):
        false_string = 'nil'
        true_string = 't'
    else:
        false_string = '0'
        true_string = '1'
    tests = []
    tests += [(False, None, 'nil'), (False, False, false_string),
              (False, True, true_string), (False, 3, '3'), (False, 0, '0'),
              (False, -3, '-3'), (False, 3., '3.0'), (False, 0., '0.0'),
              (False, -3., '-3.0'), (False, '', '""'), (False, 'a', '"a"'),
              (False, 'byz', '"byz"'), (False, 'c\'bz', '"c\'bz"'),
              (False, 'd"z', r'"d\"z"'), (False, 'e\\bz', r'"e\\bz"'),
              (False, 'f\bz', '"f\bz"'), (False, 'g\fz', '"g\fz"'),
              (False, 'h\nz', '"h\nz"'), (False, 'i\rz', '"i\rz"'),
              (False, 'j\r\nz', '"j\r\nz"'), (False, 'k\tz', '"k\tz"'),
              (False, 'l\x1bz', '"l\x1bz"')]

    tests += [(False, u'p', '"p"'), (False, u'qyz', '"qyz"'),
              (False, u'rêvé', '"r\303\252v\303\251"'),
              (False, u's—z!', '"s\342\200\224z!"')]
    tests += [(False, (), '[]'), (False, (0, ), '[0]'),
              (False, (0.0, ), '[0.0]'), (False, ('a', ), '["a"]'),
              (False, (0, 0.0, "a"), '[0 0.0 "a"]'), (True, [], 'nil'),
              (True, [0], '(0)'), (True, [0.0], '(0.0)'),
              (True, ['a'], '("a")'), (True, [0, 0.0, "a"], '(0 0.0 "a")'),
              (False, lisp['nil'], 'nil'), (True, lisp['t'], 't'),
              (True, lisp['ab_cd'], 'ab_cd'), (True, lisp['ab-cd'], 'ab-cd'),
              (True, lisp['lambda'], 'lambda'), (False, lisp.nil, 'nil'),
              (True, lisp.t, 't'), (True, lisp.ab_cd, 'ab-cd')]
    # TODO: Lisp and derivatives
    for quotable, input, output in tests:
        fragments = []
        pymacs.print_lisp(input, fragments.append, quotable)
        yield validate, ''.join(fragments), output
    tests = [(ord, '(pymacs-defun 0 nil)'), (object(), '(pymacs-python 0)')]
    for input, output in tests:
        fragments = []
        pymacs.print_lisp(input, fragments.append, True)
        yield validate, '\'' + ''.join(fragments), output
예제 #5
0
def test_1():
    def validate(input, expected):
        output = re.sub(r'\(pymacs-(defun|python) \. [0-9]*\)',
                        r'(pymacs-\1 . 0)',
                        setup.ask_emacs('(pymacs-eval %s)' % input, 'prin1'))
        assert output == expected, (output, expected)

    tests = []
    tests += [(False, None, 'nil'), (False, False, 'nil'), (False, True, 't'),
              (False, 3, '3'), (False, 0, '0'), (False, -3, '-3'),
              (False, 3., '3.0'), (False, 0., '0.0'), (False, -3., '-3.0'),
              (False, '', '""'), (False, 'a', '"a"'), (False, 'byz', '"byz"'),
              (False, 'c\'bz', '"c\'bz"'), (False, 'd"z', r'"d\"z"'),
              (False, 'e\\bz', r'"e\\bz"'), (False, 'f\bz', '"f\bz"'),
              (False, 'g\fz', '"g\fz"'), (False, 'h\nz', '"h\nz"'),
              (False, 'i\rz', '"i\rz"'), (False, 'j\r\nz', '"j\r\nz"'),
              (False, 'k\tz', '"k\tz"'), (False, 'l\x1bz', '"l\x1bz"')]

    tests += [(False, u'p', '"p"'), (False, u'qyz', '"qyz"'),
              (False, u'rêvé', '"r\303\252v\303\251"'),
              (False, u's—z!', '"s\342\200\224z!"')]
    tests += [(False, (), '[]'), (False, (0, ), '[0]'),
              (False, (0.0, ), '[0.0]'), (False, ('a', ), '["a"]'),
              (False, (0, 0.0, "a"), '[0 0.0 "a"]'), (True, [], 'nil'),
              (True, [0], '(0)'), (True, [0.0], '(0.0)'),
              (True, ['a'], '("a")'), (True, [0, 0.0, "a"], '(0 0.0 "a")'),
              (False, lisp['nil'], 'nil'), (True, lisp['t'], 't'),
              (True, lisp['ab_cd'], 'ab_cd'), (True, lisp['ab-cd'], 'ab-cd'),
              (True, lisp['lambda'], 'lambda'), (False, lisp.nil, 'nil'),
              (True, lisp.t, 't'), (True, lisp.ab_cd, 'ab-cd')]
    # TODO: Lisp and derivatives
    for quotable, input, output in tests:
        fragments = []

        pymacs.print_lisp(repr(input), fragments.append, quotable)
        yield validate, ''.join(fragments), output
    tests = [('ord', ('(lambda (&rest arguments)'
                      ' (pymacs-apply (quote (pymacs-python . 0))'
                      ' arguments))')), ('object()', '(pymacs-python . 0)')]
    for input, output in tests:
        fragments = []
        pymacs.print_lisp(input, fragments.append, True)
        yield validate, '\'' + ''.join(fragments), output
예제 #6
0
def test_1():

    def validate(input, expected):
        output = re.sub(r'\(pymacs-(defun|python) \. [0-9]*\)',
                        r'(pymacs-\1 . 0)',
                        setup.ask_emacs('(pymacs-eval %s)' % input, 'prin1'))
        assert output == expected, (output, expected)

    for quotable, input, output in (
            (False, None, 'nil'),
            (False, False, 'nil'),
            (False, True, 't'),
            (False, 3, '3'),
            (False, 0, '0'),
            (False, -3, '-3'),
            (False, 3., '3.0'),
            (False, 0., '0.0'),
            (False, -3., '-3.0'),
            (False, '', '""'),
            (False, 'a', '"a"'),
            (False, 'byz', '"byz"'),
            (False, 'c\'bz', '"c\'bz"'),
            (False, 'd"z', r'"d\"z"'),
            (False, 'e\\bz', r'"e\\bz"'),
            (False, 'f\bz', '"f\bz"'),
            (False, 'g\fz', '"g\fz"'),
            (False, 'h\nz', '"h\nz"'),
            (False, 'i\rz', '"i\rz"'),
            (False, 'j\r\nz', '"j\r\nz"'),
            (False, 'k\tz', '"k\tz"'),
            (False, 'l\x1bz', '"l\x1bz"'),
            (False, u'p', '"p"'),
            (False, u'qyz', '"qyz"'),
            (False, u'rêvé', '"r\303\252v\303\251"'),
            (False, u's—z!', '"s\342\200\224z!"'),
            (False, (), '[]'),
            (False, (0,), '[0]'),
            (False, (0.0,), '[0.0]'),
            (False, ('a',), '["a"]'),
            (False, (0, 0.0, "a"), '[0 0.0 "a"]'),
            (True, [], 'nil'),
            (True, [0], '(0)'),
            (True, [0.0], '(0.0)'),
            (True, ['a'], '("a")'),
            (True, [0, 0.0, "a"], '(0 0.0 "a")'),
            (False, lisp['nil'], 'nil'),
            (True, lisp['t'], 't'),
            (True, lisp['ab_cd'], 'ab_cd'),
            (True, lisp['ab-cd'], 'ab-cd'),
            (True, lisp['lambda'], 'lambda'),
            (False, lisp.nil, 'nil'),
            (True, lisp.t, 't'),
            (True, lisp.ab_cd, 'ab-cd'),
            # TODO: Lisp and derivatives
            ):
        fragments = []
        pymacs.print_lisp(repr(input), fragments.append, quotable)
        yield validate, ''.join(fragments), output
    for input, output in (
            ('ord', ('(lambda (&rest arguments)'
                     ' (pymacs-apply (quote (pymacs-python . 0)) arguments))')),
            ('object()', '(pymacs-python . 0)'),
            ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, True)
        yield validate, '\'' + ''.join(fragments), output
예제 #7
0
 def validate(input, quoted, expected):
     fragments = []
     pymacs.print_lisp(input, fragments.append, quoted)
     output = re.sub(r'\(pymacs-(defun|python) [0-9]*', r'(pymacs-\1 0',
                     ''.join(fragments))
     assert output == expected, (output, expected)
예제 #8
0
def test_1():

    def validate(input, expected):
        output = setup.ask_emacs(input, 'prin1')
        output = re.sub(r'\(pymacs-(defun|python) [0-9]*',
                        r'(pymacs-\1 0',
                        output)
        assert output == expected, (output, expected)

    if isinstance(bool, type):
        false_string = 'nil'
        true_string = 't'
    else:
        false_string = '0'
        true_string = '1'
    for quotable, input, output in (
            (False, None, 'nil'),
            (False, False, false_string),
            (False, True, true_string),
            (False, 3, '3'),
            (False, 0, '0'),
            (False, -3, '-3'),
            (False, 3., '3.0'),
            (False, 0., '0.0'),
            (False, -3., '-3.0'),
            (False, '', '""'),
            (False, 'a', '"a"'),
            (False, 'byz', '"byz"'),
            (False, 'c\'bz', '"c\'bz"'),
            (False, 'd"z', r'"d\"z"'),
            (False, 'e\\bz', r'"e\\bz"'),
            (False, 'f\bz', '"f\bz"'),
            (False, 'g\fz', '"g\fz"'),
            (False, 'h\nz', '"h\nz"'),
            (False, 'i\rz', '"i\rz"'),
            (False, 'j\r\nz', '"j\r\nz"'),
            (False, 'k\tz', '"k\tz"'),
            (False, 'l\x1bz', '"l\x1bz"'),
            (False, u'p', '"p"'),
            (False, u'qyz', '"qyz"'),
            (False, u'rêvé', '"r\303\252v\303\251"'),
            (False, u's—z!', '"s\342\200\224z!"'),
            (False, (), '[]'),
            (False, (0,), '[0]'),
            (False, (0.0,), '[0.0]'),
            (False, ('a',), '["a"]'),
            (False, (0, 0.0, "a"), '[0 0.0 "a"]'),
            (True, [], 'nil'),
            (True, [0], '(0)'),
            (True, [0.0], '(0.0)'),
            (True, ['a'], '("a")'),
            (True, [0, 0.0, "a"], '(0 0.0 "a")'),
            (False, lisp['nil'], 'nil'),
            (True, lisp['t'], 't'),
            (True, lisp['ab_cd'], 'ab_cd'),
            (True, lisp['ab-cd'], 'ab-cd'),
            (True, lisp['lambda'], 'lambda'),
            (False, lisp.nil, 'nil'),
            (True, lisp.t, 't'),
            (True, lisp.ab_cd, 'ab-cd'),
            # TODO: Lisp and derivatives
            ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, quotable)
        yield validate, ''.join(fragments), output
    for input, output in (
            (ord, '(pymacs-defun 0 nil)'),
            (object(), '(pymacs-python 0)'),
            ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, True)
        yield validate, '\'' + ''.join(fragments), output
예제 #9
0
def notest_2():
    def validate(input, expected):
        import re
        output = re.sub(r'\(pymacs-(defun|python) [0-9]*', r'(pymacs-\1 0',
                        setup.ask_emacs(input, 'pymacs-print-for-eval'))
        assert output == expected, (output, expected)

    for quotable, input, output in (
        (False, None, 'None'),
        (False, False, 'None'),
        (False, True, 'True'),
        (False, 3, '3'),
        (False, 0, '0'),
        (False, -3, '-3'),
        (False, 3., '3.0'),
        (False, 0., '0.0'),
        (False, -3., '-3.0'),
        (False, '', '""'),
        (False, 'a', '"a"'),
        (False, 'byz', '"byz"'),
        (False, 'c\'bz', '"c\'bz"'),
        (False, 'd"z', r'"d\"z"'),
        (False, 'e\\bz', r'"e\\bz"'),
        (False, 'f\bz', '"f\x08z"'),
        (False, 'g\fz', '"g\x0cz"'),
        (False, 'h\nz', r'"h\nz"'),
        (False, 'i\rz', '"i\rz"'),
        (False, 'j\r\nz', '"j\r\nz"'),
        (False, 'k\tz', '"k\tz"'),
        (False, 'l\x1bz', '"l\x1bz"'),
        (False, (), '[]'),
        (False, (0, ), '[0]'),
        (False, (0.0, ), '[0.0]'),
        (False, ('a', ), '["a"]'),
        (False, (0, 0.0, "a"), '[0 0.0 "a"]'),
        (True, [], 'nil'),
        (True, [0], '(0)'),
        (True, [0.0], '(0.0)'),
        (True, ['a'], '("a")'),
        (True, [0, 0.0, "a"], '(0 0.0 "a")'),
        (False, lisp['nil'], 'nil'),
        (True, lisp['t'], 't'),
        (True, lisp['ab_cd'], 'ab_cd'),
        (True, lisp['ab-cd'], 'ab-cd'),
        (True, lisp['lambda'], 'lambda'),
        (False, lisp.nil, 'nil'),
        (True, lisp.t, 't'),
        (True, lisp.ab_cd, 'ab-cd'),
            # TODO: Lisp and derivatives
    ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, quotable)
        yield (validate,
               ('(let ((pymacs-forget-mutability t)\n'
                '   (pymacs-print-for-eval %s)))\n' % ''.join(fragments)),
               output)
    for input, output in (
        (ord, '(pymacs-defun 0 nil)'),
        (object(), '(pymacs-python 0)'),
    ):
        fragments = []
        pymacs.print_lisp(input, fragments.append, True)
        yield validate, '\'' + ''.join(fragments), output