#!/usr/bin/python """ A sample test to check the _decode function of IDLEimprovements mockText class usage example: python decodeTest.py "insert +1chars" """ import re import sys line = sys.argv[1:] line = str(line[0]) ''' regular expressions to handle mockText's _decode indexes findind the index's parts as first, operator(+or- if any) move(for linestart..) increase (valueof operator) increaseby (whether lines or c/chars) to handle line.char, insert, end, +-#c/chars, lineend, linestart, wordstart, wordend ''' matchObj = re.search( r'(insert|end|\d*.\d*)(( *)(\+|-)*( *)((linestart|lineend|wordstart|wordend)|(\d*)((c|chars|lines))))*', line, re.M|re.I) if matchObj: print "first :", matchObj.group(1) #print " :", matchObj.group(2) #print " :", matchObj.group(3) print "operator :", matchObj.group(4) #print " :", matchObj.group(5) #print " :", matchObj.group(6) print "move :", matchObj.group(7) print "increase :", matchObj.group(8) print "increaseby:", matchObj.group(9) else: print "No match!!"