expand.test 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # POSIX 2008 compliant expand tests.
  3. # Copyright 2012 by Jonathan Clairembault <jonathan@clairembault.fr>
  4. [ -f testing.sh ] && . testing.sh
  5. # some basic tests
  6. testing "default" "expand input" " foo bar\n" "\tfoo\tbar\n" ""
  7. testing "default stdin" "expand" " foo bar\n" "" "\tfoo\tbar\n"
  8. testing "single" "expand -t 2 input" " foo bar\n" "\tfoo\tbar\n" ""
  9. testing "tablist" "expand -t 5,10,12 input" " foo bar foo\n" "\tfoo\tbar\tfoo\n" ""
  10. testing "backspace" "expand input" "foobarfoo\b\b bar\n" "foobarfoo\b\b\tbar\n" ""
  11. # advanced tests
  12. POW=15
  13. TABSTOP=1
  14. BIGTAB=" "
  15. for i in $(seq $POW); do
  16. BIGTAB=$BIGTAB$BIGTAB
  17. TABSTOP=$(($TABSTOP*2))
  18. done
  19. testing "long tab single" "expand -t $TABSTOP input" "${BIGTAB}foo\n" "\tfoo\n" ""
  20. testing "long tab tablist" "expand -t $TABSTOP,$((TABSTOP+5)) input" \
  21. "${BIGTAB}foo bar\n" "\tfoo\tbar\n" ""
  22. testing "multiline single" "expand -t 4 input" "foo \n bar\n" "foo\t\n\tbar\n" ""
  23. testing "multiline tablist" "expand -t 4,8 input" \
  24. "foo bar\n bar foo\n" "foo\t\tbar\n\tbar\tfoo\n" ""
  25. POW=15
  26. BIGLINE="foo "
  27. for i in $(seq $POW); do
  28. BIGLINE=$BIGLINE$BIGLINE
  29. done
  30. if [ $POW -gt 0 ]; then
  31. EXPANDLINE="${BIGLINE} foo\n"
  32. else
  33. EXPANDLINE="${BIGLINE} foo\n"
  34. fi
  35. BIGLINE="${BIGLINE}\tfoo\n"
  36. testing "long line single" "expand input" \
  37. "${EXPANDLINE}" "$BIGLINE" ""