File: parsearray_maxlen.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (78 lines) | stat: -rw-r--r-- 2,261 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Test the parse\w+array(idx)? functions honour their maxlen parameter.
body common control
{
      inputs => { "../../default.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
}

bundle agent init
{
  vars:
      "float" string => "
1.0     4.0
2.0     1.0
3.0     1e1     # 36 bytes up to 1e1
4.0     2.0
5.0    16.0
6.0     3.0";
      "whole" string => "
1       4
2       1
3      10       # 30 bytes up to 10
4       2
5      16
6       3";
      "words" string => "
one     four
two     one
three   ten     # 37 bytes up to ten
four    two
five    sixteen
six     three";
}

bundle agent test
{
  vars:
      "flen" int => parserealarray("float", "$(init.float)", "\s*#[^\n]*", "\s+", 1000, 36);
      "ilen" int => parseintarray("whole", "$(init.whole)", "\s*#[^\n]*", "\s+", 1000, 30);
      "slen" int => parsestringarray("words", "$(init.words)", "\s*#[^\n]*", "\s+", 1000, 37);
      "tlen" int => parsestringarrayidx("texts", "$(init.words)", "\s*#[^\n]*", "\s+", 1000, 37);
}

bundle agent check
{
  vars:
      "arrays" slist => { "float", "whole", "words", "texts" };

      "key_$(arrays)" slist => getindices("test.$(arrays)");
      "sub_$(key_$(arrays))" slist => getindices("test.$(arrays)[$(key_$(arrays))]");

  classes:
      "okf" expression => strcmp("$(test.flen)", "3");
      "oki" expression => strcmp("$(test.ilen)", "3");
      "oks" expression => strcmp("$(test.slen)", "3");
      "okt" expression => strcmp("$(test.tlen)", "3");

      "ok" and => { "okf", "oki", "oks", "okt" };

  reports:
    DEBUG.!okf::
      "float: '$(test.flen)'";
      "float[$(key_float)][$(sub_$(key_float))] = $(test.float[$(key_float)][$(sub_$(key_float))])";
    DEBUG.!oki::
      "whole: '$(test.ilen)'";
      "whole[$(key_whole)][$(sub_$(key_whole))] = $(test.whole[$(key_whole)][$(sub_$(key_whole))])";
    DEBUG.!oks::
      "words: '$(test.slen)'";
      "words[$(key_words)][$(sub_$(key_words))] = $(test.words[$(key_words)][$(sub_$(key_words))])";
    DEBUG.!okt::
      "texts: '$(test.tlen)'";
      "texts[$(key_texts)][$(sub_$(key_texts))] = $(test.texts[$(key_texts)][$(sub_$(key_texts))])";

  reports:
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";
}