~ubuntu-branches/ubuntu/natty/augeas/natty

« back to all changes in this revision

Viewing changes to lenses/tests/test_shellvars_list.aug

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella (Canonical)
  • Date: 2010-06-25 16:12:45 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625161245-8pwq1gbejazeo07u
Tags: 0.7.2-1
* New upstream release
* Droped 50_iptables-lens.diff. Included upstream
* Updated libaugeas0.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* Test for shell list handling lens *)
 
2
module Test_shellvars_list =
 
3
 
 
4
  let list_vals = "# Some comment
 
5
MODULES_LOADED_ON_BOOT=\"ipv6 sunrpc\"
 
6
 
 
7
DEFAULT_APPEND=\"showopts noresume console=tty0 console=ttyS0,115200n8 ro\"
 
8
 
 
9
LOADER_TYPE=\"grub\"
 
10
"
 
11
 
 
12
  test Shellvars_list.lns get list_vals =
 
13
    { "#comment" = "Some comment" }
 
14
    { "MODULES_LOADED_ON_BOOT"
 
15
      { "quote" = "\"" }
 
16
      { "value" = "ipv6" }
 
17
      { "value" = "sunrpc" } }
 
18
    {  }
 
19
    { "DEFAULT_APPEND"
 
20
      { "quote" = "\"" }
 
21
      { "value" = "showopts" }
 
22
      { "value" = "noresume" }
 
23
      { "value" = "console=tty0" }
 
24
      { "value" = "console=ttyS0,115200n8" }
 
25
      { "value" = "ro" } }
 
26
    {  }
 
27
    { "LOADER_TYPE"
 
28
      { "quote" = "\"" }
 
29
      { "value" = "grub" } }
 
30
 
 
31
 
 
32
  (* append a value *)
 
33
  test Shellvars_list.lns put "VAR=\"test1\t  \ntest2\"\n" after
 
34
    set "VAR/value[last()+1]" "test3"
 
35
    = "VAR=\"test1\t  \ntest2 test3\"\n"
 
36
 
 
37
  (* in double quoted lists, single quotes and escaped values are allowed *)
 
38
  test Shellvars_list.lns get "VAR=\"test'1 test2 a\ \\\"longer\\\"\ test\"\n" =
 
39
    { "VAR"
 
40
      { "quote" = "\"" }
 
41
      { "value" = "test'1" }
 
42
      { "value" = "test2" }
 
43
      { "value" = "a\ \\\"longer\\\"\ test" } }
 
44
 
 
45
  (* add new value, delete one and append something *)
 
46
  test Shellvars_list.lns put list_vals after
 
47
    set "FAILSAVE_APPEND/quote" "\"" ;
 
48
    set "FAILSAVE_APPEND/value[last()+1]" "console=ttyS0" ;
 
49
    rm "LOADER_TYPE" ;
 
50
    rm "MODULES_LOADED_ON_BOOT/value[1]" ;
 
51
    set "DEFAULT_APPEND/value[last()+1]" "teststring"
 
52
    = "# Some comment
 
53
MODULES_LOADED_ON_BOOT=\"sunrpc\"
 
54
 
 
55
DEFAULT_APPEND=\"showopts noresume console=tty0 console=ttyS0,115200n8 ro teststring\"
 
56
 
 
57
FAILSAVE_APPEND=\"console=ttyS0\"
 
58
"
 
59
 
 
60
  (* test of single quotes (leading/trailing whitespaces are kept *)
 
61
  (* leading/trailing) *)
 
62
  test Shellvars_list.lns put "VAR=' \t test1\t  \ntest2  '\n" after
 
63
    set "VAR/value[last()+1]" "test3"
 
64
    = "VAR=' \t test1\t  \ntest2 test3  '\n"
 
65
 
 
66
  (* change quotes (leading/trailing whitespaces are lost *)
 
67
  test Shellvars_list.lns put "VAR=' \t test1\t  \ntest2  '\n" after
 
68
    set "VAR/quote" "\""
 
69
    = "VAR=\"test1\t  \ntest2\"\n"
 
70
 
 
71
  (* double quotes are allowed in single quoted lists *)
 
72
  test Shellvars_list.lns get "VAR='test\"1 test2'\n" =
 
73
    { "VAR"
 
74
      { "quote" = "'" }
 
75
      { "value" = "test\"1" }
 
76
      { "value" = "test2" } }
 
77
 
 
78
  (* emtpy list with quotes *)
 
79
  test Shellvars_list.lns get "VAR=''\n" =
 
80
    { "VAR"
 
81
      { "quote" = "'" } }
 
82
 
 
83
  (* unquoted value *)
 
84
  test Shellvars_list.lns get "VAR=test\n" =
 
85
    { "VAR"
 
86
      { "quote" = "" }
 
87
      { "value" = "test" } }
 
88
 
 
89
  (* uquoted value with escaped space etc. *)
 
90
  test Shellvars_list.lns get "VAR=a\\ \\\"long\\\"\\ test\n" =
 
91
    { "VAR"
 
92
      { "quote" = "" }
 
93
      { "value" = "a\\ \\\"long\\\"\\ test" } }
 
94
 
 
95
  (* append to unquoted value *)
 
96
  test Shellvars_list.lns put "VAR=test1\n" after
 
97
    set "VAR/quote" "\"";
 
98
    set "VAR/value[last()+1]" "test2"
 
99
    = "VAR=\"test1 test2\"\n"
 
100
 
 
101
  (* empty entry *)
 
102
  test Shellvars_list.lns get "VAR=\n" =
 
103
    { "VAR"
 
104
      { "quote" = "" } }
 
105
 
 
106
  (* set value w/o quotes to empty value... *)
 
107
  test Shellvars_list.lns put "VAR=\n" after
 
108
    set "VAR/value[last()+1]" "test"
 
109
    = "VAR=test\n"
 
110
 
 
111
  (* ... or no value *)
 
112
  test Shellvars_list.lns put "" after
 
113
    set "VAR/quote" "";
 
114
    set "VAR/value[1]" "test"
 
115
    = "VAR=test\n"
 
116
 
 
117
(* Local Variables: *)
 
118
(* mode: caml       *)
 
119
(* End:             *)