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
#![cfg_attr(test, allow(clippy::expect_used, clippy::unwrap_used))]

use camino::Utf8PathBuf;
use parallax::Parallax;
use tempfile::TempDir;

const VALID: &str = r#"{:variants {:desktop {:viewport [1280 900]}}
 :server (fn [] {:cmd ["true"]})
 :flow (fn [] nil)}"#;

const NAMED: &str = r#"{:name "ketchup"
 :variants {:desktop {:viewport [1280 900]}}
 :server (fn [] {:cmd ["true"]})
 :flow (fn [] nil)}"#;

fn config_file(source: &str) -> (TempDir, Utf8PathBuf) {
    let dir = tempfile::tempdir().expect("tempdir");
    let path: Utf8PathBuf = dir
        .path()
        .join("config.fnl")
        .try_into()
        .expect("utf-8 path");
    fs_err::write(&path, source).expect("write config");
    (dir, path)
}

#[test]
fn name_defaults_to_the_config_directory() {
    let (dir, path) = config_file(VALID);
    let parallax = Parallax::load(&path).expect("config loads");
    let directory = dir.path().file_name().unwrap().to_str().unwrap();
    assert_eq!(parallax.name(), directory);
}

#[test]
fn name_field_overrides_the_default() {
    let (_dir, path) = config_file(NAMED);
    let parallax = Parallax::load(&path).expect("config loads");
    assert_eq!(parallax.name(), "ketchup");
}