示例#1
0
def main():
    sg = os.path.dirname(__file__) + '/shitgrep'

    # get text from command line?
    if len(sys.argv) < 2:
        cl_text = False
    elif len(sys.argv) == 2:
        text = sys.argv[1]
        cl_text = True
    else:
        raise Exception('too many arguments')

    # print head stuff
    print '''#include <scope/test.h>

#include "stest.h"
'''

    setnum = 0

    for line in sys.stdin:
        # read the test set
        parts = line.rstrip('\n').split('\t')

        if cl_text:
            pats = parts
        else:
            pats = parts[0:-1]
            text = parts[-1]

        # get matches from shitgrep
        matches = lgtestlib.run_shitgrep(sg, pats, text)

        if len(pats) == 1:
            stest = 'R"({})"'.format(pats[0])
        else:
            stest = '{{ R"({})" }}'.format(')", R"('.join(pats))

        print '''SCOPE_FIXTURE_CTOR(autoPatternTest{setnum}, STest, STest({stest})) {{'''.format(
            setnum=setnum, stest=stest)

        if matches is None:
            # every pattern in this set has zero-length matches
            print '  SCOPE_ASSERT(fixture.parsesButNotValid());'
        else:
            # this pattern set has no zero-length matches
            print '''  const char text[] = "{text}";
  fixture.search(text, text + {textlen}, 0);
  SCOPE_ASSERT_EQUAL({matchcount}u, fixture.Hits.size());'''.format(
                text=text, textlen=len(text), matchcount=len(matches))

            for i, m in enumerate(matches):
                print '  SCOPE_ASSERT_EQUAL(SearchHit({}, {}, {}), fixture.Hits[{}]);'.format(
                    m[0], m[1], m[2], i)

        print '}\n'

        setnum += 1

    return 0
示例#2
0
def main():
  sg = os.path.dirname(__file__) + '/shitgrep'

  # get text from command line?
  if len(sys.argv) < 2:
    cl_text = False
  elif len(sys.argv) == 2:
    text = sys.argv[1]
    cl_text = True
  else:
    raise Exception('too many arguments') 

  # print head stuff
  print '''#include <scope/test.h>

#include "stest.h"
'''

  setnum = 0

  for line in sys.stdin:
    # read the test set
    parts = line.rstrip('\n').split('\t')
   
    if cl_text:
      pats = parts
    else: 
      pats = parts[0:-1]
      text = parts[-1]

    apats = ['^(' + p + ')' for p in pats]

    # get matches from shitgrep
    matches = lgtestlib.run_shitgrep(sg, apats, text)

    if len(pats) == 1:
      stest = 'R"({})"'.format(pats[0])
    else:
      stest = '{{ R"({})" }}'.format(')", R"('.join(pats))

    print '''SCOPE_FIXTURE_CTOR(autoPatternStartsWithTest{setnum}, STest, STest({stest})) {{'''.format(setnum=setnum, stest=stest)

    if matches is None:
      # every pattern in this set has zero-length matches
      print '  SCOPE_ASSERT(fixture.parsesButNotValid());'
    else:
      # this pattern set has no zero-length matches
      print '''  const char text[] = "{text}";
  fixture.startsWith(text, text + {textlen}, 0);
  SCOPE_ASSERT_EQUAL({matchcount}u, fixture.Hits.size());'''.format(text=text, textlen=len(text), matchcount=len(matches))

      for i, m in enumerate(matches):
        print '  SCOPE_ASSERT_EQUAL(SearchHit({}, {}, {}), fixture.Hits[{}]);'.format(m[0], m[1], m[2], i)

    print '}\n'

    setnum += 1

  return 0
示例#3
0
def mismatch(sg, lg, pats, text):
  # get matches from shitgrep
  sgmatches = lgtestlib.run_shitgrep(sg, pats, text)

  # get matches from lightgrep
  lgmatches = lgtestlib.run_lightgrep(lg, pats, text)
 
  return lgmatches != sgmatches
