Exemplo n.º 1
0
def test_single_unnamed_argument():
    lex = ArgumentsLexer()

    lex.process("value1")

    assert lex.tokens == [
        Text("value1"),
    ]
Exemplo n.º 2
0
def test_single_named_argument():
    lex = ArgumentsLexer()

    lex.process("argument1=value1")

    assert lex.tokens == [
        Text("argument1"),
        Literal("="),
        Text("value1"),
    ]
Exemplo n.º 3
0
def test_multiple_unnamed_arguments():
    lex = ArgumentsLexer()

    lex.process("value1, value2")

    assert lex.tokens == [
        Text("value1"),
        Literal(","),
        WS(" "),
        Text("value2"),
    ]
Exemplo n.º 4
0
def test_spaces():
    lex = ArgumentsLexer()

    lex.process("argument1=value1 value2")

    assert lex.tokens == [
        Text("argument1"),
        Literal("="),
        Text("value1"),
        WS(" "),
        Text("value2"),
    ]
Exemplo n.º 5
0
def test_escaped_quotes():
    lex = ArgumentsLexer()

    lex.process(r"Argument \"with\" quotes")

    assert lex.tokens == [
        Text("Argument"),
        WS(" "),
        Literal("\\"),
        Literal('"'),
        Text("with"),
        Literal("\\"),
        Literal('"'),
        WS(" "),
        Text("quotes"),
    ]
Exemplo n.º 6
0
 def __init__(self, raw=False):
     super().__init__()
     self.lexer = ArgumentsLexer()
     self.raw = raw
     self._named_arguments = False
     self.kwargs = {}
     self.args = []
Exemplo n.º 7
0
    def __init__(self):
        super().__init__()
        self.lexer = ArgumentsLexer()

        # This flag is turned on as soon as
        # a named argument is parsed
        self._named_arguments = False

        self.kwargs = {}
        self.args = []
Exemplo n.º 8
0
def test_mixed_arguments():
    lex = ArgumentsLexer()

    lex.process("value1, value2,argument1=value1, argument2=value2")

    assert lex.tokens == [
        Text("value1"),
        Literal(","),
        WS(" "),
        Text("value2"),
        Literal(","),
        Text("argument1"),
        Literal("="),
        Text("value1"),
        Literal(","),
        WS(" "),
        Text("argument2"),
        Literal("="),
        Text("value2"),
    ]
Exemplo n.º 9
0
def test_quotes():
    lex = ArgumentsLexer()

    lex.process('argument1="value1,value2"')

    assert lex.tokens == [
        Text("argument1"),
        Literal("="),
        Literal('"'),
        Text("value1"),
        Literal(","),
        Text("value2"),
        Literal('"'),
    ]

    assert [t.position for t in lex.tokens] == [
        (0, 0),
        (0, 9),
        (0, 10),
        (0, 11),
        (0, 17),
        (0, 18),
        (0, 24),
    ]