2015-11-16 14:04:32 -08:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-02-03 02:02:57 -06:00
|
|
|
"""Tests the xonsh lexer."""
|
|
|
|
from __future__ import unicode_literals, print_function
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import ast
|
|
|
|
|
2015-08-02 17:34:13 -05:00
|
|
|
from nose.tools import assert_raises
|
|
|
|
|
2015-02-03 02:02:57 -06:00
|
|
|
from xonsh.execer import Execer
|
2015-05-12 03:14:36 -04:00
|
|
|
from xonsh.tools import ON_WINDOWS
|
2015-02-03 02:02:57 -06:00
|
|
|
|
2016-06-05 16:25:43 -04:00
|
|
|
from tools import (mock_xonsh_env, execer_setup, check_exec, check_eval,
|
|
|
|
check_parse, skip_if)
|
2015-03-01 19:13:09 -06:00
|
|
|
|
2015-02-03 02:02:57 -06:00
|
|
|
def setup():
|
2016-06-05 16:25:43 -04:00
|
|
|
execer_setup()
|
2015-03-01 19:13:09 -06:00
|
|
|
|
2016-06-05 16:25:43 -04:00
|
|
|
@skip_if(not ON_WINDOWS)
|
|
|
|
def test_win_ipconfig():
|
|
|
|
yield (check_eval,
|
|
|
|
os.environ['SYSTEMROOT'] + '\\System32\\ipconfig.exe /all')
|
2015-02-03 02:02:57 -06:00
|
|
|
|
2016-06-05 16:25:43 -04:00
|
|
|
@skip_if(not ON_WINDOWS)
|
|
|
|
def test_ipconfig():
|
|
|
|
yield check_eval, 'ipconfig /all'
|
2015-02-11 02:01:35 -06:00
|
|
|
|
2016-06-05 16:25:43 -04:00
|
|
|
@skip_if(ON_WINDOWS)
|
|
|
|
def test_bin_ls():
|
|
|
|
yield check_eval, '/bin/ls -l'
|
2015-02-11 02:01:35 -06:00
|
|
|
|
2016-04-09 00:25:53 -04:00
|
|
|
def test_ls_dashl():
|
|
|
|
yield check_parse, 'ls -l'
|
2015-05-09 01:58:51 -04:00
|
|
|
|
2016-04-09 00:25:53 -04:00
|
|
|
def test_which_ls():
|
|
|
|
yield check_parse, 'which ls'
|
2015-05-09 01:58:51 -04:00
|
|
|
|
2016-04-09 00:25:53 -04:00
|
|
|
def test_echo_hello():
|
|
|
|
yield check_parse, 'echo hello'
|
2015-07-29 23:58:25 +02:00
|
|
|
|
2015-03-10 21:38:11 -05:00
|
|
|
def test_simple_func():
|
|
|
|
code = ('def prompt():\n'
|
|
|
|
" return '{user}'.format(user='me')\n")
|
|
|
|
yield check_parse, code
|
|
|
|
|
2016-06-11 21:02:28 -04:00
|
|
|
def test_lookup_alias():
|
|
|
|
code = (
|
|
|
|
'def foo(a, s=None):\n'
|
|
|
|
' return "bar"\n'
|
|
|
|
'@(foo)\n')
|
|
|
|
yield check_parse, code
|
|
|
|
|
|
|
|
def test_lookup_anon_alias():
|
|
|
|
code = ('echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n')
|
|
|
|
yield check_parse, code
|
|
|
|
|
2015-03-10 21:38:11 -05:00
|
|
|
def test_simple_func_broken():
|
|
|
|
code = ('def prompt():\n'
|
|
|
|
" return '{user}'.format(\n"
|
|
|
|
" user='me')\n")
|
|
|
|
yield check_parse, code
|
|
|
|
|
2015-08-02 17:34:13 -05:00
|
|
|
def test_bad_indent():
|
|
|
|
code = ('if True:\n'
|
|
|
|
'x = 1\n')
|
|
|
|
assert_raises(SyntaxError, check_parse, code)
|
2015-03-10 21:38:11 -05:00
|
|
|
|
2016-05-19 20:12:07 -04:00
|
|
|
def test_good_rhs_subproc():
|
|
|
|
# nonsense but parsebale
|
|
|
|
code = 'str().split() | ![grep exit]\n'
|
|
|
|
check_parse(code)
|
|
|
|
|
|
|
|
def test_bad_rhs_subproc():
|
|
|
|
# nonsense but unparsebale
|
|
|
|
code = 'str().split() | grep exit\n'
|
|
|
|
assert_raises(SyntaxError, check_parse, code)
|
|
|
|
|
2015-08-05 12:05:13 +03:00
|
|
|
def test_indent_with_empty_line():
|
|
|
|
code = ('if True:\n'
|
|
|
|
'\n'
|
|
|
|
' some_command for_sub_process_mode\n')
|
|
|
|
yield check_parse, code
|
|
|
|
|
2016-02-21 14:37:03 -05:00
|
|
|
def test_command_in_func():
|
|
|
|
code = ('def f():\n'
|
|
|
|
' echo hello\n')
|
|
|
|
yield check_parse, code
|
|
|
|
|
|
|
|
def test_command_in_func_with_comment():
|
|
|
|
code = ('def f():\n'
|
|
|
|
' echo hello # comment\n')
|
|
|
|
yield check_parse, code
|
|
|
|
|
2016-05-19 18:52:50 -04:00
|
|
|
def test_pyeval_redirect():
|
|
|
|
code = 'echo @("foo") > bar\n'
|
|
|
|
yield check_parse, code
|
|
|
|
|
2016-05-24 23:55:07 -04:00
|
|
|
def test_echo_comma():
|
|
|
|
code = 'echo ,\n'
|
|
|
|
yield check_parse, code
|
|
|
|
|
|
|
|
def test_echo_comma_val():
|
|
|
|
code = 'echo ,1\n'
|
|
|
|
yield check_parse, code
|
|
|
|
|
|
|
|
def test_echo_comma_2val():
|
|
|
|
code = 'echo 1,2\n'
|
|
|
|
yield check_parse, code
|
|
|
|
|
2015-03-10 21:38:11 -05:00
|
|
|
|
2015-02-03 02:02:57 -06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
nose.runmodule()
|