Debian Codegraph @

hitch/story/scalar-hexadecimal-integer.story

raw
1 Hexadecimal Integers (HexInt):
2 docs: scalar/hexadecimal-integer
3 based on: strictyaml
4 description: |
5 StrictYAML can interpret a hexadecimal integer
6 preserving its value
7 given:
8 yaml_snippet: |
9 x: 0x1a
10 setup: |
11 from strictyaml import Map, HexInt, load
12 from ensure import Ensure
13
14 schema = Map({"x": HexInt()})
15
16 parsed = load(yaml_snippet, schema)
17
18 variations:
19 Parsed correctly:
20 steps:
21 - Run: |
22 Ensure(parsed).equals({"x": 26})
23 Ensure(parsed.as_yaml()).equals("x: 0x1a\n")
24
25 Uppercase:
26 given:
27 yaml_snippet: |
28 x: 0X1A
29 steps:
30 - Run:
31 code: |
32 Ensure(load(yaml_snippet, schema).data).equals({"x": 26})
33 Ensure(load(yaml_snippet, schema).as_yaml()).equals("x: 0X1A\n")
34
35 Invalid scalar hexadecimal integer:
36 based on: strictyaml
37 given:
38 yaml_snippet: |
39 x: some_string
40 setup: |
41 from strictyaml import Map, HexInt, load
42
43 schema = Map({"x": HexInt()})
44 steps:
45 - Run:
46 code: load(yaml_snippet, schema)
47 raises:
48 type: strictyaml.exceptions.YAMLValidationError
49 message: |-
50 when expecting a hexadecimal integer
51 found arbitrary text
52 in "<unicode string>", line 1, column 1:
53 x: some_string
54 ^ (line: 1)