]> git.proxmox.com Git - rustc.git/blob - src/librustdoc/clean/types/tests.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / src / librustdoc / clean / types / tests.rs
1 use super::*;
2
3 use crate::clean::collapse_doc_fragments;
4
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;
9
10 fn create_doc_fragment(s: &str) -> Vec<DocFragment> {
11 vec![DocFragment {
12 span: DUMMY_SP,
13 item_id: None,
14 doc: Symbol::intern(s),
15 kind: DocFragmentKind::SugaredDoc,
16 indent: 0,
17 }]
18 }
19
20 #[track_caller]
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);
26 });
27 }
28
29 #[test]
30 fn should_unindent() {
31 run_test(" line1\n line2", "line1\nline2");
32 }
33
34 #[test]
35 fn should_unindent_multiple_paragraphs() {
36 run_test(" line1\n\n line2", "line1\n\nline2");
37 }
38
39 #[test]
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");
44 }
45
46 #[test]
47 fn should_ignore_first_line_indent() {
48 run_test("line1\n line2", "line1\n line2");
49 }
50
51 #[test]
52 fn should_not_ignore_first_line_indent_in_a_single_line_para() {
53 run_test("line1\n\n line2", "line1\n\n line2");
54 }
55
56 #[test]
57 fn should_unindent_tabs() {
58 run_test("\tline1\n\tline2", "line1\nline2");
59 }
60
61 #[test]
62 fn should_trim_mixed_indentation() {
63 run_test("\t line1\n\t line2", "line1\nline2");
64 run_test(" \tline1\n \tline2", "line1\nline2");
65 }
66
67 #[test]
68 fn should_not_trim() {
69 run_test("\t line1 \n\t line2", "line1 \nline2");
70 run_test(" \tline1 \n \tline2", "line1 \nline2");
71 }
72
73 #[test]
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));
82 }