| 8 | |
| 9 | |
| 10 | class Test_RustParser(unittest.TestCase): |
| 11 | def setUp(self) -> None: |
| 12 | with open('tests/test_parser/test_sample/rust_test_sample.rs', 'r') as file: |
| 13 | self.code_sample = file.read() |
| 14 | |
| 15 | tree = parse_code(self.code_sample, 'rust') |
| 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 = RustParser.get_function_list(root) |
| 24 | |
| 25 | self.assertEqual(len(function_list), 4) |
| 26 | |
| 27 | def test_get_class_list(self): |
| 28 | root = self.root_node |
| 29 | |
| 30 | class_list = RustParser.get_class_list(root) |
| 31 | |
| 32 | self.assertEqual(len(class_list), 2) |
| 33 | |
| 34 | def test_get_docstring(self): |
| 35 | code_sample = """ |
| 36 | // Comment something |
| 37 | mod my_mod { |
| 38 | /// Creates a new rendering surface. |
| 39 | /// |
| 40 | /// # Arguments |
| 41 | /// |
| 42 | /// Initialization of surfaces happens through the types provided by |
| 43 | /// [`drm-rs`](drm). |
| 44 | /// |
| 45 | /// - [`crtcs`](drm::control::crtc) represent scanout engines of the device pointing to one framebuffer. \\ |
| 46 | /// Their responsibility is to read the data of the framebuffer and export it into an "Encoder". \\ |
| 47 | /// The number of crtc's represent the number of independent output devices the hardware may handle. |
| 48 | fn private_function() { |
| 49 | println!("called `my_mod::private_function()`"); |
| 50 | } |
| 51 | |
| 52 | /** - Outer block doc (exactly) 2 asterisks */ |
| 53 | pub fn function() { |
| 54 | println!("called `my_mod::function()`"); |
| 55 | } |
| 56 | |
| 57 | // Items can access other items in the same module, |
| 58 | // even when private. |
| 59 | pub fn indirect_access() { |
| 60 | print!("called `my_mod::indirect_access()`, that\n> "); |
| 61 | private_function(); |
| 62 | } |
| 63 | } |
| 64 | """ |
| 65 | |
| 66 | tree = parse_code(code_sample, 'rust') |
| 67 | root = tree.root_node |
nothing calls this directly
no outgoing calls
no test coverage detected