Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / language-server / src / tests / document_symbols.rs
2.9 kB 159 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2024 The Gleam contributors 3 4use insta::assert_debug_snapshot; 5use lsp_types::{ 6 DocumentSymbol, DocumentSymbolParams, PartialResultParams, WorkDoneProgressParams, 7}; 8 9use super::*; 10 11fn doc_symbols(tester: TestProject<'_>) -> Vec<DocumentSymbol> { 12 tester.at(Position::default(), |engine, param, _| { 13 let params = DocumentSymbolParams { 14 text_document: param.text_document, 15 work_done_progress_params: WorkDoneProgressParams::default(), 16 partial_result_params: PartialResultParams::default(), 17 }; 18 let response = engine.document_symbol(params); 19 20 response.result.unwrap() 21 }) 22} 23 24#[test] 25fn doc_symbols_type_no_constructors() { 26 let code = " 27pub type A"; 28 29 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 30} 31 32#[test] 33fn doc_symbols_type_no_constructors_starting_at_documentation() { 34 let code = " 35/// My type 36pub type A"; 37 38 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 39} 40 41#[test] 42fn doc_symbols_type_no_constructors_starting_at_empty_doc() { 43 let code = " 44// Some prior code... 45 46/// 47pub type A"; 48 49 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 50} 51 52#[test] 53fn doc_symbols_type_constructor_no_args() { 54 let code = " 55pub type B { 56 C 57 D 58 59 /// E 60 E 61}"; 62 63 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 64} 65 66#[test] 67fn doc_symbols_type_constructor_pos_args() { 68 let code = " 69pub type B { 70 C(Int) 71 72 /// D 73 D(List(Int)) 74 75 /// E 76 E( 77 Result(Int, Bool) 78 ) 79}"; 80 81 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 82} 83 84#[test] 85fn doc_symbols_type_constructor_labeled_args() { 86 let code = " 87pub type B { 88 C(argc: Int) 89 90 /// D 91 D(argd: List(Int)) 92 93 /// E 94 E( 95 /// Arg 96 arge: Result(Int, Bool) 97 ) 98}"; 99 100 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 101} 102 103#[test] 104fn doc_symbols_type_constructor_pos_and_labeled_args() { 105 let code = " 106pub type B { 107 C(Int, argc: Int) 108 109 /// D 110 D(Int, argd: List(Int)) 111 112 /// E 113 E( 114 Int, 115 116 /// Arg 117 arge: Result(Int, Bool) 118 ) 119}"; 120 121 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 122} 123 124#[test] 125fn doc_symbols_type_alias() { 126 let code = " 127/// DOC 128pub type FFF = Int 129 130pub type FFFF = List(Int)"; 131 132 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 133} 134 135#[test] 136fn doc_symbols_function() { 137 let code = " 138/// DOC 139pub fn super_func(a: Int) -> List(Int) { 140 [a + 5] 141} 142 143pub fn super_func2(a: Int) -> List(Int) { 144 [a + 5] 145}"; 146 147 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 148} 149 150#[test] 151fn doc_symbols_constant() { 152 let code = " 153/// DOC 154pub const my_const = 5 155 156pub const my_const2 = [25]"; 157 158 assert_debug_snapshot!(doc_symbols(TestProject::for_source(code))) 159}