(self)
| 82 | return ret |
| 83 | |
| 84 | def parse(self) -> List[Case]: |
| 85 | with open(self.filename, "r") as f: |
| 86 | data = filter( |
| 87 | lambda x: x, |
| 88 | map( |
| 89 | lambda x: x.strip(), |
| 90 | f.readlines() |
| 91 | ) |
| 92 | ) |
| 93 | |
| 94 | cases: List[Case] = [] |
| 95 | title_at = 0 |
| 96 | for no, line in enumerate(data): |
| 97 | newCase = isTitle(line) |
| 98 | if len(cases) == 0 or newCase: |
| 99 | cases.append(Case()) |
| 100 | case = cases[-1] |
| 101 | if title := isTitle(line): |
| 102 | case.title = title |
| 103 | title_at = no |
| 104 | continue |
| 105 | if no == title_at + 1 and re.match(r"^[——-]", line): |
| 106 | case.subtitle = line.strip("——-") |
| 107 | continue |
| 108 | |
| 109 | if isSection(line): |
| 110 | case.content.append(f"## {line.strip('【】')}") |
| 111 | else: |
| 112 | case.content += self.__slice_content(line) |
| 113 | return cases |
| 114 | |
| 115 | def write(self, cases: List[Case]): |
| 116 | ret_json = [] |
no test coverage detected