1
1
import { Test } from 'nodeunit' ;
2
+ import { toYAML } from '../lib/serialize' ;
2
3
3
- import YAML = require( 'js-yaml' ) ;
4
-
5
- function yamlStringify ( obj : any ) {
6
- return YAML . dump ( obj ) ;
7
- }
4
+ // Preferred quote of the YAML library
5
+ const q = '"' ;
8
6
9
7
export = {
10
8
'quote the word "ON"' ( test : Test ) {
11
9
// NON NEGOTIABLE! If not quoted, will be interpreted as the boolean TRUE
12
10
13
11
// tslint:disable-next-line:no-console
14
- const output = yamlStringify ( {
12
+ const output = toYAML ( {
15
13
notABoolean : "ON"
16
14
} ) ;
17
15
18
- test . equals ( output . trim ( ) , `notABoolean: 'ON' ` ) ;
16
+ test . equals ( output . trim ( ) , `notABoolean: ${ q } ON ${ q } ` ) ;
19
17
20
18
test . done ( ) ;
21
19
} ,
22
20
23
21
'quote number-like strings with a leading 0' ( test : Test ) {
24
- const output = yamlStringify ( {
22
+ const output = toYAML ( {
25
23
leadingZero : "012345"
26
24
} ) ;
27
25
28
- test . equals ( output . trim ( ) , `leadingZero: ' 012345' ` ) ;
26
+ test . equals ( output . trim ( ) , `leadingZero: ${ q } 012345${ q } ` ) ;
29
27
30
28
test . done ( ) ;
31
29
} ,
32
30
33
31
'do not quote octal numbers that arent really octal' ( test : Test ) {
34
- // Under contention: this seems to be okay, pyyaml parses it
35
- // correctly. Unsure of what CloudFormation does about it.
32
+ // This is a contentious one, and something that might have changed in YAML1.2 vs YAML1.1
33
+ //
34
+ // One could make the argument that a sequence of characters that couldn't ever
35
+ // be an octal value doesn't need to be quoted, and pyyaml parses it correctly.
36
+ //
37
+ // However, CloudFormation's parser interprets it as a decimal number (eating the
38
+ // leading 0) if it's unquoted, so that's the behavior we're testing for.
36
39
37
- const output = yamlStringify ( {
40
+ const output = toYAML ( {
38
41
leadingZero : "0123456789"
39
42
} ) ;
40
43
41
- test . equals ( output . trim ( ) , `leadingZero: 0123456789` ) ;
44
+ test . equals ( output . trim ( ) , `leadingZero: ${ q } 0123456789${ q } ` ) ;
42
45
43
46
test . done ( ) ;
44
47
} ,
@@ -48,14 +51,14 @@ export = {
48
51
//
49
52
// 'yaml' fails this.
50
53
51
- const output = yamlStringify ( {
54
+ const output = toYAML ( {
52
55
colons : [ 'arn' , ':' , 'aws' ]
53
56
} ) ;
54
57
55
58
test . equals ( output . trim ( ) , [
56
59
'colons:' ,
57
60
' - arn' ,
58
- ` - ':' ` ,
61
+ ` - ${ q } : ${ q } ` ,
59
62
' - aws'
60
63
] . join ( '\n' ) ) ;
61
64
0 commit comments