mirror of
https://github.com/zdharma-continuum/zinit.git
synced 2026-09-10 07:36:38 -04:00
wait-invalid-suffix-x asserted on 'Expected one of: a, b, c', but
+zi-log colourises each suffix letter separately, so the raw output
carries escape sequences between them and no such contiguous substring
exists. Strip the escapes before asserting on the sentence.
for-invalid-as asserted rc 0 while the load ran on to
∞zinit-compile-plugin-hook, which returns 1 for this fixture ("No files
for compilation found") and made `zinit for' exit 1 for a reason
unrelated to the invalid ice under test. Add nocompile so the test
measures ice validation only.
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
289 lines
5.8 KiB
Bash
289 lines
5.8 KiB
Bash
#!/usr/bin/env zunit
|
|
# vim:ft=zsh:sw=2:sts=2:et:foldmarker={,}:foldmethod=marker
|
|
#
|
|
# Tests for ice value validation in .zinit-validate-ice()
|
|
#
|
|
|
|
@test 'as-valid-null' {
|
|
run zinit ice as'null'
|
|
assert $state equals 0
|
|
}
|
|
|
|
@test 'as-valid-command' {
|
|
run zinit ice as'command'
|
|
assert $state equals 0
|
|
}
|
|
|
|
@test 'as-valid-program' {
|
|
run zinit ice as'program'
|
|
assert $state equals 0
|
|
}
|
|
|
|
@test 'as-valid-completion' {
|
|
run zinit ice as'completion'
|
|
assert $state equals 0
|
|
}
|
|
|
|
@test 'as-empty' {
|
|
run zinit ice as''
|
|
assert $state equals 0
|
|
}
|
|
|
|
@test 'as-invalid-none' {
|
|
run zinit ice as'none'
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'none'
|
|
assert $output contains 'null'
|
|
assert $output contains 'program'
|
|
}
|
|
|
|
@test 'as-invalid-banana' {
|
|
run zinit ice as'banana'
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'banana'
|
|
}
|
|
|
|
@test 'wait-valid-0' {
|
|
run zinit ice wait'0'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-3' {
|
|
run zinit ice wait'3'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-0a' {
|
|
run zinit ice wait'0a'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-3b' {
|
|
run zinit ice wait'3b'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-1c' {
|
|
run zinit ice wait'1c'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-bang' {
|
|
run zinit ice wait'!0'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-bang-a' {
|
|
run zinit ice wait'!2a'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-bang-no-suffix' {
|
|
run zinit ice wait'!3'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-valid-decimal' {
|
|
run zinit ice wait'3.5'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-empty' {
|
|
run zinit ice wait
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-cond-command-exists' {
|
|
run zinit ice wait'[[ -n $commands[fzf] ]]'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-cond-arithmetic' {
|
|
run zinit ice wait'(( $+commands[kubectl] ))'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-cond-variable' {
|
|
run zinit ice wait'[[ -n $MY_VAR ]]'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-cond-always-false' {
|
|
run zinit ice wait'[[ 1 = 0 ]]'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-cond-single-command' {
|
|
run zinit ice wait'type fzf &>/dev/null'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'wait-invalid-suffix-x' {
|
|
run zinit ice wait'0x'
|
|
assert $state equals 0
|
|
assert $output contains 'wait'
|
|
assert $output contains 'x'
|
|
# +zi-log colourises each suffix letter separately, so the list reads
|
|
# `a<esc>, <esc>b<esc>, <esc>c' in the raw output and no contiguous
|
|
# 'a, b, c' exists to match. Strip the escapes before asserting on the
|
|
# sentence as a whole.
|
|
setopt localoptions extendedglob
|
|
local plain="${(S)output//$'\e'\[[0-9;]#[a-zA-Z]/}"
|
|
assert "$plain" contains 'Expected one of: a, b, c'
|
|
}
|
|
|
|
@test 'wait-invalid-suffix-d' {
|
|
run zinit ice wait'3d'
|
|
assert $state equals 0
|
|
assert $output contains 'wait'
|
|
assert $output contains 'd'
|
|
}
|
|
|
|
@test 'wait-invalid-suffix-z' {
|
|
run zinit ice wait'1z'
|
|
assert $state equals 0
|
|
assert $output contains 'wait'
|
|
assert $output contains 'z'
|
|
}
|
|
|
|
@test 'wait-invalid-bang-suffix' {
|
|
run zinit ice wait'!2x'
|
|
assert $state equals 0
|
|
assert $output contains 'wait'
|
|
assert $output contains 'x'
|
|
}
|
|
|
|
@test 'wait-invalid-suffix-A' {
|
|
run zinit ice wait'0A'
|
|
assert $state equals 0
|
|
assert $output contains 'wait'
|
|
assert $output contains 'A'
|
|
}
|
|
|
|
@test 'depth-valid-1' {
|
|
run zinit ice depth'1'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'depth-valid-10' {
|
|
run zinit ice depth'10'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'depth-invalid-zero' {
|
|
run zinit ice depth'0'
|
|
assert $state equals 0
|
|
assert $output contains 'depth'
|
|
assert $output contains '0'
|
|
}
|
|
|
|
@test 'depth-empty' {
|
|
run zinit ice depth''
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'depth-invalid-text' {
|
|
run zinit ice depth'abc'
|
|
assert $state equals 0
|
|
assert $output contains 'depth'
|
|
assert $output contains 'abc'
|
|
}
|
|
|
|
@test 'depth-invalid-negative' {
|
|
run zinit ice depth'-1'
|
|
assert $state equals 0
|
|
assert $output contains 'depth'
|
|
assert $output contains '-1'
|
|
}
|
|
|
|
@test 'depth-invalid-decimal' {
|
|
run zinit ice depth'1.5'
|
|
assert $state equals 0
|
|
assert $output contains 'depth'
|
|
assert $output contains '1.5'
|
|
}
|
|
|
|
@test 'combined-all-valid' {
|
|
run zinit ice as'null' wait'0a' depth'1'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'combined-some-invalid' {
|
|
run zinit ice as'none' wait'0a'
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'none'
|
|
}
|
|
|
|
@test 'combined-all-invalid' {
|
|
run zinit ice as'none' wait'3x' depth'abc'
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'wait'
|
|
assert $output contains 'depth'
|
|
}
|
|
|
|
@test 'dash-prefix-valid' {
|
|
run zinit ice --as'null'
|
|
assert $state equals 0
|
|
|
|
}
|
|
|
|
@test 'dash-prefix-invalid' {
|
|
run zinit ice --as'none'
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'none'
|
|
}
|
|
|
|
@test 'as-invalid-NULL-case' {
|
|
run zinit ice as'NULL'
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'NULL'
|
|
}
|
|
|
|
@test 'as-colon-valid' {
|
|
run zinit ice as:null
|
|
assert $state equals 0
|
|
}
|
|
|
|
@test 'as-colon-invalid' {
|
|
run zinit ice as:none
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'none'
|
|
}
|
|
|
|
@test 'for-invalid-as' {
|
|
# nocompile keeps the assertion on ice validation. Without it the load
|
|
# reaches ∞zinit-compile-plugin-hook, which returns 1 on this fixture
|
|
# ("No files for compilation found") and makes `zinit for' exit 1 for a
|
|
# reason that has nothing to do with the invalid ice under test.
|
|
run zinit for as'none' nocompile @zdharma-continuum/null
|
|
assert $state equals 0
|
|
assert $output contains 'as'
|
|
assert $output contains 'none'
|
|
}
|