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