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