source [file dirname [info script]]/testing.tcl

needs cmd regexp
testConstraint regexp_are [expr {[regexp {\d} 1]}]
needs constraint regexp_are

# Test regexp counted repetitions

set n 0
foreach {pat str exp} {
	a+ bac a
	a{1,} bac a
	a* bac {{}}
	a{0,} bac {{}}
	aa+ bac {}
	a{2,} bac {}
	a{2,} bacaad aa
	a{3,} bacaad {}
	{a{2,}$} bacaad {}
	{a{2,}$} bacaa aa
	{a{2,}$} ba {}
	{a{2,}$} aa aa
	{a{0,0}b$} b b
	{a{1,1}b$} b {}
	{a{1,1}b$} cab ab
	{a{2,2}b$} cab {}
	{a{2,2}b$} cabaabx {}
	{a{2,2}b$} cacaab aab
	ca{2,4}b cacaab caab
	ca{2,3}b cacaab caab
	ca{2,3}b cacaaab caaab
	c(a|b){2,3}d xcbad {cbad a}
	c(a|b){2,3}d xcabbd {cabbd b}
	c(a|b){2,3}d xcbaaad {}
	a{4} baaaad aaaa
	a{2,5} baaaad aaaa
	a{1,3} baaaad aaa
	a{1,2} baaaad aa
	a{3,4} baaaad aaaa
	a{5,6} baaaad {}
	a{4}? baaaad aaaa
	a{2,5}? baaaad aa
	a{1,3}? baaaad a
	a{1,2}? baaaad a
	a{3,4}? baaaad aaa
	a{5,6}? baaaad {}
	{\d{1,3}} 239 239
	(aa|bb)?c xabbaac {aac aa}
	(a|y)+ bac {a a}
	(a|y){1,} bac {a a}
	(a|y)* bac {{} {}}
	(a|y){0,} bac {{} {}}
	(a|y)a+ bac {}
	(a|y){2,} bac {}
	(a|y){2,} bacaad {aa a}
	(a|y){3,} bacaad {}
	{(a|y){2,}$} bacaad {}
	{(a|y){2,}$} bacaa {aa a}
	{(a|y){2,}$} ba {}
	{(a|y){2,}$} aa {aa a}
	{(a|y){0,0}b$} b {b {}}
	{(a|y){1,1}b$} b {}
	{(a|y){1,1}b$} cab {ab a}
	{(a|y){2,2}b$} cab {}
	{(a|y){2,2}b$} cabaabx {}
	{(a|y){2,2}b$} cacaab {aab a}
	c(a|y){2,4}b cacaab {caab a}
	c(a|y){2,3}b cacaab {caab a}
	c(a|y){2,3}b cacaaab {caaab a}
	c((a|y)|b){2,3}d xcbad {cbad a a}
	####c((a|y)|b){2,3}d xcabbd {cabbd b {}}
	c((a|y)|b){2,3}d xcbaaad {}
	(a|y){4} baaaad {aaaa a}
	(a|y){2,5} baaaad {aaaa a}
	(a|y){1,3} baaaad {aaa a}
	(a|y){1,2} baaaad {aa a}
	(a|y){3,4} baaaad {aaaa a}
	(a|y){5,6} baaaad {}
	(a|y){4}? baaaad {aaaa a}
	(a|y){2,5}? baaaad {aa a}
	(a|y){1,3}? baaaad {a a}
	(a|y){1,2}? baaaad {a a}
	(a|y){3,4}? baaaad {aaa a}
	(a|y){5,6}? baaaad {}
    {[[:alpha:]]+} _bcd56_ef bcd
    {[[:alnum:]]+} _bcd56_ef bcd56
    {[\w]+} :_bcd56_ef _bcd56_ef
    {[[:space:]]+} "_bc \t\r\n\f\v_" "{ \t\r\n\f\v}"
    {[\x41-\x43]+} "_ABCD_" ABC
    {\m.+\M} "#A test#" "{A test}"
    {\m.+?\M} "#A test#" "A"
    {\m\M} "a" ""
    {ab*c} xnbbmbbbc {}
    {.^xxx} yyy {}
    {\mb} "   abc   " ""
	####((a*)*b)*b aaaaaaaaaaaaaaaaaaaaaaaaab {b {} {}}
	####(a*)* aab {aa {}}
	{^([^:=]*)(:)?(=)?$} version {version version {} {}}
} {
	if {[string match #* $pat]} {
		continue
	}
	#puts \t[list $pat $str [regexp -inline -- $pat $str]]
	test regcount-1.[incr n] "Test: regexp $pat $str" [list regexp -inline -- $pat $str] $exp
}

test regcount-2.1 "regexp counts cleared" {
	set re "((a|b){1,2}(c{2,3}))"
	regexp -inline $re xabcccce
	regexp -inline $re xabcccce
} {abccc abccc b ccc}

testreport
