#!/usr/bin/env bash
tcmp() {
	local atom
	echo -n "Checking '${2}'"
	atomsp atom "${2}"
	echo " == '${atom[*]}'"
	(( ${#atom[@]} == 9 )) || fail "expected array length 9, got ${#atom[@]}"
	[[ ${atom[*]} == ${1} ]] || fail mismatch
}
tcmp '        ' ''
tcmp '!        ' '!'
tcmp ' =       ' '='
tcmp '  c      ' 'c/'
tcmp '   n     ' 'n'
tcmp '   0     ' '0'
tcmp '    0    ' '-0'
tcmp '     0   ' '-r0'
tcmp '      0  ' ':0'
tcmp '       0 ' '/0'
tcmp '        =' ':='
tcmp '    1.0    ' '1.0'
tcmp '! ~ c      ' '!~c/'
tcmp '   n 0 1   ' 'n-0-r1'
tcmp '      a b =' ':a/b='
# note <no-slot>/<sub> may not be valid by the PM spec, but is handled anyway
tcmp ' ~ c  0 1  0 ' '~c/-0-r1:/0'
tcmp '  cat name 0.1.2 3   ' 'cat/name-0.1.2-r3'
# likewise, */<sub> is also questionable, but atom should be valid beside that
tcmp \
	'!! >= _.+-0- _-test-T-123_beta1_-4a-6+-_p- 1.00.02b_alpha3_pre_p4 5 * _-+6-9 =' \
	'!!>=_.+-0-/_-test-T-123_beta1_-4a-6+-_p--1.00.02b_alpha3_pre_p4-r5:*/_-+6-9=[test(+),test(-)]'
tcmp '  c n     ' 'c/n::test'
tcmp '  c n 1*    ' 'c/n-1*'
tcmp '  c n 1    ' 'c/n/n-1.ebuild'
tcmp '  s s 1    ' 's/s/s-1.ebuild'
tcmp '  c n 1    ' 'c/n-1.ebuild'
tcmp '   n 1    ' 'n/n-1.ebuild'
xfail 1 atomsp '-c/n'
xfail 1 atomsp '@'
xfail 1 atomsp 'c/n-0@'
xfail 1 atomsp 'c/n-1-1'
xfail 1 atomsp 'c/n/n-1'
