1#  Copyright 2021 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{
32  classes:
33      "every_dot_star" expression => every(".*", test);
34      "every_dot" expression => every(".", test);
35      "every_number" expression => every("[0-9]", test);
36
37      "every2_dot_star" expression => every(".*", test2);
38      "every2_dot" expression => every(".", test2);
39      "every2_number" expression => every("[0-9]", test2);
40
41  vars:
42      "test" slist => {
43                        1,2,3,
44                        "one", "two", "three",
45                        "long string",
46                        "four", "fix", "six",
47                        "one", "two", "three",
48      };
49
50      "test2" data => parsejson('[1,2,3,
51                        "one", "two", "three",
52                        "long string",
53                        "four", "fix", "six",
54                        "one", "two", "three",]');
55
56  reports:
57      "The test list is $(test)";
58
59    every_dot_star::
60      "every() test passed: every element matches '.*'";
61    !every_dot_star::
62      "every() test failed: not every element matches '.*'";
63    every_number::
64      "every() test failed: every element matches '[0-9]'";
65    !every_number::
66      "every() test passed: not every element matches '[0-9]'";
67    every_dot::
68      "every() test failed: every element matches '.'";
69    !every_dot::
70      "every() test passed: not every element matches '.'";
71
72      "The test2 list is $(test2)";
73    every2_dot_star::
74      "every() test2 passed: every element matches '.*'";
75    !every2_dot_star::
76      "every() test2 failed: not every element matches '.*'";
77    every2_number::
78      "every() test2 failed: every element matches '[0-9]'";
79    !every2_number::
80      "every() test2 passed: not every element matches '[0-9]'";
81    every2_dot::
82      "every() test2 failed: every element matches '.'";
83    !every2_dot::
84      "every() test2 passed: not every element matches '.'";
85}
86#+end_src
87###############################################################################
88#+begin_src example_output
89#@ ```
90#@ R: The test list is 1
91#@ R: The test list is 2
92#@ R: The test list is 3
93#@ R: The test list is one
94#@ R: The test list is two
95#@ R: The test list is three
96#@ R: The test list is long string
97#@ R: The test list is four
98#@ R: The test list is fix
99#@ R: The test list is six
100#@ R: every() test passed: every element matches '.*'
101#@ R: every() test passed: not every element matches '[0-9]'
102#@ R: every() test passed: not every element matches '.'
103#@ R: The test2 list is 1
104#@ R: The test2 list is 2
105#@ R: The test2 list is 3
106#@ R: The test2 list is one
107#@ R: The test2 list is two
108#@ R: The test2 list is three
109#@ R: The test2 list is long string
110#@ R: The test2 list is four
111#@ R: The test2 list is fix
112#@ R: The test2 list is six
113#@ R: every() test2 passed: every element matches '.*'
114#@ R: every() test2 passed: not every element matches '[0-9]'
115#@ R: every() test2 passed: not every element matches '.'
116#@ ```
117#+end_src
118