示例#4
0
def main():
  sg = os.path.dirname(__file__) + '/shitgrep'

  # compile the output structs
  bstruct = struct.Struct('B')
  lstruct = struct.Struct('=L')
  mstruct = struct.Struct('=QQQ')

  setnum = 0

  for line in sys.stdin:
    # read the patterns
    parts = line.rstrip('\n').split('\t')

    # get the text from the command line if specified
    if len(sys.argv) == 2:
      text = sys.argv[1]
    else:
      text = parts[-1]
      parts = parts[0:-1]

    # slice up the parts
    pats = parts[0::4]
    fixeds = parts[1::4]
    cases = parts[2::4]
    encodings = parts[3::4] 

    # get matches from shitgrep
    matches = lgtestlib.run_shitgrep(sg, pats, text)

    if matches is None:
      # skip pattern sets where every pattern has zero-length matches
      continue

    # write out patterns and their matches
    sys.stdout.write(lstruct.pack(len(pats)))
    for (pat,fix,case,enc) in zip(pats,fixeds,cases,encodings):
      sys.stdout.write(lstruct.pack(len(pat)))
      sys.stdout.write(pat)
      sys.stdout.write(bstruct.pack(int(fix)))
      sys.stdout.write(bstruct.pack(int(case)))
      sys.stdout.write(lstruct.pack(len(enc)))
      sys.stdout.write(enc)
    sys.stdout.write(lstruct.pack(len(text)))
    sys.stdout.write(text)
    sys.stdout.write(lstruct.pack(len(matches)))

    for m in matches:
      sys.stdout.write(mstruct.pack(m[0], m[1], m[2]))

    # show progress
    setnum += 1
    if not setnum % 100:
      print >>sys.stderr, setnum

  print >>sys.stderr, setnum
  return 0
示例#5
0
def main():
    sg = os.path.dirname(__file__) + '/shitgrep'

    # compile the output structs
    bstruct = struct.Struct('B')
    lstruct = struct.Struct('=L')
    mstruct = struct.Struct('=QQQ')

    setnum = 0

    for line in sys.stdin:
        # read the patterns
        pats = line.rstrip('\n').split('\t')

        # get the text from the command line if specified
        if len(sys.argv) == 2:
            text = sys.argv[1]
        else:
            text = pats[-1]
            pats = pats[0:-1]

        # get matches from shitgrep
        matches = lgtestlib.run_shitgrep(sg, pats, text)

        if matches is None:
            # skip pattern sets where every pattern is faulty
            continue

        # write out patterns and their matches
        sys.stdout.write(lstruct.pack(len(pats)))
        for pat in pats:
            sys.stdout.write(lstruct.pack(len(pat)))
            sys.stdout.write(pat)
            sys.stdout.write(bstruct.pack(0))
            sys.stdout.write(bstruct.pack(0))
            sys.stdout.write(lstruct.pack(len('ASCII')))
            sys.stdout.write('ASCII')
        sys.stdout.write(lstruct.pack(len(text)))
        sys.stdout.write(text)
        sys.stdout.write(lstruct.pack(len(matches)))

        for m in matches:
            sys.stdout.write(mstruct.pack(m[0], m[1], m[2]))

        # show progress
        setnum += 1
        if not setnum % 100:
            print >> sys.stderr, setnum

    print >> sys.stderr, setnum
    return 0
示例#6
0
def main():
  sg = os.path.dirname(__file__) + '/shitgrep'

  # compile the output structs
  bstruct = struct.Struct('B')
  lstruct = struct.Struct('=L')
  mstruct = struct.Struct('=QQQ')

  setnum = 0

  for line in sys.stdin:
    # read the patterns
    pats = line.rstrip('\n').split('\t')

    # get the text from the command line if specified
    if len(sys.argv) == 2:
      text = sys.argv[1]
    else:
      text = pats[-1]
      pats = pats[0:-1]

    # get matches from shitgrep
    matches = lgtestlib.run_shitgrep(sg, pats, text)

    if matches is None:
      # skip pattern sets where every pattern is faulty
      continue

    # write out patterns and their matches
    sys.stdout.write(lstruct.pack(len(pats)))
    for pat in pats:
      sys.stdout.write(lstruct.pack(len(pat)))
      sys.stdout.write(pat)
      sys.stdout.write(bstruct.pack(0))
      sys.stdout.write(bstruct.pack(0))
      sys.stdout.write(lstruct.pack(len('ASCII')))
      sys.stdout.write('ASCII')
    sys.stdout.write(lstruct.pack(len(text)))
    sys.stdout.write(text)
    sys.stdout.write(lstruct.pack(len(matches)))

    for m in matches:
      sys.stdout.write(mstruct.pack(m[0], m[1], m[2]))

    # show progress
    setnum += 1
    if not setnum % 100:
      print >>sys.stderr, setnum

  print >>sys.stderr, setnum
  return 0
