| 8 | |
| 9 | |
| 10 | class Test_GoParser(unittest.TestCase): |
| 11 | def setUp(self) -> None: |
| 12 | with open('tests/test_parser/test_sample/go_test_sample.go', 'r') as file: |
| 13 | self.code_sample = file.read() |
| 14 | |
| 15 | tree = parse_code(self.code_sample, 'go') |
| 16 | self.root_node = tree.root_node |
| 17 | return super().setUp() |
| 18 | |
| 19 | def test_get_function_list(self): |
| 20 | root = self.root_node |
| 21 | |
| 22 | function_list = GoParser.get_function_list(root) |
| 23 | |
| 24 | self.assertEqual(len(function_list), 1) |
| 25 | |
| 26 | def test_get_function_metadata(self): |
| 27 | root = self.root_node |
| 28 | |
| 29 | function = GoParser.get_function_list(root)[0] |
| 30 | metadata = GoParser.get_function_metadata(function) |
| 31 | |
| 32 | for key in ['identifier', 'parameters', 'return_type']: |
| 33 | self.assertTrue(key in metadata.keys()) |
| 34 | self.assertEqual(metadata['parameters'], {'e': 'TypeError'}) |
| 35 | self.assertEqual(metadata['identifier'], 'Error') |
| 36 | self.assertEqual(metadata['return_type'], 'string') |
| 37 | |
| 38 | def test_get_docstring(self): |
| 39 | code_sample = """ |
| 40 | type TypeError struct { |
| 41 | Type1, Type2 reflect.Type |
| 42 | Extra string |
| 43 | } |
| 44 | // Something must not include as docstring |
| 45 | |
| 46 | // The path package should only be used for paths separated by forward |
| 47 | // slashes, such as the paths in URLs. This package does not deal with |
| 48 | // Windows paths with drive letters or backslashes; to manipulate |
| 49 | // operating system paths, use the [path/filepath] package. |
| 50 | func (e TypeError) Error() string { |
| 51 | msg := e.Type1.String() |
| 52 | if e.Type2 != nil { |
| 53 | msg += " and " + e.Type2.String() |
| 54 | } |
| 55 | msg += " " + e.Extra |
| 56 | return msg |
| 57 | } |
| 58 | """ |
| 59 | tree = parse_code(code_sample, 'go') |
| 60 | root = tree.root_node |
| 61 | |
| 62 | fn = GoParser.get_function_list(root)[0] |
| 63 | |
| 64 | docs = GoParser.get_docstring(fn) |
| 65 | self.assertEqual(docs, '// The path package should only be used for paths separated by forward\n// slashes, such as the paths in URLs. This package does not deal with\n// Windows paths with drive letters or backslashes; to manipulate\n// operating system paths, use the [path/filepath] package.') |
| 66 | |
| 67 |
nothing calls this directly
no outgoing calls
no test coverage detected