HsacExamples.SlimTests.UtilityFixtures.ListFixtureTest


List Fixture allows Lists to be defined and manipulated in the wiki. It is usable both in script tables and dynamic decision tables.
Furthermore it also allows us to ensure Slim show lists as numbered items, instead of comma separated between square brackets (i.e. '[' and ']').



Lists in a Script

Here we manipulate lists using script tables[?].


script list fixture
add Fried
add github@hsac.nl
check value at 0 Fried
check size 2
set value Ivan at 4
check size 5
check value at 2 null
check value at 3 null
check value at 4 Ivan
check value at 1 github@hsac.nl
set value Jan at 1
check value at 1 Jan
ensure element Ivan is present
check index of Ivan 4
check index of Klaas -1
$list1<-[[Fried, Jan, null, null, Ivan]] copy list

Showing Lists as Numbered Items

As seen in the table above Slim's default behavior is to show lists using Java's toString() notation, comma separated between square brackets.
By invoking ListFixture's display lists numbered method we instruct Slim to show lists as HTML ordered lists.

This could also be achieved directly in Java code by invoking nl.hsac.fitnesse.slim.converter.NumberedListConverter.register().


script list fixture
display lists numbered
add Fried
set value Jan at 1
$list1<-[
  1. Fried
  2. Jan
]
copy list



List may be nested


script list fixture
add $list1->[
  1. Fried
  2. Jan
]
add $list1->[
  1. Fried
  2. Jan
]
copy values from $list1->[
  1. Fried
  2. Jan
]
$list2<-[
    1. Fried
    2. Jan
    1. Fried
    2. Jan
  1. Fried
  2. Jan
]
copy list



Define a List using Dynamic Decision Table

This examples show usage of the fixture in a dynamic decision table[?].

Here we define two lists (and store them in Slim variables) using a dynamic decision table. Any output column (header name ending on '?') will receive a copy of the list defined.
ddt: list fixture
0 1 3 4 list?
Jan github@hsac.nl Karel $list3<-[
  1. Jan
  2. github@hsac.nl
  3. null
  4. Karel
]
Karel Piet Milk $list4<-[
  1. Karel
  2. Piet
  3. null
  4. Milk
]

List as Argument

We don't use lists defined in the current fixture instance, but supply the lists to work on in the rows to the script.

script list fixture
check value at 1 in $list3->[
  1. Jan
  2. github@hsac.nl
  3. null
  4. Karel
]
github@hsac.nl
check size of $list3->[
  1. Jan
  2. github@hsac.nl
  3. null
  4. Karel
]
5
check value at 2 in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
null
check value at 3 in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
BLANK
set value Ivan at 3 in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
check value at 3 in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
Ivan
ensure element Ivan is present in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
check index of Ivan in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
3
copy values from $list1->[
  1. Fried
  2. Jan
]
to $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
check index of Fried in $list4->[
  1. Karel
  2. Piet
  3. null
  4. Milk
]
5