1009
|
1 #!/bin/bash
|
|
2
|
|
3 #################################################################################################################
|
|
4 # cut.test #
|
|
5 # This script is part of toybox test suite, for cut command #
|
|
6 # #
|
|
7 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> and Divya Kothari <divya.s.kothari@gmail.com> #
|
|
8 # Copyright 2013 Kyungwan.Han <asura321@gmail.com> #
|
|
9 # How to run - ./script/test.sh cut #
|
|
10 #################################################################################################################
|
|
11
|
|
12 [ -f testing.sh ] && . testing.sh
|
|
13
|
|
14 #testing "name" "command" "result" "infile" "stdin"
|
|
15 #set -x
|
|
16
|
|
17 # Creating test file for testing cut
|
|
18 echo "one:two:three:four:five:six:seven
|
|
19 alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
|
|
20 the quick brown fox jumps over the lazy dog" >abc.txt
|
|
21
|
|
22 testing "cut with -c (a-b)" "cut -c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" ""
|
|
23 testing "cut with -f (a-)" "cut -d ':' -f 5- abc.txt" "five:six:seven\nepsilon:zeta:eta:teta:iota:kappa:lambda:mu\nthe quick brown fox jumps over the lazy dog\n" "" ""
|
|
24
|
|
25 testing "cut with -f (a)" "cut -d ' ' -f 3 abc.txt" "one:two:three:four:five:six:seven\nalpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu\nbrown\n" "" ""
|
|
26
|
|
27 testing "cut with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" ""
|
|
28 testing "cut with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" ""
|
|
29
|
|
30 # Modifying abc.txt data as per new testcase
|
|
31 echo "abcdefghijklmnopqrstuvwxyz" >abc.txt
|
|
32
|
|
33 testing "cut with -c (a,b,c)" "cut -c 4,5,20 abc.txt" "det\n" "" ""
|
|
34
|
|
35 testing "cut with -b (a,b,c)" "cut -b 4,5,20 abc.txt" "det\n" "" ""
|
|
36
|
|
37 # Modifying abc.txt data as per testcase
|
|
38 echo "406378:Sales:Itorre:Jan
|
|
39 031762:Marketing:Nasium:Jim
|
|
40 636496:Research:Ancholie:Mel
|
|
41 396082:Sales:Jucacion:Ed" >abc.txt
|
|
42
|
|
43 testing "cut with -d -f(:) -s" "cut -d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" ""
|
|
44
|
|
45 testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s abc.txt && echo yes" "yes\n" "" ""
|
|
46
|
|
47 testing "cut with -d -f(a) -s" "cut -da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
|
|
48
|
|
49 testing "cut with -d -f(a) -s -n" "cut -da -f3 -s -n abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
|
|
50
|
|
51 # Removing abc.txt file for cleanup purpose
|
|
52 rm abc.txt
|