<commit_before><commit_msg>Adds a test for #240<commit_after>extern crate mdbook;
extern crate tempdir;

use std::path::Path;
use std::fs::File;
use std::io::Write;

use mdbook::MDBook;
use tempdir::TempDir;

// Tests that config values unspecified in the configuration file do not overwrite
// values specified earlier.
#[test]
fn do_not_overwrite_unspecified_config_values() {
    let dir = TempDir::new("mdbook").expect("Could not create a temp dir");
    
    let book = MDBook::new(dir.path())
        .with_source(Path::new("bar"))
        .with_destination(Path::new("baz"));

    assert_eq!(book.get_root(), dir.path());
    assert_eq!(book.get_source(), dir.path().join("bar"));
    assert_eq!(book.get_destination().unwrap(), dir.path().join("baz"));

    // Test when trying to read a config file that does not exist
    let book = book.read_config().expect("Error reading the config file");

    assert_eq!(book.get_root(), dir.path());
    assert_eq!(book.get_source(), dir.path().join("bar"));
    assert_eq!(book.get_destination().unwrap(), dir.path().join("baz"));

    // Try with a partial config file
    let file_path = dir.path().join("book.toml");
    let mut f = File::create(file_path).expect("Could not create config file");
    f.write_all(br#"source = "barbaz""#).expect("Could not write to config file");
    f.sync_all().expect("Could not sync the file");

    let book = book.read_config().expect("Error reading the config file");

    assert_eq!(book.get_root(), dir.path());
    assert_eq!(book.get_source(), dir.path().join("barbaz"));
    assert_eq!(book.get_destination().unwrap(), dir.path().join("baz"));
}

{'fraction_non_alphanumeric': 0.177007299270073, 'fraction_numerical': 0.0018248175182481751, 'mean_word_length': 4.5574324324324325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '605087', 'n_tokens_mistral': 529, 'n_tokens_neox': 509, 'n_words': 124}