#!/usr/bin/env zunit

@setup {
    load "../you-should-use.plugin.zsh"
    # Simplify format for tests
    YSU_MESSAGE_FORMAT='Found existing %alias_type for "%command". You should use: "%alias"'
    unset YSU_MESSAGE_POSITION
}

@teardown {
}

@test 'global aliases no match' {
    alias -g hw="Hello World!"
    run _check_global_aliases "echo 'hello'"

    assert "$output" is_empty
    assert $state equals 0
}

@test 'global aliases match' {
    alias -g NE="2>/dev/null"
    run _check_global_aliases "echo 'hello' 2>/dev/null"

    assert "$output" contains 'Found existing global alias for "2>/dev/null". You should use: "NE"'
    assert $state equals 0
}

@test 'test doesnt match substrings' {
    alias -g n="nvim"
    run _check_global_aliases "nvimkaowjqwe"

    assert "$output" is_empty
    assert $state equals 0
}

@test 'global aliases ignore on sudo' {
    alias -g NE="2>/dev/null"
    run _check_global_aliases "sudo echo 'hello' 2>/dev/null"

    assert "$output" is_empty
    assert $state equals 0
}

@test 'global aliases - does not report an ignored alias' {
    export YSU_MODE="ALL"
    export YSU_IGNORED_GLOBAL_ALIASES=("..." "NE")
    alias -g ...="../.."
    run _check_global_aliases "cd ../.."

    assert $output is_empty
    assert $state equals 0
}