HsacAcceptanceTests.SlimTests.UtilityFixtures.MapFixtureTest


Map Fixture allows Maps to be defined and manipulated in the wiki. It is usable both in script tables and dynamic decision tables.



Dynamic Decision Table Usage

The first examples show usage of the fixture in dynamic decision tables[?].
This allows a map to be defined based on a row of a wiki table, Map of Maps Fixture allows maps to be defined based on the columns of a table.

Define a Map

Here we define a map (and store it in a Slim variable) using simple values and a list (indicated by the header name ending on '[]'), using a dynamic decision table. Any output column (header name ending on '?') will receive a copy of the map defined.

ddt: map fixture
a b email aliases[] hash?
1 2 fitnesse@hsac.nl github@hsac.nl, FitNesse@hsac.nl $hash1<-[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]

Nested maps

Here we define a map with a nested map under the 'map' key.

ddt: map fixture
c map url map?
 <xml/> 
$hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/ $hash2<-[
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
]
3 $hash2->[
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
]
https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki $hash3<-[
c 3
map
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
url https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki
]



Maps in a Script

Here we manipulate a map using script tables[?]. This can be done either with or without a map to manipulate in the script's first row.

Map Supplied in Constructor

The map to use is supplied using a constructor argument to the fixture. First we use 'hash3' defined above and then 'hash4', created by the first script.

Values for lists can either be set using the 'set values' method or by specifying a key name ending on '[]'. (The '[]' will not be included in the key name. If you do want a key name ending on '[]' you have to specify '\[]', its content will not be seen as a list)

