HsacAcceptanceTests.SlimTests.UtilityFixtures.YamlFileFixtureTest



Yaml files fixture is a specialization of FileFixture which allows YAML files to be read.
It supports YAML specification version 1.1.

Reading

In this sample we first create a .yml file, using FileFixture, and then read it.

script file fixture
set directory http://files/test
$yaml<-[sample.yml] create sample.yml containing wine: good
append #comment: ignored to $yaml->[sample.yml] on new line
append beer: "bad" to $yaml->[sample.yml] on new line
show content of $yaml->[sample.yml]
wine: good
#comment: ignored
beer: "bad"

script yaml file fixture
load values from $yaml->[sample.yml]
show values
wine good
beer bad
check value wine good
check value beer bad
check number of values 2
We can use standard file fixture methods
delete $yaml->[sample.yml]

Writing

We can also write in an easier way:

script yaml file fixture
set directory http://files/test
set value bad for wine
set value good for beer
set value better for cola
$sample2<-[sample2.yml] create sample2.yml containing values
show content of $sample2->[sample2.yml]
wine: bad
beer: good
cola: better

script yaml file fixture
load values from $sample2->[sample2.yml]
show values
wine bad
beer good
cola better
check value wine bad
check value beer good
check value cola better
check number of values 3
delete $sample2->[sample2.yml]

Reading array

The top level of a YAML file can be an array instead of a set of properties. In that case the fixture will create a 'root value' called elements.

script file fixture
set directory http://files/test
$sample3<-[sample3.yml] create sample3.yml containing - wine
append - beer to $sample3->[sample3.yml] on new line
show content of $sample3->[sample3.yml]
- wine
- beer

script yaml file fixture
load values from $sample3->[sample3.yml]
show values
elements
  1. wine
  2. beer
check value elements[0] wine
check value elements[1] beer
check number of values 1
delete $sample3->[sample3.yml]

Writing nested value


script yaml file fixture
set directory http://files/test
set value white for wine[0]
set value red for wine[1]
set value rose for wine[2]
$sample4<-[sample4.yml] create sample4.yml containing value wine
show content of $sample4->[sample4.yml]
- white
- red
- rose

script yaml file fixture
load values from $sample4->[sample4.yml]
show values
elements
  1. white
  2. red
  3. rose
check value elements[0] white
check value elements[1] red
check value elements[2] rose
delete $sample4->[sample4.yml]

Reading binary content


script file fixture
set directory http://files/test
$bin<-[sample-bin.yml] create sample-bin.yml containing canonical: !!binary "\ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" description: The binary value above is a tiny arrow encoded as a gif image.

script yaml file fixture
load values from $bin->[sample-bin.yml]
show values
canonical [71, 73, 70, 56, 57, 97, 12, 0, 12, 0, -124, 0, 0, -1, -1, -9, -11, -11, -18, -23, -23, -27, 102, 102, 102, 0, 0, 0, -25, -25, -25, 94, 94, 94, -13, -13, -19, -114, -114, -114, -32, -32, -32, -97, -97, -97, -109, -109, -109, -89, -89, -89, -98, -98, -98, 105, 105, 105, 99, 99, 99, -93, -93, -93, -124, -124, -124, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, -1, -2, -7, 33, -2, 14, 77, 97, 100, 101, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 0, 44, 0, 0, 0, 0, 12, 0, 12, 0, 0, 5, 44, 32, 32, -114, -127, 48, -98, -29, 64, 20, -24, 105, 16, -60, -47, -118, 8, 28, -49, -128, 77, 36, 122, -17, -1, 48, -123, 112, -72, -80, 49, 102, 13, 27, -50, 1, -61, 1, 30, 16, 39, 32, -126, 10, 1, 0, 59]
description The binary value above is a tiny arrow encoded as a gif image.
check value description The binary value above is a tiny arrow encoded as a gif image.
$img1<-[arrow1.gif] create arrow1.gif containing base64 value canonical
$img2<-[arrow2.gif] create arrow2.gif containing value canonical
delete $bin->[sample-bin.yml]

Writing binary content


script yaml file fixture
set content of $img2->[arrow2.gif] as value for gif
set base64 encoded content of $img2->[arrow2.gif] as value for encoded-gif
set value A small arrow image for description
$sample5<-[sample5.yml] create sample5.yml containing values
show content of $sample5->[sample5.yml]
gif: !!binary |-
  R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
encoded-gif: R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
description: A small arrow image
delete $sample5->[sample5.yml]