<commit_before>#!/usr/bin/env bats

################################################################################
# Tests for built-in Doily commands.
# https://github.com/relsqui/doily
#
# (c) 2017 <NAME>.
# You are free to use, copy, modify, etc. this by the terms of the MIT license.
# See included LICENSE.txt for details.
#
# This file is intended to be read by Bats.
################################################################################

load helpers

setup() {
    doily_dir="${DOILY_TMP}/dailies"
    mkdir -p "${doily_dir}"
    source "${BATS_TEST_DIRNAME}"/../doily
}

@test "identify dailyfile" {
    # Test various kinds of day input.
    touch "${doily_dir}/2017-01-01"
    touch "${doily_dir}/2017-01-02"
    test "$(identify_dailyfile last)" == "2017-01-02"
    touch "${doily_dir}/2017-01-03"
    test "$(identify_dailyfile last)" == "2017-01-03"
    test "$(identify_dailyfile "2017-01-01")" == "2017-01-01"
    test "$(identify_dailyfile "January 2, 2017")" == "2017-01-02"
    test "$(identify_dailyfile "")" == ""
    test "$(identify_dailyfile "1985-12-05")" == ""
    test "$(identify_dailyfile "This isn't a parseable date.")" == ""
}

@test "config command" {
    # Test that the config command edits the config.
    EDITOR=touch
    assertFails ls "${personal_config}"
    mkdir -p "${PERSONAL_CONFIG_DIR}"
    command_config
    ls "${PERSONAL_CONFIG}"
}

@test "version command" {
    # Test that the version command succeeds.
    command_version
}

@test "help command" {
    # Test that the help command succeeds.
    command_help
}

@test "read command" {
    # Test that the read command affects the correct files.
    PAGER=cat
    for date in 1984-11-03 1985-12-05; do
        echo "${date}" > "${doily_dir}/${date}"
        test "$(command_read "${date}")" == "${date}"
    done
    test "$(command_read)" == "1985-12-05"
    assertFails command_read "Some non-date."
}

@test "search command default" {
    # Test that the search command defaults to all daily files.
    for file in 1 2 3; do
        echo "foo" > "${doily_dir}/${file}"
        echo "${doily_dir}/${file}:foo" >> "${DOILY_TMP}/expected"
    done
    command_search "foo" > "${DOILY_TMP}/actual"
    diff "${DOILY_TMP}/expected" "${DOILY_TMP}/actual"

    echo "bar" > "${doily_dir}/4"
    diff "${DOILY_TMP}/expected" "${DOILY_TMP}/actual"
    echo "foo" >> "${doily_dir}/4"
    echo "${doily_dir}/4:foo" >> "${DOILY_TMP}/expected"
    command_search "foo" > "${DOILY_TMP}/actual"
    diff "${DOILY_TMP}/expected" "${DOILY_TMP}/actual"
}

@test "default command is write" {
    # Test that run_command chooses write when no command is specified.
    EDITOR=touch
    assertFails ls "${doily_dir}/$(date +%F)"
    run_command
    ls "${doily_dir}/$(date +%F)"
}

@test "nonexistant command" {
    # Test that run_command fails when passed non-commands.
    assertFails run_command not_a_command
}
<commit_msg>Add tests for the search command with specific dates.<commit_after>#!/usr/bin/env bats

################################################################################
# Tests for built-in Doily commands.
# https://github.com/relsqui/doily
#
# (c) 2017 <NAME>.
# You are free to use, copy, modify, etc. this by the terms of the MIT license.
# See included LICENSE.txt for details.
#
# This file is intended to be read by Bats.
################################################################################

load helpers

setup() {
    doily_dir="${DOILY_TMP}/dailies"
    mkdir -p "${doily_dir}"
    source "${BATS_TEST_DIRNAME}"/../doily
}

@test "identify dailyfile" {
    # Test various kinds of day input.
    touch "${doily_dir}/2017-01-01"
    touch "${doily_dir}/2017-01-02"
    test "$(identify_dailyfile last)" == "2017-01-02"
    touch "${doily_dir}/2017-01-03"
    test "$(identify_dailyfile last)" == "2017-01-03"
    test "$(identify_dailyfile "2017-01-01")" == "2017-01-01"
    test "$(identify_dailyfile "January 2, 2017")" == "2017-01-02"
    test "$(identify_dailyfile "")" == ""
    test "$(identify_dailyfile "1985-12-05")" == ""
    test "$(identify_dailyfile "This isn't a parseable date.")" == ""
}

@test "config command" {
    # Test that the config command edits the config.
    EDITOR=touch
    assertFails ls "${personal_config}"
    mkdir -p "${PERSONAL_CONFIG_DIR}"
    command_config
    ls "${PERSONAL_CONFIG}"
}

@test "version command" {
    # Test that the version command succeeds.
    command_version
}

@test "help command" {
    # Test that the help command succeeds.
    command_help
}

@test "read command" {
    # Test that the read command affects the correct files.
    PAGER=cat
    for date in 1984-11-03 1985-12-05; do
        echo "${date}" > "${doily_dir}/${date}"
        test "$(command_read "${date}")" == "${date}"
    done
    test "$(command_read)" == "1985-12-05"
    assertFails command_read "Some non-date."
}

@test "search command default" {
    # Test that the search command defaults to all daily files.
    for file in 1 2 3; do
        echo "foo" > "${doily_dir}/${file}"
        echo "${doily_dir}/${file}:foo" >> "${DOILY_TMP}/expected"
    done
    command_search "foo" > "${DOILY_TMP}/actual"
    diff "${DOILY_TMP}/expected" "${DOILY_TMP}/actual"

    echo "bar" > "${doily_dir}/4"
    diff "${DOILY_TMP}/expected" "${DOILY_TMP}/actual"
    echo "foo" >> "${doily_dir}/4"
    echo "${doily_dir}/4:foo" >> "${DOILY_TMP}/expected"
    command_search "foo" > "${DOILY_TMP}/actual"
    diff "${DOILY_TMP}/expected" "${DOILY_TMP}/actual"
}

@test "search command bad date" {
    assertFails command_search "foo" "not a date"
}

@test "search command specific dates" {
    echo "foo" > "${doily_dir}/1985-12-05"
    test "foo" == "$(command_search 'foo' 'December 5, 1985')"
    assertFails command_search 'foo' 'December 6, 1985'
    touch "${doily_dir}/1985-12-06"
    test "" == "$(command_search 'foo' 'December 6, 1985')"
}

@test "default command is write" {
    # Test that run_command chooses write when no command is specified.
    EDITOR=touch
    assertFails ls "${doily_dir}/$(date +%F)"
    run_command
    ls "${doily_dir}/$(date +%F)"
}

@test "nonexistant command" {
    # Test that run_command fails when passed non-commands.
    assertFails run_command not_a_command
}

{'fraction_non_alphanumeric': 0.2031548757170172, 'fraction_numerical': 0.04031230082855322, 'mean_word_length': 3.63589364844904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 2, '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': '3592989', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2049, 'n_words': 566}