summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/tests.rs
blob: 437d3995e29fca356eb31f085d9f10437496507a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::html::format::href_relative_parts;
use rustc_span::{sym, Symbol};

fn assert_relative_path(expected: &[Symbol], relative_to_fqp: &[Symbol], fqp: &[Symbol]) {
    // No `create_default_session_globals_then` call is needed here because all
    // the symbols used are static, and no `Symbol::intern` calls occur.
    assert_eq!(expected, href_relative_parts(&fqp, &relative_to_fqp).collect::<Vec<_>>());
}

#[test]
fn href_relative_parts_basic() {
    let relative_to_fqp = &[sym::std, sym::vec];
    let fqp = &[sym::std, sym::iter];
    assert_relative_path(&[sym::dotdot, sym::iter], relative_to_fqp, fqp);
}

#[test]
fn href_relative_parts_parent_module() {
    let relative_to_fqp = &[sym::std, sym::vec];
    let fqp = &[sym::std];
    assert_relative_path(&[sym::dotdot], relative_to_fqp, fqp);
}

#[test]
fn href_relative_parts_different_crate() {
    let relative_to_fqp = &[sym::std, sym::vec];
    let fqp = &[sym::core, sym::iter];
    assert_relative_path(&[sym::dotdot, sym::dotdot, sym::core, sym::iter], relative_to_fqp, fqp);
}

#[test]
fn href_relative_parts_same_module() {
    let relative_to_fqp = &[sym::std, sym::vec];
    let fqp = &[sym::std, sym::vec];
    assert_relative_path(&[], relative_to_fqp, fqp);
}

#[test]
fn href_relative_parts_child_module() {
    let relative_to_fqp = &[sym::std];
    let fqp = &[sym::std, sym::vec];
    assert_relative_path(&[sym::vec], relative_to_fqp, fqp);
}

#[test]
fn href_relative_parts_root() {
    let relative_to_fqp = &[];
    let fqp = &[sym::std];
    assert_relative_path(&[sym::std], relative_to_fqp, fqp);
}