# -*- tcl -*-
# textutil.test:  tests for the textutil package.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 2.0

support {
    useLocal     string.tcl   textutil::string
    useLocal     repeat.tcl   textutil::repeat
    useLocal     adjust.tcl   textutil::adjust
    useLocal     split.tcl    textutil::split
    useLocal     tabify.tcl   textutil::tabify
    useLocal     trim.tcl     textutil::trim
    useLocal     trim.tcl     textutil::trim
    useLocal     wcswidth.tcl textutil::wcswidth
}
testing {
    useLocalKeep textutil.tcl textutil
}

# -------------------------------------------------------------------------

test textutil-1.0 {blank -1} {
    textutil::blank -1
} {}

test textutil-1.1 {blank 0} {
    textutil::blank 0
} {}

test textutil-1.2 {blank 1} {
    textutil::blank 1
} { }

test textutil-1.3 {blank 10} {
    textutil::blank 10
} {          }



test textutil-2.0 {chop empty} {
    textutil::chop {}
} {}

test textutil-2.1 {chop single} {
    textutil::chop { }
} {}

test textutil-2.2 {chop long} {
    textutil::chop {abcde}
} {abcd}



test textutil-3.0 {tail empty} {
    textutil::tail {}
} {}

test textutil-3.1 {tail single} {
    textutil::tail { }
} {}

test textutil-3.2 {tail long} {
    textutil::tail {abcde}
} {bcde}



test textutil-4.0 {cap empty} {
    textutil::cap {}
} {}

test textutil-4.1 {cap single} {
    textutil::cap {a}
} {A}

test textutil-4.2 {cap long} {
    textutil::cap {abcde}
} {Abcde}

test textutil-4.3 {cap capped} {
    textutil::cap {Abcde}
} {Abcde}



test textutil-5.0 {uncap empty} {
    textutil::uncap {}
} {}

test textutil-5.1 {uncap single} {
    textutil::uncap {A}
} {a}

test textutil-5.2 {uncap long} {
    textutil::uncap {Abcde}
} {abcde}

test textutil-5.3 {uncap uncapped} {
    textutil::uncap {abcde}
} {abcde}



test textutil-6.0 {lcs, no strings} {
    textutil::longestCommonPrefixList {}
} {}

test textutil-6.1 {lcs, one string} {
    textutil::longestCommonPrefixList {foo}
} {foo}

test textutil-6.2 {lcs, two strings, no prefix} {
    textutil::longestCommonPrefixList {foo bar}
} {}

test textutil-6.3 {lcs, two strings, small prefix} {
    textutil::longestCommonPrefixList {foo fbar}
} {f}

test textutil-6.4 {lcs, two strings, common} {
    textutil::longestCommonPrefixList {foo foo}
} {foo}

test textutil-6.5 {lcs, multiple strings} {
    textutil::longestCommonPrefixList {foo fox fubar}
} {f}

# -------------------------------------------------------------------------

test textutil-7.0 {capEachWord, wrong args, not enough} -body {
    textutil::capEachWord
} -returnCodes error -result {wrong # args: should be "textutil::capEachWord sentence"}

test textutil-7.1 {capEachWord, wrong args, too many} -body {
    textutil::capEachWord S X
} -returnCodes error -result {wrong # args: should be "textutil::capEachWord sentence"}

test textutil-7.2 {capEachWord, empty} -body {
    textutil::capEachWord {}
} -result {}

test textutil-7.3 {capEachWord, single word} -body {
    textutil::capEachWord alpha
} -result Alpha

test textutil-7.4 {capEachWord, multiple words} -body {
    textutil::capEachWord {here comes the sun}
} -result {Here Comes The Sun}

test textutil-7.5 {capEachWord, blocks} -body {
    textutil::capEachWord {here \comes the $sun}
} -result {Here \comes The $sun}

# -------------------------------------------------------------------------

test textutil-8.0 {wcswidth} -body {
   textutil::wcswidth {The Quick Brown Fox}
} -result 19

test textutil-8.1 {wcswidth} -body {
   textutil::wcswidth {道德經}
} -result 6

test textutil-8.2 {wcswidth} -body {
   textutil::wcswidth {道德經 of the fox}
} -result 17
# -------------------------------------------------------------------------
testsuiteCleanup
return
