1# -*- tcl -*- 2# adjust.test: tests for the adjust sub-package of the textutil package. 3# 4# This file contains a collection of tests for one or more of the Tcl 5# built-in commands. Sourcing this file into Tcl runs the tests and 6# generates output for errors. No output means no errors were found. 7# 8 9# ------------------------------------------------------------------------- 10 11source [file join \ 12 [file dirname [file dirname [file join [pwd] [info script]]]] \ 13 devtools testutilities.tcl] 14 15testsNeedTcl 8.2 16testsNeedTcltest 1.0 17 18support { 19 useLocal repeat.tcl textutil::repeat 20 useLocal string.tcl textutil::string 21} 22testing { 23 useLocal adjust.tcl textutil::adjust 24} 25 26# ------------------------------------------------------------------------- 27 28set string " hello, world " 29 30set text "Hello, world! 31 This is the end, my friend. 32 33You're just another brick in the wall. 34 Michele, ma belle, sont des mots qui vont tr�s bien ensembles, 35tr�s bien ensembles. 36 37 Smoke on the water, and fire in the sky. 38 Oh Lord, don't let me be misunderstood. 39 40Cause tramp like us, baby we were born to run." 41 42set text2 "Hello, world! 43 This is the end, my friend. 44 45You're just another brick in the wall. 46 Michele, ma belle, sont des mots qui vont tr�s bien ensembles, 47tr�s bien ensembles. 48 49ThisIsSimilarToTextOnlyThisStringHasOneReallyLongWordInIt 50 51 Smoke on the water, and fire in the sky. 52 Oh Lord, don't let me be misunderstood. 53 54Cause tramp like us, baby we were born to run." 55 56################################################### 57 58test adjust-0.1 {adjust string on left} { 59 ::textutil::adjust::adjust $string 60} \ 61"hello, world" 62 63test adjust-0.2 {adjust string on rigth} { 64 ::textutil::adjust::adjust $string -justify right 65} \ 66" hello, world" 67 68test adjust-0.3 {adjust string on center} { 69 ::textutil::adjust::adjust $string -justify center 70} \ 71" hello, world" 72 73test adjust-0.4 {adjust string with plain justification} { 74 ::textutil::adjust::adjust $string -justify plain -full no 75} \ 76"hello, world" 77 78test adjust-0.5 {adjust string on left with full line} { 79 ::textutil::adjust::adjust $string -full yes 80} \ 81"hello, world " 82 83test adjust-0.6 {adjust string on right with full line} { 84 ::textutil::adjust::adjust $string -justify right -full yes 85} \ 86" hello, world " 87 88test adjust-0.7 {adjust string on center with full line} { 89 ::textutil::adjust::adjust $string -justify center -full 1 90} \ 91" hello, world " 92 93test adjust-0.8 {adjust string with plain justification and full line} { 94 ::textutil::adjust::adjust $string -justify plain -full YES 95} \ 96"hello, world " 97 98############################## 99 100test adjust-1.1 {adjust multi lines on left} { 101 ::textutil::adjust::adjust $text -full no 102} \ 103"Hello, world! This is the end, my friend. You're just another brick in 104the wall. Michele, ma belle, sont des mots qui vont tr�s bien ensembles, 105tr�s bien ensembles. Smoke on the water, and fire in the sky. Oh Lord, 106don't let me be misunderstood. Cause tramp like us, baby we were born to 107run." 108 109test adjust-1.2 {adjust multi lines on right} { 110 ::textutil::adjust::adjust $text -justify right 111} \ 112" Hello, world! This is the end, my friend. You're just another brick in 113the wall. Michele, ma belle, sont des mots qui vont tr�s bien ensembles, 114 tr�s bien ensembles. Smoke on the water, and fire in the sky. Oh Lord, 115don't let me be misunderstood. Cause tramp like us, baby we were born to 116 run." 117 118test adjust-1.3 {adjust multi lines on center} { 119 ::textutil::adjust::adjust $text -justify center -full yes 120} \ 121"Hello, world! This is the end, my friend. You're just 122 another brick in the wall. Michele, ma belle, sont des mots 123 qui vont tr�s bien ensembles, tr�s bien ensembles. Smoke on the 124water, and fire in the sky. Oh Lord, don't let me be misunderstood. 125 Cause tramp like us, baby we were born to run. " 126 127test adjust-1.4 {adjust multi lines with plain justification} { 128 ::textutil::adjust::adjust $text -justify plain -full yes 129} \ 130"Hello, world! This is the end, my friend. You're just 131another brick in the wall. Michele, ma belle, sont des mots 132qui vont tr�s bien ensembles, tr�s bien ensembles. Smoke on the 133water, and fire in the sky. Oh Lord, don't let me be misunderstood. 134Cause tramp like us, baby we were born to run. " 135 136test adjust-1.5 {adjust multi lines with plain justification} { 137 ::textutil::adjust::adjust $text -justify plain 138} \ 139"Hello, world! This is the end, my friend. You're just another brick in 140the wall. Michele, ma belle, sont des mots qui vont tr�s bien ensembles, 141tr�s bien ensembles. Smoke on the water, and fire in the sky. Oh Lord, 142don't let me be misunderstood. Cause tramp like us, baby we were born to 143run." 144 145############################## 146 147test adjust-2.1 {adjust multi lines on left with specified length} { 148 ::textutil::adjust::adjust $text -justify left -length 62 149} \ 150"Hello, world! This is the end, my friend. You're just another 151brick in the wall. Michele, ma belle, sont des mots qui vont 152tr�s bien ensembles, tr�s bien ensembles. Smoke on the water, 153and fire in the sky. Oh Lord, don't let me be misunderstood. 154Cause tramp like us, baby we were born to run." 155 156test adjust-2.2 {adjust multi lines on right with specified length} { 157 ::textutil::adjust::adjust $text -justify right -length 62 158} \ 159" Hello, world! This is the end, my friend. You're just another 160 brick in the wall. Michele, ma belle, sont des mots qui vont 161 tr�s bien ensembles, tr�s bien ensembles. Smoke on the water, 162 and fire in the sky. Oh Lord, don't let me be misunderstood. 163 Cause tramp like us, baby we were born to run." 164 165test adjust-2.3 {adjust multi lines on center with specified length} { 166 ::textutil::adjust::adjust $text -justify center -length 62 -full yes 167} \ 168" Hello, world! This is the end, my friend. 169 You're just another brick in the wall. Michele, 170 ma belle, sont des mots qui vont tr�s bien ensembles, tr�s 171bien ensembles. Smoke on the water, and fire in the sky. 172 Oh Lord, don't let me be misunderstood. Cause tramp like us, 173 baby we were born to run. " 174 175test adjust-2.4 {adjust multi lines with plain justification} { 176 ::textutil::adjust::adjust $text -justify plain -length 62 -full yes 177} \ 178"Hello, world! This is the end, my friend. 179You're just another brick in the wall. Michele, 180ma belle, sont des mots qui vont tr�s bien ensembles, tr�s 181bien ensembles. Smoke on the water, and fire in the sky. 182Oh Lord, don't let me be misunderstood. Cause tramp like us, 183baby we were born to run. " 184 185test adjust-2.5 {adjust multi lines with plain justification} { 186 ::textutil::adjust::adjust $text -justify plain -length 62 187} \ 188"Hello, world! This is the end, my friend. You're just another 189brick in the wall. Michele, ma belle, sont des mots qui vont 190tr�s bien ensembles, tr�s bien ensembles. Smoke on the water, 191and fire in the sky. Oh Lord, don't let me be misunderstood. 192Cause tramp like us, baby we were born to run." 193 194test adjust-2.6 {adjust multi lines with plain justification and long word} { 195 ::textutil::adjust::adjust $text2 -justify plain -length 31 -strictlength 1 196} \ 197"Hello, world! This is the end, 198my friend. You're just another 199brick in the wall. Michele, ma 200belle, sont des mots qui vont 201tr�s bien ensembles, tr�s bien 202ensembles. 203ThisIsSimilarToTextOnlyThisStrin 204gHasOneReallyLongWordInIt Smoke 205on the water, and fire in the 206sky. Oh Lord, don't let me be 207misunderstood. Cause tramp like 208us, baby we were born to run." 209 210test adjust-2.7 {adjust multi lines with plain justification and strictlength} { 211 ::textutil::adjust::adjust $text2 -justify plain -length 31 -strictlength 1 212} \ 213"Hello, world! This is the end, 214my friend. You're just another 215brick in the wall. Michele, ma 216belle, sont des mots qui vont 217tr�s bien ensembles, tr�s bien 218ensembles. 219ThisIsSimilarToTextOnlyThisStrin 220gHasOneReallyLongWordInIt Smoke 221on the water, and fire in the 222sky. Oh Lord, don't let me be 223misunderstood. Cause tramp like 224us, baby we were born to run." 225 226test adjust-2.8 {adjust multi lines with left justification and strictlength} { 227 ::textutil::adjust::adjust $text2 -justify left -length 31 -strictlength 1 228} \ 229"Hello, world! This is the end, 230my friend. You're just another 231brick in the wall. Michele, ma 232belle, sont des mots qui vont 233tr�s bien ensembles, tr�s bien 234ensembles. 235ThisIsSimilarToTextOnlyThisStrin 236gHasOneReallyLongWordInIt Smoke 237on the water, and fire in the 238sky. Oh Lord, don't let me be 239misunderstood. Cause tramp like 240us, baby we were born to run." 241 242################################################### 243 244unset string 245unset text 246unset text2 247 248################################################### 249# Indentation 250 251test indent-1.0 {indent spaces, no skip} { 252 ::textutil::adjust::indent {foo 253bar 254 255bob} { } 256} { foo 257 bar 258 259 bob} 260 261test indent-1.1 {indent spaces, negative skip} { 262 ::textutil::adjust::indent {foo 263bar 264 265bob} { } -4 266} { foo 267 bar 268 269 bob} 270 271test indent-1.2 {indent spaces, skip one} { 272 ::textutil::adjust::indent {foo 273bar 274 275bob} { } 1 276} {foo 277 bar 278 279 bob} 280 281test indent-1.3 {indent spaces, skip three} { 282 ::textutil::adjust::indent {foo 283bar 284 285bob} { } 3 286} {foo 287bar 288 289 bob} 290 291test indent-1.4 {indent spaces, skip all} { 292 ::textutil::adjust::indent {foo 293bar 294 295bob} { } 5 296} {foo 297bar 298 299bob} 300 301test indent-1.5 {indent spaces, skip all, on border} { 302 ::textutil::adjust::indent {foo 303bar 304 305bob} { } 4 306} {foo 307bar 308 309bob} 310 311test indent-1.6 {indent text with leading spaces} { 312 ::textutil::adjust::indent { foo 313 bar 314 315 bob} { } 0 316} { foo 317 bar 318 319 bob} 320 321test indent-1.7 {indent text with leading spaces, removal of traling spaces} { 322 ::textutil::adjust::indent { foo 323 bar 324 325 bob } { } 0 326} { foo 327 bar 328 329 bob} 330 331test undent-1.0 {undent, empty line, completely empty} { 332 ::textutil::adjust::undent { foo 333 bar 334 335 bob} 336} {foo 337bar 338 339bob} 340 341test undent-1.1 {undent, empty line, whitespace} { 342 ::textutil::adjust::undent { foo 343 bar 344 345 bob} 346} {foo 347bar 348 349bob} 350 351test undent-1.2 {undent, ignore common non-whitespace prefix} { 352 ::textutil::adjust::undent { foo 353 foobar 354 foobob} 355} {foo 356foobar 357foobob} 358 359test undent-1.3 {undent, ignore common non-whitespace part of prefix} { 360 ::textutil::adjust::undent { foo 361 foo bar 362 foo bob} 363} {foo 364foo bar 365foo bob} 366 367 368testsuiteCleanup 369