Пример #1
0
 def test_click_command_with_number_arg(self):
     tokens = scan("Click Button (5)")
     self.assertEquals("id= Keyword          subid= click        lexeme='click' ", tokens[0].tostr())
     self.assertEquals("id= Keyword          subid= button       lexeme='button' ", tokens[1].tostr())
     self.assertEquals("id= (                subid=              lexeme='(' ", tokens[2].tostr())
     self.assertEquals("id= Number           subid=              lexeme='5' ", tokens[3].tostr())
     self.assertEquals("id= )                subid=              lexeme=')' ", tokens[4].tostr())
Пример #2
0
 def test_click_command_with_string_arg(self):
     tokens = scan('Click Button ("Save as...")')
     self.assertEquals("id= Keyword          subid= click        lexeme='click' ", tokens[0].tostr())
     self.assertEquals("id= Keyword          subid= button       lexeme='button' ", tokens[1].tostr())
     self.assertEquals("id= (                subid=              lexeme='(' ", tokens[2].tostr())
     self.assertEquals("id= String           subid=              lexeme='\"Save as...\"' ", tokens[3].tostr())
     self.assertEquals("id= )                subid=              lexeme=')' ", tokens[4].tostr())
Пример #3
0
def parse(instruction_line):
    tokens = scan(instruction_line)

    CMD_PARSERS = {scanner.ID_ASSERT: parse_assert,
                   scanner.ID_CLICK: parse_click,
                   scanner.ID_CLOSE: parse_close,
                   scanner.ID_ENTER: parse_enter,
                   scanner.ID_EXIT: parse_exit,
                   scanner.ID_SELECT: parse_select,
                   scanner.ID_ADD: parse_add,
                   }

    if len(tokens) == 0:
        raise InstructionSyntaxException("Empty instruction")

    if tokens[0].id != scanner.KEYWORD:
        raise InstructionSyntaxException(tokens[0].lexeme)

    if (tokens[0].subid in CMD_PARSERS):
        return CMD_PARSERS[tokens[0].subid](instruction_line, tokens)
    else:
        raise InstructionSyntaxException(tokens[0].lexeme)
Пример #4
0
def parse(instruction_line):
    tokens = scan(instruction_line)

    CMD_PARSERS = {scanner.ID_ASSERT: parse_assert,
                   scanner.ID_CLICK: parse_click,
                   scanner.ID_CLOSE: parse_close,
                   scanner.ID_ENTER: parse_enter,
                   scanner.ID_EXIT: parse_exit,
                   scanner.ID_SELECT: parse_select,
                   scanner.ID_ADD: parse_add,
                   scanner.ID_CHANGE: parse_change,
                   }

    if len(tokens) == 0:
        raise InstructionSyntaxException("Empty instruction")

    if tokens[0].id != scanner.KEYWORD:
        raise InstructionSyntaxException(tokens[0].lexeme)

    if (tokens[0].subid in CMD_PARSERS):
        return CMD_PARSERS[tokens[0].subid](instruction_line, tokens)
    else:
        raise InstructionSyntaxException(tokens[0].lexeme)
Пример #5
0
 def test_comment_can_start_with_spaces(self):
     tokens = scan("    # Comment")
     self.assertEquals("id= Keyword          subid= #            lexeme='# Comment' ", tokens[0].tostr())
Пример #6
0
 def test_empty_text_returns_no_tokens(self):
     self.assertEquals([], scan(""))