<commit_before>#! test/for/moderni/sh
# -*- mode: sh; -*-
# See the file LICENSE in the main modernish directory for the licence.

doTest1() {
	title='isset -r: an unset readonly'
	unset -v unsetro
	readonly unsetro
	if ! isset -v unsetro && isset -r unsetro; then
		return 0
	elif thisshellhas BUG_NOUNSETRO; then
		xfailmsg=BUG_NOUNSETRO
		return 2
	else
		return 1
	fi
}

doTest2() {
	title='isset -r: a set readonly'
	readonly setro=foo
	isset -v setro && isset -r setro
}

doTest3() {
	title='isset -r: an unset non-readonly'
	unset -v unsetnonro
	! isset -v unsetnonro && ! isset -r unsetnonro
}

doTest4() {
	title='isset -r: a set non-readonly'
	setnonro=foo
	isset -v setnonro && ! isset -r setnonro
}

doTest5() {
	title='isset -x: an unset exported variable'
	unset -v unsetex
	export unsetex
	if ! isset -v unsetex && isset -x unsetex; then
		return 0
	elif thisshellhas BUG_NOUNSETEX; then
		xfailmsg=BUG_NOUNSETEX
		return 2
	else
		return 1
	fi
}

doTest6() {
	title='isset -x: a set exported variable'
	export setex=foo
	isset -v setex && isset -x setex
}

doTest7() {
	title='isset -x: an unset non-exported variable'
	unset -v unsetnonex
	! isset -v unsetnonex && ! isset -x unsetnonex
}

doTest8() {
	title='isset -x: a set non-exported variable'
	setnonex=foo
	isset -v setnonex && ! isset -x setnonex
}

doTest9() {
	title='isset -r/-x: an unset exported readonly' 
	unset -v unsetrx
	export unsetrx
	readonly unsetrx
	if ! isset -v unsetrx && isset -r unsetrx && isset -x unsetrx; then
		return 0
	elif thisshellhas BUG_NOUNSETRO || thisshellhas BUG_NOUNSETEX; then
		xfailmsg='BUG_NOUNSET{RO,EX}'
		return 2
	else
		return 1
	fi
}

doTest10() {
	title='isset -r/-x: a set exported readonly'
	export setrx=foo
	readonly setrx
	isset -v setrx && isset -r setrx && isset -x setrx
}

lastTest=10
<commit_msg>complete the test suite for isset()<commit_after>#! test/for/moderni/sh
# -*- mode: sh; -*-
# See the file LICENSE in the main modernish directory for the licence.

doTest1() {
	title='isset -r: an unset readonly'
	unset -v unsetro
	readonly unsetro
	if ! isset -v unsetro && isset -r unsetro; then
		return 0
	elif thisshellhas BUG_NOUNSETRO; then
		xfailmsg=BUG_NOUNSETRO
		return 2
	else
		return 1
	fi
}

doTest2() {
	title='isset -r: a set readonly'
	readonly setro=foo
	isset -v setro && isset -r setro
}

doTest3() {
	title='isset -r: an unset non-readonly'
	unset -v unsetnonro
	! isset -v unsetnonro && ! isset -r unsetnonro
}

doTest4() {
	title='isset -r: a set non-readonly'
	setnonro=foo
	isset -v setnonro && ! isset -r setnonro
}

doTest5() {
	title='isset -x: an unset exported variable'
	unset -v unsetex
	export unsetex
	if ! isset -v unsetex && isset -x unsetex; then
		return 0
	elif thisshellhas BUG_NOUNSETEX; then
		xfailmsg=BUG_NOUNSETEX
		return 2
	else
		return 1
	fi
}

doTest6() {
	title='isset -x: a set exported variable'
	export setex=foo
	isset -v setex && isset -x setex
}

doTest7() {
	title='isset -x: an unset non-exported variable'
	unset -v unsetnonex
	! isset -v unsetnonex && ! isset -x unsetnonex
}

doTest8() {
	title='isset -x: a set non-exported variable'
	setnonex=foo
	isset -v setnonex && ! isset -x setnonex
}

doTest9() {
	title='isset -r/-x: an unset exported readonly' 
	unset -v unsetrx
	export unsetrx
	readonly unsetrx
	if ! isset -v unsetrx && isset -r unsetrx && isset -x unsetrx; then
		return 0
	elif thisshellhas BUG_NOUNSETRO || thisshellhas BUG_NOUNSETEX; then
		xfailmsg='BUG_NOUNSET{RO,EX}'
		return 2
	else
		return 1
	fi
}

doTest10() {
	title='isset -r/-x: a set exported readonly'
	export setrx=foo
	readonly setrx
	isset -v setrx && isset -r setrx && isset -x setrx
}

doTest11() {
	title='isset -f: an unset function'
	unset -f _Msh_nofunction 2>/dev/null
	! isset -f _Msh_nofunction
}

doTest12() {
	title='isset -f: a set function'
	isset -f doTest12
}

doTest13() {
	title='isset -f: a readonly function'
	if ! thisshellhas ROFUNC; then
		skipmsg='no ROFUNC'
		return 3
	fi
	(
		_Msh_testFn() { :; }
		readonly -f _Msh_testFn && isset -f _Msh_testFn
	) || return 1
}

doTest14() {
	title='isset: an unset short shell option'
	(set +f && ! isset -f)
}

doTest15() {
	title='isset: a set short shell option'
	(set -f && isset -f) || return 1
}

doTest16() {
	title='isset -o: an unset long shell option'
	(set +f && ! isset -o noglob)
}

doTest17() {
	title='isset -o: a set long shell option'
	(set -f && isset -o noglob) || return 1
}

doTest18() {
	title='isset (-v): an unset variable'
	unset -v _Msh_test && ! isset -v _Msh_test && ! isset _Msh_test
}

doTest19() {
	title='isset (-v): a set variable'
	isset -v title && isset title || return 1
}

doTest20() {
	title='isset (-v): unset IFS'
	if thisshellhas BUG_IFSISSET; then
		okmsg='BUG_IFSISSET worked around'
		failmsg='BUG_IFSISSET workaround failed'
	fi
	push IFS
	unset -v IFS
	if ! isset -v IFS && ! isset IFS; then
		pop IFS
		return 0
	fi
	pop IFS
	return 1
}

doTest21() {
	title='isset (-v): set, empty IFS'
	if thisshellhas BUG_IFSISSET; then
		okmsg='BUG_IFSISSET worked around'
		failmsg='BUG_IFSISSET workaround failed'
	fi
	push IFS
	IFS=
	if isset -v IFS && isset IFS; then
		pop IFS
		return 0
	fi
	pop IFS
	return 1
}

doTest22() {
	title='isset (-v): set, nonempty IFS'
	if thisshellhas BUG_IFSISSET; then
		okmsg='BUG_IFSISSET worked around'
		failmsg='BUG_IFSISSET workaround failed'
	fi
	push IFS
	IFS=" $CCt$CCn"
	if isset -v IFS && isset IFS; then
		pop IFS
		return 0
	fi
	pop IFS
	return 1
}

lastTest=22

{'fraction_non_alphanumeric': 0.1146345908511026, 'fraction_numerical': 0.0149444140696191, 'mean_word_length': 3.4545454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5372505', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2277, 'n_words': 698}