File: constructors.rs

package info (click to toggle)
rust-search-path 0.1.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 148 kB
  • sloc: makefile: 12; sh: 1
file content (91 lines) | stat: -rw-r--r-- 2,491 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use search_path::SearchPath;
use std::path::{Path, PathBuf};

#[cfg(target_family = "windows")]
const SIMPLE_PATH: &str = ".;..";
#[cfg(not(target_family = "windows"))]
const SIMPLE_PATH: &str = ".:..";

#[cfg(target_family = "windows")]
const NOT_SO_SIMPLE_PATH: &str = ";.;..;";
#[cfg(not(target_family = "windows"))]
const NOT_SO_SIMPLE_PATH: &str = ":.:..:";

fn assert_correct(search_path: &SearchPath) {
    assert_eq!(search_path.len(), 2);
    assert!(search_path.contains(&PathBuf::from(".")));
    assert!(search_path.contains(&PathBuf::from("..")));
    assert!(search_path.contains_cwd());
    assert!(!search_path.contains(&PathBuf::from("tests")));
}

// ------------------------------------------------------------------------------------------------

#[test]
fn test_no_env_var() {
    let search_path = SearchPath::new("UNLIKELY_THIS_VAR_EXISTS");
    assert!(search_path.is_err());
}

#[test]
fn test_no_env_var_or() {
    let search_path = SearchPath::new_or("UNLIKELY_THIS_VAR_EXISTS", SIMPLE_PATH);
    assert_correct(&search_path);
}

#[test]
fn test_no_env_var_or_default() {
    let search_path = SearchPath::new_or_default("UNLIKELY_THIS_VAR_EXISTS");
    assert_eq!(search_path.len(), 0);
}

#[test]
fn test_ignore_empty() {
    let search_path = SearchPath::new_or("UNLIKELY_THIS_VAR_EXISTS", "");
    assert_eq!(search_path.len(), 0);
}

#[test]
fn test_ignore_empty_split() {
    let search_path = SearchPath::new_or("UNLIKELY_THIS_VAR_EXISTS", NOT_SO_SIMPLE_PATH);
    assert_correct(&search_path);
}

// ------------------------------------------------------------------------------------------------

#[test]
fn from_string() {
    let search_path: SearchPath = String::from(SIMPLE_PATH).into();
    assert_correct(&search_path);
}

#[test]
fn from_str() {
    let search_path: SearchPath = SIMPLE_PATH.into();
    assert_correct(&search_path);
}

#[test]
fn from_str_vec() {
    let search_path: SearchPath = vec![".", ".."].into();
    assert_correct(&search_path);
}

#[test]
fn from_pathbuf_vec() {
    let search_path: SearchPath = vec![PathBuf::from("."), PathBuf::from("..")].into();
    assert_correct(&search_path);
}

#[test]
fn from_path_vec() {
    let search_path: SearchPath = vec![Path::new("."), Path::new("..")].into();
    assert_correct(&search_path);
}

#[test]
fn from_pathbuf() {
    let search_path: SearchPath = PathBuf::from(".").into();
    assert_eq!(search_path.len(), 1);
    assert!(search_path.contains(&PathBuf::from(".")));
}