"Fossies" - the Fresh Open Source Software Archive

Member "argbash-2.10.0/tests/unittests/check-list.m4" (22 Sep 2020, 3383 Bytes) of package /linux/privat/argbash-2.10.0.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "check-list.m4": 2.9.0_vs_2.10.0.

    1 m4_include([utilities.m4])
    2 m4_include_once([test-support.m4])
    3 
    4 dnl If BOMB gets expanded, we will be noticed.
    5 assert_equals(m4_quote(m4_list_contents([lol])), [])
    6 assert_equals(m4_quote(m4_list_nth([lol], , x)), [x])
    7 assert_equals(m4_quote(m4_list_indices([lol], [lala])), [])
    8 m4_list_declare([FOO])
    9 assert_equals(m4_list_len([FOO]), 0)
   10 assert_equals(m4_list_len([NOLIST]), 0)
   11 assert_equals(m4_quote(m4_argn(1, m4_list_foreach([FOO], [item], [-item-,]))), [])
   12 m4_list_ifempty([FOO], ,[m4_fatal([The list is supposed to be empty now])])
   13 m4_list_append([FOO], [BOMB])
   14 m4_list_ifempty([FOO], [m4_fatal([The list is supposed to be non-empty now])],)
   15 assert_equals(m4_list_len([FOO]), 1)
   16 m4_list_append([FOO], [ANTIFUSE(list)])
   17 m4_list_append([FOO], [BOMB], [BAZ])
   18 assert_equals(m4_quote(m4_list_nth([FOO], 9, x)), [x])
   19 assert_equals(m4_list_nth([FOO], 4), [BAZ])
   20 assert_equals(m4_list_nth([FOO], m4_list_indices([FOO], [BAZ])), [BAZ])
   21 assert_equals(m4_list_join([FOO], -), [BOMB-ANTIFUSE(list)-BOMB-BAZ])
   22 assert_equals(m4_list_join([FOO], -, ", ', [ and ]), ["BOMB'-"ANTIFUSE(list)'-"BOMB' and "BAZ'])
   23 assert_equals(m4_expand([m4_list_join([FOO], [,], ", ', [ , ])]), ["BOMB',"ANTIFUSE(list)',"BOMB' , "BAZ'])
   24 
   25 assert_equals(m4_list_format_sequence([FOO], [ and ]), ['BOMB', 'ANTIFUSE(list)', 'BOMB' and 'BAZ'])
   26 assert_equals(m4_list_format_sequence([FOO]), ['BOMB', 'ANTIFUSE(list)', 'BOMB', 'BAZ'])
   27 assert_equals(m4_list_format_sequence([FOO], [ and ], ", [ , ]), ["BOMB" , "ANTIFUSE(list)" , "BOMB" and "BAZ"])
   28 
   29 m4_list_append([FOO], [BAZ2])
   30 assert_equals(m4_list_len([FOO]), 5)
   31 
   32 dnl Try a simple sum
   33 m4_list_append([nums], [1])
   34 m4_list_append([nums], [8])
   35 m4_list_append([nums],[-5])
   36 m4_list_append([nums],[12])
   37 m4_list_append([nums], [0])
   38 dnl Sum is ........ 16
   39 assert_equals(m4_list_sum([nums]), 16)
   40 
   41 m4_ifnblank(m4_expand([m4_list_append([FOO], [])m4_list_append([FOO], [--LALA])]),
   42 	[m4_fatal([Leaking text in m4_list_append])])
   43 assert_equals(m4_list_nth([FOO], 1), [BOMB])
   44 m4_ifnblank(
   45 	m4_list_nth([FOO], 6),
   46 	[m4_fatal([Item ]m4_list_nth([FOO], 5)[ is not blank.])])
   47 assert_equals(m4_list_nth([FOO], 7), [--LALA])
   48 dnl The list items should be single-quoted only, so passing them to m4_expand should expand them.
   49 m4_expand(m4_list_nth([FOO], 2))
   50 ANTIBOMB([list])
   51 assert_equals(m4_quote(m4_argn(1, m4_list_foreach([FOO], [item], [-item-,]))), [-BOMB-])
   52 assert_equals(m4_quote(m4_argn(1, m4_lists_foreach([FOO,FOO], [item,item2], [-item-item2-,]))), [-BOMB-BOMB-])
   53 assert_equals(m4_list_len([FOO]), 7)
   54 assert_equals(m4_quote(m4_list_indices([FOO], [BOMB])), [1,3])
   55 assert_equals(m4_quote(m4_list_indices([FOO], [BAZ])), 4)
   56 assert_equals(m4_quote(m4_list_indices([FOO], [BAM])), [])
   57 assert_equals(m4_quote(m4_list_pop_front([FOO])), [BOMB])
   58 assert_equals(m4_quote(m4_list_indices([FOO], [BOMB])), [2])
   59 assert_equals(m4_quote(m4_list_contains([FOO], [BOMB], 3, 4)), [3])
   60 assert_equals(m4_quote(m4_list_contains([FOO], [lalala], 3, 4)), [4])
   61 assert_equals(m4_list_len([FOO]), 6)
   62 assert_equals(m4_quote(m4_list_pop_back([FOO])), [--LALA])
   63 assert_equals(m4_list_len([FOO]), 5)
   64 dnl After pop
   65 assert_equals(m4_list_nth([FOO], 2), [BOMB])
   66 
   67 m4_list_append([EMPTY], [])
   68 m4_list_append([EMPTY], [second])
   69 
   70 assert_equals(m4_list_nth([EMPTY], 1), [])
   71 assert_equals(m4_list_nth([EMPTY], 2), [second])
   72 assert_equals(m4_list_len([EMPTY]), 2)
   73 m4_ignore([
   74 m4_divert_push(0)dnl
   75 ])
   76 ]) dnl m4_ignore