| 8 | |
| 9 | |
| 10 | class TestCodeExtractors(unittest.TestCase): |
| 11 | |
| 12 | def test_extract_first_source_code(self): |
| 13 | target_code = "some code here!" |
| 14 | responses = [ |
| 15 | f""" |
| 16 | ``` |
| 17 | {target_code} |
| 18 | ``` |
| 19 | """, |
| 20 | f""" |
| 21 | ``` |
| 22 | {target_code} |
| 23 | ``` |
| 24 | Some ending comment |
| 25 | """, |
| 26 | f""" |
| 27 | Some beginning comment |
| 28 | ``` |
| 29 | {target_code} |
| 30 | ``` |
| 31 | Some ending comment |
| 32 | """, |
| 33 | f""" |
| 34 | Some beginning comment |
| 35 | ```cpp |
| 36 | {target_code} |
| 37 | ``` |
| 38 | Some ending comment |
| 39 | """, |
| 40 | f""" |
| 41 | Some beginning comment |
| 42 | ```h |
| 43 | {target_code} |
| 44 | ``` |
| 45 | ```cpp |
| 46 | code we don't care about |
| 47 | ``` |
| 48 | """, |
| 49 | f""" |
| 50 | {target_code} |
| 51 | """, |
| 52 | ] |
| 53 | |
| 54 | for response in responses: |
| 55 | extracted_code = extract_first_source_code(response) |
| 56 | self.assertEqual(target_code, extracted_code) |
| 57 | |
| 58 | def test_extract_header_implementation(self): |
| 59 | target_header = "header here!" |
| 60 | target_implementation = "implementation here!" |
| 61 | responses = [ |
| 62 | f""" |
| 63 | ```cpp |
| 64 | {target_header} |
| 65 | ``` |
| 66 | ```cpp |
| 67 | {target_implementation} |
nothing calls this directly
no outgoing calls
no test coverage detected