self-check-unindent.tap 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Sanity check for the automake testsuite.
  17. # Check the 'unindent' subroutine.
  18. . test-init.sh
  19. plan_ 22
  20. #------------------------------------------------------------------
  21. will_test () { tst=$*; }
  22. do_check ()
  23. {
  24. command_ok_ "$tst [simple, exit status]" \
  25. eval 'unindent input > got'
  26. command_ok_ "$tst [simple, output]" \
  27. diff exp got
  28. command_ok_ "$tst [parallel, exit status]" \
  29. eval 'unindent input | unindent > got'
  30. command_ok_ "$tst [parallel, output]" \
  31. diff exp got
  32. }
  33. #------------------------------------------------------------------
  34. will_test 'leading spaces'
  35. cat > input <<END
  36. 1
  37. 2
  38. 3
  39. 4
  40. ${tab}5
  41. ${tab} 6
  42. 6${sp}
  43. 7${sp}
  44. 8${sp}${sp}
  45. 9${sp}${sp}
  46. 10${tab}
  47. 11${tab}
  48. 12${sp}${tab}
  49. 13${sp}${tab}
  50. 14 this${tab}with${tab}multiple fields${sp}
  51. 15 and ${tab}${tab}this too${tab}
  52. 16 and also this
  53. ${sp}${sp}
  54. ${sp}
  55. ${tab}
  56. last line
  57. END
  58. cat > exp <<END
  59. 1
  60. 2
  61. 3
  62. 4
  63. ${tab}5
  64. ${tab} 6
  65. 6${sp}
  66. 7${sp}
  67. 8${sp}${sp}
  68. 9${sp}${sp}
  69. 10${tab}
  70. 11${tab}
  71. 12${sp}${tab}
  72. 13${sp}${tab}
  73. 14 this${tab}with${tab}multiple fields${sp}
  74. 15 and ${tab}${tab}this too${tab}
  75. 16 and also this
  76. ${sp}
  77. ${tab}
  78. last line
  79. END
  80. do_check
  81. #------------------------------------------------------------------
  82. will_test 'leading tab'
  83. cat > input <<END
  84. ${tab}1
  85. ${tab} 2
  86. 3
  87. 4
  88. 5
  89. 6
  90. 7
  91. ${tab}8
  92. ${tab}${tab}9
  93. ${tab}10${tab}
  94. ${tab}11${sp}
  95. 12${tab}
  96. 13${sp}
  97. ${tab}14 this with${tab}multiple fields${sp}
  98. 15 and ${tab}${tab}this too${tab}
  99. 16 and also this
  100. ${tab}
  101. ${sp}
  102. ${sp}${tab}
  103. last line
  104. END
  105. cat > exp <<END
  106. 1
  107. 2
  108. 3
  109. 4
  110. 5
  111. 6
  112. 7
  113. ${tab}8
  114. ${tab}9
  115. 10${tab}
  116. 11${sp}
  117. 12${tab}
  118. 13${sp}
  119. 14 this with${tab}multiple fields${sp}
  120. 15 and ${tab}${tab}this too${tab}
  121. 16 and also this
  122. ${sp}
  123. ${sp}${tab}
  124. last line
  125. END
  126. do_check "leading tab"
  127. #------------------------------------------------------------------
  128. will_test 'no leading whitespace'
  129. cat > input <<END
  130. 1
  131. 2
  132. 3
  133. 4
  134. ${tab}5
  135. ${tab} 6
  136. ${tab}7
  137. ${tab}${tab}8
  138. 9${sp}
  139. 10${tab}
  140. ${tab}10${sp}${sp}
  141. 14 this with${tab}multiple fields${sp}
  142. 15 and this too${tab}
  143. ${tab}16 and also this
  144. ${tab}
  145. ${sp}
  146. last line
  147. END
  148. cp input exp
  149. do_check
  150. #------------------------------------------------------------------
  151. will_test 'leading empty lines ignored (1)'
  152. cat > input <<END
  153. foo
  154. bar
  155. quux
  156. END
  157. cat > exp <<END
  158. foo
  159. bar
  160. quux
  161. END
  162. do_check
  163. #------------------------------------------------------------------
  164. will_test 'leading empty lines ignored (2)'
  165. cat > input <<END
  166. foo
  167. bar
  168. quux
  169. END
  170. cat > exp <<END
  171. foo
  172. bar
  173. quux
  174. END
  175. do_check
  176. #------------------------------------------------------------------
  177. will_test 'more elaborated parallel use'
  178. cat > input <<END
  179. x
  180. ${tab}y
  181. z
  182. ${tab}a
  183. ${tab} b
  184. ${tab}c
  185. ${tab}d
  186. ${tab}e
  187. ${tab}${tab}f
  188. END
  189. cat > exp <<END
  190. y
  191. z
  192. a
  193. b
  194. c
  195. ${tab}d
  196. ${tab}e
  197. ${tab}f
  198. END
  199. command_ok_ "$tst [exit status]" \
  200. eval 'unindent input | sed 1d | unindent > got'
  201. command_ok_ "$tst [output]" diff exp got
  202. :