1# Copyright 2020 Northern.tech AS 2 3# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 4 5# This program is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License as published by the 7# Free Software Foundation; version 3. 8 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 18# To the extent this program is licensed as part of the Enterprise 19# versions of Cfengine, the applicable Commercial Open Source License 20# (COSL) may apply to this file if you as a licensee so wish it. See 21# included file COSL.txt. 22 23#+begin_src cfengine3 24body common control 25{ 26 bundlesequence => { "test" }; 27} 28 29bundle agent test 30{ 31 vars: 32 "test" slist => { 33 1,2,3, 34 "one", "two", "three", 35 "long string", 36 "one", "two", "three", 37 }; 38 39 "test2" data => parsejson('[1,2,3, "ab", "c"]'); 40 41 "test_filtergrep" slist => filter("[0-9]", test, "true", "false", 999); 42 "test_exact1" slist => filter("one", test, "false", "false", 999); 43 "test_exact2" slist => filter(".", test, "false", "false", 999); 44 "test_invert" slist => filter("[0-9]", test, "true", "true", 999); 45 "test_max2" slist => filter(".*", test, "true", "false", 2); 46 "test_max0" slist => filter(".*", test, "true", "false", 0); 47 "test_grep" slist => grep("[0-9]", test); 48 49 "test2_filtergrep" slist => filter("[0-9]", test2, "true", "false", 999); 50 "test2_exact1" slist => filter("one", test2, "false", "false", 999); 51 "test2_exact2" slist => filter(".", test2, "false", "false", 999); 52 "test2_invert" slist => filter("[0-9]", test2, "true", "true", 999); 53 "test2_max2" slist => filter(".*", test2, "true", "false", 2); 54 "test2_max0" slist => filter(".*", test2, "true", "false", 0); 55 "test2_grep" slist => grep("[0-9]", test2); 56 57 "todo" slist => { "test", "test2", "test_filtergrep", "test_exact1", 58 "test_exact2", "test_invert", "test_max2", 59 "test_max0", "test_grep", "test2_filtergrep", 60 "test2_exact1", "test2_exact2", 61 "test2_invert", "test2_max2", "test2_max0", 62 "test2_grep"}; 63 64 "$(todo)_str" string => format("%S", $(todo)); 65 "tests" slist => { "test", "test2" }; 66 67 reports: 68 "The $(tests) list is $($(tests)_str)"; 69 "The grepped list (only single digits from $(tests)) is $($(tests)_grep_str)"; 70 "The filter-grepped list (only single digits from $(tests)) is $($(tests)_grep_str)"; 71 "The filter-exact list, looking for only 'one' in $(tests), is $($(tests)_exact1_str)"; 72 "This list should be empty, the '.' is not literally in the list $(tests): $($(tests)_exact2_str)"; 73 "The filter-invert list, looking for non-digits in $(tests), is $($(tests)_invert_str)"; 74 "The filter-bound list, matching at most 2 items from the whole list $(tests), is $($(tests)_max2_str)"; 75 "This list should be empty because 0 elements of $(tests) were requested: $($(tests)_max0_str)"; 76} 77#+end_src 78############################################################################### 79#+begin_src example_output 80#@ ``` 81#@ R: The test list is { "1", "2", "3", "one", "two", "three", "long string", "one", "two", "three" } 82#@ R: The test2 list is [1,2,3,"ab","c"] 83#@ R: The grepped list (only single digits from test) is { "1", "2", "3" } 84#@ R: The grepped list (only single digits from test2) is { "1", "2", "3" } 85#@ R: The filter-grepped list (only single digits from test) is { "1", "2", "3" } 86#@ R: The filter-grepped list (only single digits from test2) is { "1", "2", "3" } 87#@ R: The filter-exact list, looking for only 'one' in test, is { "one", "one" } 88#@ R: The filter-exact list, looking for only 'one' in test2, is { } 89#@ R: This list should be empty, the '.' is not literally in the list test: { } 90#@ R: This list should be empty, the '.' is not literally in the list test2: { } 91#@ R: The filter-invert list, looking for non-digits in test, is { "one", "two", "three", "long string", "one", "two", "three" } 92#@ R: The filter-invert list, looking for non-digits in test2, is { "ab", "c" } 93#@ R: The filter-bound list, matching at most 2 items from the whole list test, is { "1", "2" } 94#@ R: The filter-bound list, matching at most 2 items from the whole list test2, is { "1", "2" } 95#@ R: This list should be empty because 0 elements of test were requested: { } 96#@ R: This list should be empty because 0 elements of test2 were requested: { } 97#@ ``` 98#+end_src 99