示例#7
0
def main():
  sg = os.path.dirname(__file__) + '/shitgrep'

  # get text from command line?
  if len(sys.argv) < 2:
    cl_text = False
  elif len(sys.argv) == 2:
    text = sys.argv[1]
    cl_text = True
  else:
    raise Exception('too many arguments') 

  # print head stuff
  print '''#include <scope/test.h>

#include <algorithm>

#include "stest.h"
'''

  setnum = 0

  for line in sys.stdin:
    # read the test set
    parts = line.rstrip('\n').split('\t')
   
    if cl_text:
      pats = parts
    else: 
      pats = parts[0:-1]
      text = parts[-1]

    # get matches from shitgrep
    matches = lgtestlib.run_shitgrep(sg, pats, text)

    if matches is None:
      # every pattern in this set has zero-length matches
      if len(pats) == 1:
        # test single patterns for zero-length matches
        print '''SCOPE_TEST(autoPatternTest{setnum}) {{
  NFABuilder nfab;
  ParseTree tree;
  SCOPE_ASSERT(parse({R"({pat})", false, false}, tree));
  SCOPE_ASSERT(!nfab.build(tree));
}}
'''.format(setnum=setnum, pat=pats[0])

    else:
      # this pattern set has no zero-length matches
      if len(pats) == 1:
        stest = 'R"({})"'.format(pats[0])
      else:
        stest = '{{ R"({})" }}'.format(')", R"('.join(pats))

      print '''SCOPE_FIXTURE_CTOR(autoPatternTest{setnum}, STest, STest({stest})) {{
  const byte* text = (const byte*) R"({text})";
  fixture.search(text, text + {textlen}, 0);
  std::vector<SearchHit>& actual(fixture.Hits);
  SCOPE_ASSERT_EQUAL({matchcount}u, actual.size());

  std::vector<SearchHit> expected{'''

      for i, m in enumerate(matches):
        print '    {{{}, {}, {}}},'.format(m[0], m[1], m[2], i)

      print '''  };  

  std::sort(actual.begin(), actual.end());
  std::sort(expected.begin(), expected.begin());

  std::pair<std::vector<SearchHit>::iterator,
            std::vector<SearchHit>::iterator> mis(
    std::mismatch(expected.begin(), expected.end(), actual.begin())
  );

  if (mis.first != expected.end()) {
    SCOPE_ASSERT_EQUAL(*mis.first, *mis.second);
  }
}'''

    setnum += 1

  return 0
示例#8
0
def main():
  sg = os.path.dirname(__file__) + '/shitgrep'

  # get text from command line?
  if len(sys.argv) < 2:
    cl_text = False
  elif len(sys.argv) == 2:
    text = sys.argv[1]
    cl_text = True
  else:
    raise Exception('too many arguments') 

  # print head stuff
  print '''#include <scope/test.h>

#include <algorithm>

#include "stest.h"
'''

  setnum = 0

  for line in sys.stdin:
    # read the test set
    parts = line.rstrip('\n').split('\t')
   
    if cl_text:
      pats = parts
    else: 
      pats = parts[0:-1]
      text = parts[-1]

    # get matches from shitgrep
    matches = lgtestlib.run_shitgrep(sg, pats, text)

    if matches is None:
      # every pattern in this set has zero-length matches
      if len(pats) == 1:
        # test single patterns for zero-length matches
        print '''SCOPE_TEST(autoPatternTest{setnum}) {{
  NFABuilder nfab;
  ParseTree tree;
  SCOPE_ASSERT(parse({R"({pat})", false, false}, tree));
  SCOPE_ASSERT(!nfab.build(tree));
}}
'''.format(setnum=setnum, pat=pats[0])

    else:
      # this pattern set has no zero-length matches
      if len(pats) == 1:
        stest = 'R"({})"'.format(pats[0])
      else:
        stest = '{{ R"({})" }}'.format(')", R"('.join(pats))

      print '''SCOPE_FIXTURE_CTOR(autoPatternTest{setnum}, STest, STest({stest})) {{
  const byte* text = (const byte*) "{text}";
  fixture.search(text, text + {textlen}, 0);
  std::vector<SearchHit>& actual(fixture.Hits);
  SCOPE_ASSERT_EQUAL({matchcount}u, actual.size());

  std::vector<SearchHit> expected{'''

      for i, m in enumerate(matches):
        print '    {{{}, {}, {}}},'.format(m[0], m[1], m[2], i)

      print '''  };  

  std::sort(actual.begin(), actual.end());
  std::sort(expected.begin(), expected.begin());

  std::pair<std::vector<SearchHit>::iterator,
            std::vector<SearchHit>::iterator> mis(
    std::mismatch(expected.begin(), expected.end(), actual.begin())
  );

  if (mis.first != expected.end()) {
    SCOPE_ASSERT_EQUAL(*mis.first, *mis.second);
  }
}'''

    setnum += 1

  return 0