script map fixture $hash3->[
c 3
map
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
url https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki
]
check value c 3
check size 3
clear value c
check size 2
check value c null
reject clear value c
set value 6 for d
check size 3
set values 7,8 for e
set value 9,asas for f[]
set value 9,asas for g\[]
check value map.map.b 2
set value 3 for map.map.b
check value b in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
3
check value aliases[1] in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
FitNesse@hsac.nl
set value github3@hsac.nl for map.map.aliases[1]
check value aliases[1] in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
github3@hsac.nl
check value e[0] 7
check value f[1] asas
check value g[] 9,asas
$hash4<-[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
value map.map
check size of map.map 4
$allKeys2<-[[map, url, d, e, f, g[]]] all keys
show all values [<table class="hash_table"> <tr class="hash_row"> <td class="hash_key">c</td> <td class="hash_value">&lt;xml/&gt;</td> </tr> <tr class="hash_row"> <td class="hash_key">map</td> <td class="hash_value"><table class="hash_table"> <tr class="hash_row"> <td class="hash_key">a</td> <td class="hash_value">1</td> </tr> <tr class="hash_row"> <td class="hash_key">b</td> <td class="hash_value">3</td> </tr> <tr class="hash_row"> <td class="hash_key">email</td> <td class="hash_value">fitnesse@hsac.nl</td> </tr> <tr class="hash_row"> <td class="hash_key">aliases</td> <td class="hash_value">[github@hsac.nl, github3@hsac.nl]</td> </tr> </table></td> </tr> <tr class="hash_row"> <td class="hash_key">url</td> <td class="hash_value">https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/</td> </tr> </table>, https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki, 6, [7, 8], [9, asas], 9,asas]
$hash5<-[
map
c <xml/>
map
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
url https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki
d 6
e [7, 8]
f [9, asas]
g[] 9,asas
]
copy map

script map fixture $hash4->[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
check value b 3
$aliases<-[[github@hsac.nl, github3@hsac.nl]] value aliases
$aliases2<-[[github@hsac.nl, github3@hsac.nl]] value aliases[]
check value aliases[0] github@hsac.nl
check value aliases[2] null
check size of aliases 2
check size of aliases[] 2
content equals $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
reject content equals $hash2->[
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
]

Map as Argument

Here we supply no map to the constructor, but pass the one to use in each script row or use the newly (empty) implicitly created map.

script map fixture
check value b in $hash4->[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
3
set value 4 for b in $hash4->[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
note the wiki does not show the updated value for $hash4.b, but it is set correctly!
check value b in $hash4->[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
4
check value map.map.a in $hash3->[
c 3
map
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
url https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki
]
1
check size of aliases in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
2
set values mytest@hsac.nl for aliases in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
note the wiki does not show the updated value for $hash1.aliases, but it is set correctly!
check size of aliases in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
1
check value aliases[0] in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
mytest@hsac.nl
ensure content of $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
equals $hash4->[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
reject content of $hash2->[
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
]
equals $hash4->[
a 1
b 3
email fitnesse@hsac.nl
aliases [github@hsac.nl, github3@hsac.nl]
]
check size of $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
4
set value a for b
set value c for a
$hash6<-[
b a
a c
]
copy map

Not Expanding . in Name to Nested Map


Normally when setting values '.' in a name is interpreted to mean a nested map. But this can be disabled.

script map fixture
ensure expands periods in names to nested maps
set value 2 for browser.download.folderList
set value sheetml.sheet for browser.helperApps.neverAsk.saveToDisk
$browser<-[
download
folderList 2
helperApps
neverAsk
saveToDisk sheetml.sheet
]
value browser
check size of $browser->[
download
folderList 2
helperApps
neverAsk
saveToDisk sheetml.sheet
]
2
check value browser.download.folderList 2
check value browser.helperApps.neverAsk.saveToDisk sheetml.sheet



script map fixture
expand periods in names to nested maps false
reject expands periods in names to nested maps
set value 2 for browser.download.folderList
set value sheetml.sheet for browser.helperApps.neverAsk.saveToDisk
check value browser null
check value browser.download.folderList 2
check value browser.helperApps.neverAsk.saveToDisk sheetml.sheet

Adding elements to a list


We ensure we display lists numbered, because otherwise lists of maps look quite bad in wiki.

script list fixture
display lists numbered

script map fixture
Add to existing list
set values 7,8 for a
add value 9 to a
check value a[2] 9
Add to new list
add value 1 to b
add value 2 to b
check value b[1] 2
Add a map to an existing list
set value $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
for c[0]
add value $hash2->[
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
]
to c
check value c[1].map.a 1
Add a map to new list
add value $hash2->[
c <xml/>
map
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
]
to d
add value
mykey 1
key2 2
to d
check size of d 2
check value d[1].mykey 1
check value d[1].key2 2
$hash7<-[
a
  1. 7
  2. 8
  3. 9
b
  1. 1
  2. 2
c
  1. a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
  2. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
d
  1. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
  2. key2 2
    mykey 1
]
copy map

script map fixture
Add to existing list
add value 6 to a in $hash7->[
a
  1. 7
  2. 8
  3. 9
b
  1. 1
  2. 2
c
  1. a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
  2. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
d
  1. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
  2. key2 2
    mykey 1
]
check value a[3] in $hash7->[
a
  1. 7
  2. 8
  3. 9
b
  1. 1
  2. 2
c
  1. a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
  2. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
d
  1. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
  2. key2 2
    mykey 1
]
6
Add to new list
add value Hello to e in $hash7->[
a
  1. 7
  2. 8
  3. 9
b
  1. 1
  2. 2
c
  1. a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
  2. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
d
  1. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
  2. key2 2
    mykey 1
]
add value Bye to e in $hash7->[
a
  1. 7
  2. 8
  3. 9
b
  1. 1
  2. 2
c
  1. a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
  2. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
d
  1. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
  2. key2 2
    mykey 1
]
check value e[1] in $hash7->[
a
  1. 7
  2. 8
  3. 9
b
  1. 1
  2. 2
c
  1. a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
  2. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
d
  1. c <xml/>
    map
    a 1
    b 4
    email fitnesse@hsac.nl
    aliases
    1. mytest@hsac.nl
    url https://github.com/fhoeben/hsac-fitnesse-fixtures/releases/
  2. key2 2
    mykey 1
]
Bye

Copying of values


Copying values is not the same as changing existing map (but nested values are shared)!

script map fixture
copy values from $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
check value a 1
check value aliases[0] mytest@hsac.nl
set value Dag for aliases[0]
check value aliases[0] Dag
set value 2 for a
check value a in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
1
check value aliases[0] in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
Dag
$hash8<-[
a 2
b 4
email fitnesse@hsac.nl
aliases
  1. Dag
]
copy map

Copy overwrites existing values.

script map fixture
copy values from $hash8->[
a 2
b 4
email fitnesse@hsac.nl
aliases
  1. Dag
]
to $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
check value aliases[0] in $hash1->[
a 1
b 2
email fitnesse@hsac.nl
aliases [github@hsac.nl, FitNesse@hsac.nl]
]
Dag