Home | History | Annotate | Line # | Download | only in awk
t_awk.sh revision 1.1
      1  1.1  christos # $NetBSD: t_awk.sh,v 1.1 2012/03/10 19:08:56 christos Exp $
      2  1.1  christos #
      3  1.1  christos # Copyright (c) 2012 The NetBSD Foundation, Inc.
      4  1.1  christos # All rights reserved.
      5  1.1  christos #
      6  1.1  christos # This code is derived from software contributed to The NetBSD Foundation
      7  1.1  christos # by Christos Zoulas
      8  1.1  christos #
      9  1.1  christos # Redistribution and use in source and binary forms, with or without
     10  1.1  christos # modification, are permitted provided that the following conditions
     11  1.1  christos # are met:
     12  1.1  christos # 1. Redistributions of source code must retain the above copyright
     13  1.1  christos #    notice, this list of conditions and the following disclaimer.
     14  1.1  christos # 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  christos #    notice, this list of conditions and the following disclaimer in the
     16  1.1  christos #    documentation and/or other materials provided with the distribution.
     17  1.1  christos #
     18  1.1  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.1  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.1  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.1  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.1  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.1  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.1  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.1  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.1  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.1  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.1  christos # POSSIBILITY OF SUCH DAMAGE.
     29  1.1  christos #
     30  1.1  christos 
     31  1.1  christos awk=awk
     32  1.1  christos 
     33  1.1  christos atf_test_case single_char_rs
     34  1.1  christos 
     35  1.1  christos single_char_rs_head() {
     36  1.1  christos 	atf_set "descr" "Test awk(1) with single character RS"
     37  1.1  christos }
     38  1.1  christos 
     39  1.1  christos single_char_rs_body() {
     40  1.1  christos 	atf_check \
     41  1.1  christos 		-o "inline:1\n2\n\n3\n\n\n4\n\n" \
     42  1.1  christos 		-x "echo 1a2aa3aaa4 | $awk 1 RS=a"
     43  1.1  christos }
     44  1.1  christos 
     45  1.1  christos atf_test_case two_char_rs
     46  1.1  christos 
     47  1.1  christos two_char_rs_head() {
     48  1.1  christos 	atf_set "descr" "Test awk(1) with two characters RS"
     49  1.1  christos }
     50  1.1  christos 
     51  1.1  christos two_char_rs_body() {
     52  1.1  christos 	atf_check \
     53  1.1  christos 		-o "inline:1\n2\n3\n4\n\n" \
     54  1.1  christos 		-x "echo 1ab2ab3ab4 | $awk 1 RS=ab"
     55  1.1  christos }
     56  1.1  christos 
     57  1.1  christos atf_test_case single_char_regex_group_rs
     58  1.1  christos 
     59  1.1  christos single_char_regex_group_rs_head() {
     60  1.1  christos 	atf_set "descr" "Test awk(1) with single character regex group RS"
     61  1.1  christos }
     62  1.1  christos 
     63  1.1  christos single_char_regex_group_rs_body() {
     64  1.1  christos 	atf_check \
     65  1.1  christos 		-o "inline:1\n2\n\n3\n\n\n4\n\n" \
     66  1.1  christos 		-x "echo 1a2aa3aaa4 | $awk 1 RS='[a]'"
     67  1.1  christos }
     68  1.1  christos 
     69  1.1  christos atf_test_case two_char_regex_group_rs
     70  1.1  christos 
     71  1.1  christos two_char_regex_group_rs_head() {
     72  1.1  christos 	atf_set "descr" "Test awk(1) with two characters regex group RS"
     73  1.1  christos }
     74  1.1  christos 
     75  1.1  christos two_char_regex_group_rs_body() {
     76  1.1  christos 	atf_check \
     77  1.1  christos 		-o "inline:1\n2\n\n3\n\n\n4\n\n" \
     78  1.1  christos 		-x "echo 1a2ab3aba4 | $awk 1 RS='[ab]'"
     79  1.1  christos }
     80  1.1  christos 
     81  1.1  christos atf_test_case single_char_regex_star_rs
     82  1.1  christos 
     83  1.1  christos single_char_regex_star_rs_head() {
     84  1.1  christos 	atf_set "descr" "Test awk(1) with single character regex star RS"
     85  1.1  christos }
     86  1.1  christos 
     87  1.1  christos single_char_regex_star_rs_body() {
     88  1.1  christos 	atf_check \
     89  1.1  christos 		-o "inline:1\n2\n3\n4\n\n" \
     90  1.1  christos 		-x "echo 1a2aa3aaa4 | $awk 1 RS='a*'"
     91  1.1  christos }
     92  1.1  christos 
     93  1.1  christos atf_test_case two_char_regex_star_rs
     94  1.1  christos 
     95  1.1  christos two_char_regex_star_rs_head() {
     96  1.1  christos 	atf_set "descr" "Test awk(1) with two characters regex star RS"
     97  1.1  christos }
     98  1.1  christos 
     99  1.1  christos two_char_regex_star_rs_body() {
    100  1.1  christos 	atf_check \
    101  1.1  christos 		-o "inline:1\n2\n3\n4\n\n" \
    102  1.1  christos 		-x "echo 1a2aa3aaa4 | $awk 1 RS='aa*'"
    103  1.1  christos }
    104  1.1  christos 
    105  1.1  christos atf_test_case regex_two_star_rs
    106  1.1  christos 
    107  1.1  christos regex_two_star_rs_head() {
    108  1.1  christos 	atf_set "descr" "Test awk(1) with regex two star RS"
    109  1.1  christos }
    110  1.1  christos 
    111  1.1  christos regex_two_star_rs_body() {
    112  1.1  christos 	atf_check \
    113  1.1  christos 		-o "inline:1\n2\n3\n4\n\n" \
    114  1.1  christos 		-x "echo 1a2ab3aab4 | $awk 1 RS='aa*b*'"
    115  1.1  christos }
    116  1.1  christos 
    117  1.1  christos atf_test_case regex_or_1_rs
    118  1.1  christos 
    119  1.1  christos regex_or_1_rs_head() {
    120  1.1  christos 	atf_set "descr" "Test awk(1) with regex | case 1 RS"
    121  1.1  christos }
    122  1.1  christos 
    123  1.1  christos regex_or_1_rs_body() {
    124  1.1  christos 	atf_check \
    125  1.1  christos 		-o "inline:1a\nc\n\n" \
    126  1.1  christos 		-x "echo 1abc | $awk 1 RS='abcde|b'"
    127  1.1  christos }
    128  1.1  christos 
    129  1.1  christos atf_test_case regex_or_2_rs
    130  1.1  christos 
    131  1.1  christos regex_or_2_rs_head() {
    132  1.1  christos 	atf_set "descr" "Test awk(1) with regex | case 2 RS"
    133  1.1  christos }
    134  1.1  christos 
    135  1.1  christos regex_or_2_rs_body() {
    136  1.1  christos 	atf_check \
    137  1.1  christos 		-o "inline:1a\ncdf2\n\n" \
    138  1.1  christos 		-x "echo 1abcdf2 | $awk 1 RS='abcde|b'"
    139  1.1  christos }
    140  1.1  christos 
    141  1.1  christos atf_test_case regex_or_3_rs
    142  1.1  christos 
    143  1.1  christos regex_or_3_rs_head() {
    144  1.1  christos 	atf_set "descr" "Test awk(1) with regex | case 3 RS"
    145  1.1  christos }
    146  1.1  christos 
    147  1.1  christos regex_or_3_rs_body() {
    148  1.1  christos 	atf_check \
    149  1.1  christos 		-o "inline:1\n\nf2\n\n" \
    150  1.1  christos 		-x "echo 1abcdebf2 | $awk 1 RS='abcde|b'"
    151  1.1  christos }
    152  1.1  christos 
    153  1.1  christos atf_test_case regex_or_4_rs
    154  1.1  christos 
    155  1.1  christos regex_or_4_rs_head() {
    156  1.1  christos 	atf_set "descr" "Test awk(1) with regex | case 4 RS"
    157  1.1  christos }
    158  1.1  christos 
    159  1.1  christos regex_or_4_rs_body() {
    160  1.1  christos 	atf_check \
    161  1.1  christos 		-o "inline:1\nbcdf2\n\n" \
    162  1.1  christos 		-x "echo 1abcdf2 | $awk 1 RS='abcde|a'"
    163  1.1  christos 
    164  1.1  christos }
    165  1.1  christos 
    166  1.1  christos atf_test_case regex_caret_1_rs
    167  1.1  christos 
    168  1.1  christos regex_caret_1_rs_head() {
    169  1.1  christos 	atf_set "descr" "Test awk(1) with regex ^ case 1 RS"
    170  1.1  christos }
    171  1.1  christos 
    172  1.1  christos regex_caret_1_rs_body() {
    173  1.1  christos 	atf_check \
    174  1.1  christos 		-o "inline:\n1a2a3a\n\n" \
    175  1.1  christos 		-x "echo a1a2a3a | $awk 1 RS='^a'"
    176  1.1  christos 
    177  1.1  christos }
    178  1.1  christos 
    179  1.1  christos atf_test_case regex_caret_2_rs
    180  1.1  christos 
    181  1.1  christos regex_caret_2_rs_head() {
    182  1.1  christos 	atf_set "descr" "Test awk(1) with regex ^ case 2 RS"
    183  1.1  christos }
    184  1.1  christos 
    185  1.1  christos regex_caret_2_rs_body() {
    186  1.1  christos 	atf_check \
    187  1.1  christos 		-o "inline:\n1a2an\n" \
    188  1.1  christos 		-x "echo aaa1a2a | $awk 1 RS='^a'"
    189  1.1  christos 
    190  1.1  christos }
    191  1.1  christos 
    192  1.1  christos atf_test_case regex_dollar_1_rs
    193  1.1  christos 
    194  1.1  christos regex_dollar_1_rs_head() {
    195  1.1  christos 	atf_set "descr" "Test awk(1) with regex $ case 1 RS"
    196  1.1  christos }
    197  1.1  christos 
    198  1.1  christos regex_dollar_1_rs_body() {
    199  1.1  christos 	atf_check \
    200  1.1  christos 		-o "inline:a1a2a3a\n\n" \
    201  1.1  christos 		-x "echo a1a2a3a | $awk 1 RS='a$'"
    202  1.1  christos 
    203  1.1  christos }
    204  1.1  christos 
    205  1.1  christos atf_test_case regex_dollar_2_rs
    206  1.1  christos 
    207  1.1  christos regex_dollar_2_rs_head() {
    208  1.1  christos 	atf_set "descr" "Test awk(1) with regex $ case 2 RS"
    209  1.1  christos }
    210  1.1  christos 
    211  1.1  christos regex_dollar_2_rs_body() {
    212  1.1  christos 	atf_check \
    213  1.1  christos 		-o "inline:a1a2aaa\n" \
    214  1.1  christos 		-x "echo a1a2aaa | $awk 1 RS='a$'"
    215  1.1  christos 
    216  1.1  christos }
    217  1.1  christos 
    218  1.1  christos atf_test_case regex_reallocation_rs
    219  1.1  christos 
    220  1.1  christos regex_reallocation_rs_head() {
    221  1.1  christos 	atf_set "descr" "Test awk(1) with regex reallocation RS"
    222  1.1  christos }
    223  1.1  christos 
    224  1.1  christos regex_reallocation_rs_body() {
    225  1.1  christos 	atf_check \
    226  1.1  christos 		-o "inline:a\na\na\na\na\na\na\na\na\na10000\n\n" \
    227  1.1  christos 		-x "jot -s a 10000 | $awk 'NR>1' RS='999[0-9]'"
    228  1.1  christos 
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos atf_test_case empty_rs
    232  1.1  christos 
    233  1.1  christos empty_rs_head() {
    234  1.1  christos 	atf_set "descr" "Test awk(1) with empty RS"
    235  1.1  christos }
    236  1.1  christos 
    237  1.1  christos empty_rs_body() {
    238  1.1  christos 	atf_check \
    239  1.1  christos 		-o "inline:foo\n" \
    240  1.1  christos 		-x "echo foo | $awk RS=''"
    241  1.1  christos 
    242  1.1  christos }
    243  1.1  christos 
    244  1.1  christos atf_test_case newline_rs
    245  1.1  christos 
    246  1.1  christos newline_rs_head() {
    247  1.1  christos 	atf_set "descr" "Test awk(1) with newline RS"
    248  1.1  christos }
    249  1.1  christos 
    250  1.1  christos newline_rs_body() {
    251  1.1  christos 	atf_check \
    252  1.1  christos 		-o "inline:r1f1:r1f2\nr2f1:r2f2\n" \
    253  1.1  christos 		-x "printf '\n\n\nr1f1\nr1f2\n\nr2f1\nr2f2\n\n\n' | $awk '{$1=$1}1' RS= OFS=:"
    254  1.1  christos }
    255  1.1  christos 
    256  1.1  christos atf_init_test_cases() {
    257  1.1  christos 	atf_add_test_case single_char_rs
    258  1.1  christos 	atf_add_test_case two_char_rs
    259  1.1  christos 	atf_add_test_case single_char_regex_group_rs
    260  1.1  christos 	atf_add_test_case two_char_regex_group_rs
    261  1.1  christos 	atf_add_test_case two_char_regex_star_rs
    262  1.1  christos 	atf_add_test_case single_char_regex_star_rs
    263  1.1  christos 	atf_add_test_case regex_two_star_rs
    264  1.1  christos 	atf_add_test_case regex_or_1_rs
    265  1.1  christos 	atf_add_test_case regex_or_2_rs
    266  1.1  christos 	atf_add_test_case regex_or_3_rs
    267  1.1  christos 	atf_add_test_case regex_caret_1_rs
    268  1.1  christos 	atf_add_test_case regex_caret_2_rs
    269  1.1  christos 	atf_add_test_case regex_dollar_1_rs
    270  1.1  christos 	atf_add_test_case regex_dollar_2_rs
    271  1.1  christos 	atf_add_test_case regex_reallocation_rs
    272  1.1  christos 	atf_add_test_case empty_rs
    273  1.1  christos 	atf_add_test_case newline_rs
    274  1.1  christos }
    275