Ejemplo n.º 1
0
def item_parser_eol_bug_test():
    csrc = CSource(b"hello world")
    ip = ItemParser(csrc)
    maxbuf = 256
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "hello")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "world")
    # with eol_bug enabled we get last char again...
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "d")
    # now again with fixed parser
    csrc = CSource(b"hello world")
    ip = ItemParser(csrc, eol_unget_bug=False)
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "hello")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "world")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_NOTHING, None)
Ejemplo n.º 2
0
def item_parser1_test():
    csrc = CSource(b"hello world\n")
    ip = ItemParser(csrc)
    maxbuf = 256
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "hello")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_UNQUOTED, "world")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_NOTHING, None)
Ejemplo n.º 3
0
def check_item_eol(in_str, itype, item, eol):
    csrc = CSource((in_str + "\n").encode("latin-1"))
    ip = ItemParser(csrc)
    maxbuf = 256
    assert ip.read_item(maxbuf) == (itype, item)
    assert ip.read_eol() == eol
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_NOTHING, None)
Ejemplo n.º 4
0
def item_parser2_test():
    csrc = CSource(b'"hello space" "world*n"\n')
    ip = ItemParser(csrc)
    maxbuf = 256
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_QUOTED, "hello space")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_QUOTED, "world\n")
    assert ip.read_item(maxbuf) == (ItemParser.ITEM_NOTHING, None)
Ejemplo n.º 5
0
def check_item_eol(in_str, itype, item, eol):
  csrc = CSource(in_str + '\n')
  ip = ItemParser(csrc)
  maxbuf = 256
  assert ip.read_item(maxbuf) == (itype, item)
  assert ip.read_eol() == eol
  assert ip.read_item(maxbuf) == (ItemParser.ITEM_NOTHING, None)
Ejemplo n.º 6
0
def check_parse_args(template, in_str, exp_res_list=None, error=NO_ERROR):
  tal = TemplateArgList.parse_string(template)
  assert tal is not None
  p = ArgsParser(tal)
  csrc = CSource(in_str + "\n")
  result = p.parse(csrc)
  print(dos_error_strings[result])
  assert result == error
  if error == NO_ERROR:
    assert p.get_result_list().get_results() == exp_res_list