예제 #1
0
def test_variable():
    result = parse('a $b\na $$c\na "$$$d"')
    ground_truth = [
        PlainCommand('a', [VariableArgument('b')]),
        PlainCommand('a', [LiteralArgument('$c')]),
        PlainCommand('a', [LiteralArgument('$$d')]),
    ]
    must_equal(result, ground_truth)
예제 #2
0
def test_simple():
    result = parse('aaa bbb  !@#$%^&*()')
    ground_truth = [
        PlainCommand(
            'aaa',
            [LiteralArgument('bbb'),
             LiteralArgument('!@#$%^&*()')],
        ),
    ]
    must_equal(result, ground_truth)
예제 #3
0
def test_empty_lines():
    result = parse('\n\na  \n    \n \n\n')
    ground_truth = [
        PlainCommand('nop', []),
        PlainCommand('nop', []),
        PlainCommand('a', []),
        PlainCommand('nop', []),
        PlainCommand('nop', []),
        PlainCommand('nop', []),
        PlainCommand('nop', []),
    ]
    must_equal(result, ground_truth)
예제 #4
0
def test_multiline():
    result = parse('0\n1 2\n3 4 5\n 6 7\n        8')
    ground_truth = [
        PlainCommand('0', []),
        PlainCommand('1', [LiteralArgument('2')]),
        PlainCommand(
            '3',
            [LiteralArgument('4'), LiteralArgument('5')]),
        PlainCommand('6', [LiteralArgument('7')]),
        PlainCommand('8', []),
    ]
    must_equal(result, ground_truth)
예제 #5
0
def test_if():
    result = parse('''
        if a b c
            foo bar
        else
            x y z
        endif
    '''.strip())
    ground_truth = [
        If(PlainCommand(
            'a',
            [LiteralArgument('b'), LiteralArgument('c')])),
        PlainCommand('foo', [LiteralArgument('bar')]),
        Else(),
        PlainCommand(
            'x',
            [LiteralArgument('y'), LiteralArgument('z')]),
        Endif(),
    ]
    must_equal(result, ground_truth)
예제 #6
0
def test_invalid_endif():
    with pytest.raises(ParseError) as excinfo:
        parse('endif x')
    cause = excinfo.value.__cause__
    assert type(cause) is parser.InvalidBuiltinCommandUsageError
    assert 'endif' in str(cause)
예제 #7
0
def test_empty_command():
    with pytest.raises(ParseError) as excinfo:
        parse('x = ')
    assert type(excinfo.value.__cause__) is parser.EmptyCommandError
예제 #8
0
def test_assignment():
    result = parse('x = a b')
    ground_truth = [Assignment('x', PlainCommand('a', [LiteralArgument('b')]))]
    must_equal(result, ground_truth)