xref: /aosp_15_r20/external/toybox/tests/fmt.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
4*cf5a6c84SAndroid Build Coastguard Worker
5*cf5a6c84SAndroid Build Coastguard Workerecho "hello world " > en.txt
6*cf5a6c84SAndroid Build Coastguard Workerecho "this is some text    " >> en.txt
7*cf5a6c84SAndroid Build Coastguard Worker# https://en.wikipedia.org/wiki/Aegukga
8*cf5a6c84SAndroid Build Coastguard Workerecho "동해물과 백두산이 마르고 닳도록" > kr.txt
9*cf5a6c84SAndroid Build Coastguard Workerecho "하나님이 보우하사 우리나라 만세." >> kr.txt
10*cf5a6c84SAndroid Build Coastguard Worker
11*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
12*cf5a6c84SAndroid Build Coastguard Worker
13*cf5a6c84SAndroid Build Coastguard Workertesting "join" "fmt en.txt" "hello world this is some text\n" "" ""
14*cf5a6c84SAndroid Build Coastguard Workertesting "split" "fmt -w 10 en.txt" "hello\nworld\nthis is\nsome text\n" "" ""
15*cf5a6c84SAndroid Build Coastguard Workertesting "no room" "echo 'hello world' | fmt -w 1" "hello\nworld\n" "" ""
16*cf5a6c84SAndroid Build Coastguard Workertesting "blank line" "echo -e 'first paragraph of text\n\nand another' | fmt -w 10" "first\nparagraph\nof text\n\nand\nanother\n" "" ""
17*cf5a6c84SAndroid Build Coastguard Workertesting "ws-only line" "echo -e 'hello\n  \nworld' | fmt -w 10" "hello\n\nworld\n" "" ""
18*cf5a6c84SAndroid Build Coastguard Workertesting "leading space" "echo '  hello world' | fmt -w 5" "  hello\n  world\n" "" ""
19*cf5a6c84SAndroid Build Coastguard Workertesting "utf8" "fmt -w 10 kr.txt" "동해물과\n백두산이\n마르고\n닳도록\n하나님이\n보우하사\n우리나라\n만세.\n" "" ""
20*cf5a6c84SAndroid Build Coastguard Worker
21*cf5a6c84SAndroid Build Coastguard Workertesting "no newline" "fmt -w 10" "and\nthisisaverylongline\n" \
22*cf5a6c84SAndroid Build Coastguard Worker  "" "and thisisaverylongline"
23*cf5a6c84SAndroid Build Coastguard Workertesting "" "fmt -w 9" "1 2 3 4\n5 6 7 8\n9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
24*cf5a6c84SAndroid Build Coastguard Workertesting "" "fmt -w 10" "1 2 3 4 5\n6 7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
25*cf5a6c84SAndroid Build Coastguard Workertesting "" "fmt -w 11" "1 2 3 4 5\n6 7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
26*cf5a6c84SAndroid Build Coastguard Workertesting "" "fmt -w 12" "1 2 3 4 5 6\n7 8 9 0\n" "" "1 2 3 4 5 6 7 8 9 0\n"
27*cf5a6c84SAndroid Build Coastguard Worker
28*cf5a6c84SAndroid Build Coastguard Workertesting "matched tab indent" "fmt" "\thello world\n" "" "\thello\n\tworld"
29*cf5a6c84SAndroid Build Coastguard Worker# Version skew: debian is now emitting \t instead of "first line's indent"
30*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "matched tab/space" "fmt" '        hello world\n' "" \
31*cf5a6c84SAndroid Build Coastguard Worker  "        hello\n\tworld"
32*cf5a6c84SAndroid Build Coastguard Workertesting "matched space/tab" "fmt" "\thello world\n" ""  "\thello\n        world"
33*cf5a6c84SAndroid Build Coastguard Worker
34*cf5a6c84SAndroid Build Coastguard Workerrm en.txt kr.txt
35