1#!/bin/bash
2
3# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
5# Copyright 2013  Kyungwan.Han <asura321@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
13echo "one:two:three:four:five:six:seven
14alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
15the quick brown fox jumps over the lazy dog" >abc.txt
16
17testing "cut with -c (a-b)" "cut -c 4-10 abc.txt" ":two:th\nha:beta\n quick \n" "" ""
18testing "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
20testing "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
22testing "cut with echo, -c (a-b)" "echo 'ref_categorie=test' | cut -c 1-15 " "ref_categorie=t\n" "" ""
23testing "cut with echo, -c (a)" "echo 'ref_categorie=test' | cut -c 14" "=\n" "" ""
24
25# Modifying abc.txt data as per new testcase
26echo "abcdefghijklmnopqrstuvwxyz" >abc.txt
27
28testing "cut with -c (a,b,c)" "cut -c 4,5,20 abc.txt" "det\n" "" ""
29
30testing "cut with -b (a,b,c)" "cut -b 4,5,20 abc.txt" "det\n" "" ""
31
32# Modifying abc.txt data as per testcase
33echo "406378:Sales:Itorre:Jan
34031762:Marketing:Nasium:Jim
35636496:Research:Ancholie:Mel
36396082:Sales:Jucacion:Ed" >abc.txt
37
38testing "cut with -d -f(:) -s" "cut -d: -f3 -s abc.txt" "Itorre\nNasium\nAncholie\nJucacion\n" "" ""
39
40testing "cut with -d -f( ) -s" "cut -d' ' -f3 -s abc.txt && echo yes" "yes\n" "" ""
41
42testing "cut with -d -f(a) -s" "cut -da -f3 -s abc.txt" "n\nsium:Jim\n\ncion:Ed\n" "" ""
43
44testing "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
47rm abc.txt
48