| 8 | |
| 9 | |
| 10 | class Test_CsharpParser(unittest.TestCase): |
| 11 | def setUp(self) -> None: |
| 12 | with open('tests/test_parser/test_sample/c_sharp_test_sample.cs', 'r') as file: |
| 13 | self.code_sample = file.read() |
| 14 | |
| 15 | tree = parse_code(self.code_sample, 'c#') |
| 16 | self.root_node = tree.root_node |
| 17 | |
| 18 | return super().setUp() |
| 19 | |
| 20 | def test_get_function_list(self): |
| 21 | root = self.root_node |
| 22 | |
| 23 | function_list = CsharpParser.get_function_list(root) |
| 24 | |
| 25 | self.assertEqual(len(function_list), 3) # exclude constructor |
| 26 | |
| 27 | def test_get_class_list(self): |
| 28 | root = self.root_node |
| 29 | |
| 30 | class_list = CsharpParser.get_class_list(root) |
| 31 | |
| 32 | self.assertEqual(len(class_list), 1) |
| 33 | |
| 34 | def test_get_docstring(self): |
| 35 | code_sample = """ |
| 36 | class Vehicle |
| 37 | { |
| 38 | public string brand = "Ford"; // Vehicle field |
| 39 | |
| 40 | // <summary> |
| 41 | // Docstring of a method |
| 42 | // </summary> |
| 43 | // <param name="animal_honk">Argument.</param> |
| 44 | // <returns> |
| 45 | // None. |
| 46 | public void honk(string animal_honk) |
| 47 | { |
| 48 | Console.WriteLine(animal_honk); |
| 49 | Console.WriteLine("Tuut, tuut!"); |
| 50 | } |
| 51 | |
| 52 | /* Another method docstring |
| 53 | in multiple line */ |
| 54 | public void _honk() |
| 55 | { |
| 56 | Console.WriteLine("Tuut, tuut!"); |
| 57 | } |
| 58 | } |
| 59 | """ |
| 60 | tree = parse_code(code_sample, 'c#') |
| 61 | root = tree.root_node |
| 62 | |
| 63 | fn1, fn2 = list(CsharpParser.get_function_list(root)) |
| 64 | |
| 65 | docs1 = CsharpParser.get_docstring(fn1) |
| 66 | docs2 = CsharpParser.get_docstring(fn2) |
| 67 |
nothing calls this directly
no outgoing calls
no test coverage detected