1# -*- tcl -*- 2# tabify.test: tests for the tabify 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.5 16testsNeedTcltest 1.0 17 18support { 19 useLocal repeat.tcl textutil::repeat 20} 21testing { 22 useLocal tabify.tcl textutil::tabify 23} 24 25# ------------------------------------------------------------------------- 26 27test tabify-0.1 {tabify string} { 28 ::textutil::tabify::tabify " hello, world " 29} "\thello,\tworld\t" 30 31test tabify-0.2 {tabify string with 4 chars} { 32 ::textutil::tabify::tabify " hello, world " 4 33} "\t\thello,\t\tworld\t\t" 34 35test tabify-0.3 {tabify string with 5 chars} { 36 ::textutil::tabify::tabify " hello, world " 5 37} "\t hello,\t world\t " 38 39test tabify-1.1 {untabify string} { 40 ::textutil::tabify::untabify "\thello,\tworld\t" 41} " hello, world " 42 43test tabify-1.2 {untabify string with 4 chars} { 44 ::textutil::tabify::untabify "\t\thello,\t\tworld\t\t" 4 45} " hello, world " 46 47test tabify-1.3 {untabify string with 5 chars} { 48 ::textutil::tabify::untabify "\t hello,\t world\t " 5 49} " hello, world " 50 51# 52# Tests for version 2 of (un)tabify 53# 54 55# 56# tests 2.1 - 2.3: see how a single space (after 'hello') is not converted 57# to a tab 58# 59test tabify-2.1 {version 2: tabify, tab size 3} { 60 ::textutil::tabify::tabify2 "hello world" 3 61 # ---|||---|||-- 62} "hello \tworld" 63 64test tabify-2.2 {version 2: tabify, tab size 3, more spaces than needed} { 65 ::textutil::tabify::tabify2 "hello world" 3 66} "hello \t world" 67 68test tabify-2.3 {version 2: tabify, tab size 3, less spaces than needed} { 69 ::textutil::tabify::tabify2 "hello world" 3 70} "hello world" 71 72test tabify-2.4 {version 2: tabify, tab size 8} { 73 ::textutil::tabify::tabify2 "hello world" 74} "hello\tworld" 75 76test tabify-2.5 {version 2: tabify, tab size 8, more spaces than needed} { 77 ::textutil::tabify::tabify2 "hello world" 78} "hello\t world" 79 80test tabify-2.6 {version 2: tabify, tab size 8, less spaces than needed} { 81 ::textutil::tabify::tabify2 "hello world" 82} "hello world" 83 84# 85# tests 2.7 & 2.8: 'end of line' (\n or not) of last line is preserved 86# 87test tabify-2.7 {version 2: tabify, tab size 8, multi line} { 88 ::textutil::tabify::tabify2 "line 1 \n line 2\nline 3 \n line 4" 89} "line 1\t\n\tline 2\nline 3\t\n\tline 4" 90 91test tabify-2.8 {version 2: tabify, tab size 8, multi line} { 92 ::textutil::tabify::tabify2 "line 1 \n line 2\nline 3 \n line 4\n" 93} "line 1\t\n\tline 2\nline 3\t\n\tline 4\n" 94 95# Test handling of existing tabs ... 2.9 as test and 2.10 the 96# discrimator to check that it is correct if I use spaces 97# instead of a tab, to see that my understanding is basically correct. 98 99test tabify-2.9 {version 2: handling of existing tabs} { 100 ::textutil::tabify::tabify2 "hello\tworld bye" 101 # hello...world bye 102 # --------||||||||--- 103} "hello\tworld\tbye" 104 105test tabify-2.10 {version 2: handling of existing tabs} { 106 ::textutil::tabify::tabify2 "hello world bye" 107} "hello\tworld\tbye" 108 109 110# 111# untabify 112# 113test tabify-3.1 {version 2: untabify, tab size 3} { 114 ::textutil::tabify::untabify2 "hello \tworld" 3 115} "hello world" 116 117test tabify-3.2 {version 2: untabify, tab size 3, tab to single space} { 118 ::textutil::tabify::untabify2 "hello\t\tworld" 3 119} "hello world" 120 121# 122# The change in tab size from 3 to 8 (silently) results in building the 123# appropriate 'Spaces' strings (in 3.5 'Spaces(6)' is needed) 124# 125test tabify-3.3 {version 2: untabify, tab size 8} { 126 ::textutil::tabify::untabify2 "hello\tworld" 127} "hello world" 128 129test tabify-3.4 {version 2: untabify, tab size 8, mix of tab and spaces} { 130 ::textutil::tabify::untabify2 "hello \tworld" 131} "hello world" 132 133test tabify-3.5 {version 2: untabify, tab size 8, requires 'long' space string} { 134 ::textutil::tabify::untabify2 "hello\tmy\tworld" 135} "hello my world" 136 137 138# 139# tests 3.6 & 3.7: 'end of line' (\n or not) of last line is preserved 140# 141test tabify-3.6 {version 2: untabify, tab size 8, multi line} { 142 ::textutil::tabify::untabify2 "line 1\t\n\tline 2\nline 3\t\n\tline 4" 143} "line 1 \n line 2\nline 3 \n line 4" 144 145test tabify-3.7 {version 2: untabify, tab size 8, multi line} { 146 ::textutil::tabify::untabify2 "line 1\t\n\tline 2\nline 3\t\n\tline 4\n" 147} "line 1 \n line 2\nline 3 \n line 4\n" 148 149# 150# Edge cases: test for empty string 151# 152test tabify-4.1 {tabify empty string} { ::textutil::tabify::tabify "" } "" 153test tabify-4.2 {untabify empty string} { ::textutil::tabify::untabify "" } "" 154test tabify-4.3 {tabify2 empty string} { ::textutil::tabify::tabify2 "" } "" 155test tabify-4.4 {untabify2 empty string} { ::textutil::tabify::untabify2 "" } "" 156 157