Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>import re from sys import stdout #stdout = open("result.txt", 'w+') def read(in_file): cases = [] caselines_index = [] readlines = [] readlines_num = [] with open(in_file, 'r') as file: readfile = file.read().strip() for line in readfile.split('\n'): readlines_num.append(line.strip()) regex = re.compile("switch\(\$\d\).+?\}", re.DOTALL) readfile = re.sub(regex, ' ', readfile) for line in readfile.split('\n'): readlines.append(line.strip()) for line in readlines: case_search = re.search("case\s\".+?\"\:\s", line) if case_search: caselines_index.append(readlines.index(line)) #print caselines_index caselines_index_iter = iter(caselines_index) try: int_line_index = int(next(caselines_index_iter)) except: print "No cases found" try: int_next_index = int(next(caselines_index_iter)) except: int_next_index = len(readlines) - 1 while True: try: case_text = ' '.join(readlines[int_line_index:int_next_index]).strip() match1 = re.search("nvp_add", case_text) match2 = re.search("details", case_text) if match1 or match2: case = [readlines[int_line_index].strip(), readlines_num.index(readlines[int_line_index]) + 1, case_text] cases.append(case) int_line_index = int_next_index int_next_index = int(next(caselines_index_iter)) except StopIteration: case_text = ' '.join(readlines[int_line_index:len(readlines) - 1]).strip() case = [readlines[int_line_index].strip(), readlines_num.index(readlines[int_line_index]), case_text] cases.append(case) break return cases def work(cases): MATCH = 1 for case_list in cases: details = [] nvp_add = [] caseline = case_list[0].strip() nvp = re.findall("details\(.+?\)", case_list[2].strip()) for item in nvp: result_list = re.findall("(\$.+?)[\,\)]", item) for result in result_list: if "$*" not in result: details.append(result) nvp = re.findall("nvp_add\(.+?\)", case_list[2].strip()) for item in nvp: result_list = re.findall("(\$.+?)[\,\)]", item) for result in result_list: if "$*" not in result: nvp_add.append(result) missing_from_details, missing_from_nvp_add = [], [] missing_from_details = [o for o in nvp_add if o not in set(details)] missing_from_nvp_add = [o for o in details if o not in set(nvp_add)] if missing_from_nvp_add or missing_from_details: MATCH = 0 print caseline + " LINE - " + str(case_list[1] + 1) for mismatch in missing_from_details: print "Missing from details:" print mismatch for mismatch in missing_from_nvp_add: print "Missing from nvp_add:" print mismatch print "\n" if MATCH == 1: print "MATCH" else: print "MISMATCHES" def main(): in_file = "target1.txt" cases = read(in_file) work(cases) if __name__=="__main__": main() </code></pre> <p>This will filter out all the switches that are nested. This will only work in your case with your input file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload