3 use crate::clean
::collapse_doc_fragments
;
5 use rustc_resolve
::rustdoc
::{unindent_doc_fragments, DocFragment, DocFragmentKind}
;
6 use rustc_span
::create_default_session_globals_then
;
7 use rustc_span
::source_map
::DUMMY_SP
;
8 use rustc_span
::symbol
::Symbol
;
10 fn create_doc_fragment(s
: &str) -> Vec
<DocFragment
> {
14 doc
: Symbol
::intern(s
),
15 kind
: DocFragmentKind
::SugaredDoc
,
21 fn run_test(input
: &str, expected
: &str) {
22 create_default_session_globals_then(|| {
23 let mut s
= create_doc_fragment(input
);
24 unindent_doc_fragments(&mut s
);
25 assert_eq
!(collapse_doc_fragments(&s
), expected
);
30 fn should_unindent() {
31 run_test(" line1\n line2", "line1\nline2");
35 fn should_unindent_multiple_paragraphs() {
36 run_test(" line1\n\n line2", "line1\n\nline2");
40 fn should_leave_multiple_indent_levels() {
41 // Line 2 is indented another level beyond the
42 // base indentation and should be preserved
43 run_test(" line1\n\n line2", "line1\n\n line2");
47 fn should_ignore_first_line_indent() {
48 run_test("line1\n line2", "line1\n line2");
52 fn should_not_ignore_first_line_indent_in_a_single_line_para() {
53 run_test("line1\n\n line2", "line1\n\n line2");
57 fn should_unindent_tabs() {
58 run_test("\tline1\n\tline2", "line1\nline2");
62 fn should_trim_mixed_indentation() {
63 run_test("\t line1\n\t line2", "line1\nline2");
64 run_test(" \tline1\n \tline2", "line1\nline2");
68 fn should_not_trim() {
69 run_test("\t line1 \n\t line2", "line1 \nline2");
70 run_test(" \tline1 \n \tline2", "line1 \nline2");
74 fn is_same_generic() {
75 use crate::clean
::types
::{PrimitiveType, Type}
;
76 use crate::formats
::cache
::Cache
;
77 let cache
= Cache
::new(false);
78 let generic
= Type
::Generic(rustc_span
::symbol
::sym
::Any
);
79 let unit
= Type
::Primitive(PrimitiveType
::Unit
);
80 assert
!(!generic
.is_doc_subtype_of(&unit
, &cache
));
81 assert
!(unit
.is_doc_subtype_of(&generic
, &cache
));