@@ -10,7 +10,6 @@ func TestParsingMarkdownHeaders(t *testing.T) {
10
10
markdown := []byte (`# Hello World` )
11
11
document := ParseMarkdownIntoAst (markdown )
12
12
title , err := ExtractScenarioTitleFromAst (document , markdown )
13
-
14
13
if err != nil {
15
14
t .Errorf ("Error parsing title: %s" , err )
16
15
}
@@ -24,7 +23,6 @@ func TestParsingMarkdownHeaders(t *testing.T) {
24
23
markdown := []byte ("# Hello World \n # Hello again" )
25
24
document := ParseMarkdownIntoAst (markdown )
26
25
title , err := ExtractScenarioTitleFromAst (document , markdown )
27
-
28
26
if err != nil {
29
27
t .Errorf ("Error parsing title: %s" , err )
30
28
}
@@ -50,8 +48,60 @@ func TestParsingMarkdownHeaders(t *testing.T) {
50
48
})
51
49
}
52
50
53
- func TestParsingMarkdownCodeBlocks (t * testing.T ) {
51
+ func TestParsingYamlMetadata (t * testing.T ) {
52
+ t .Run ("Markdown with valid yaml metadata" , func (t * testing.T ) {
53
+ markdown := []byte (`---
54
+ key: value
55
+ array: [1, 2, 3]
56
+ ---
57
+ ` )
58
+
59
+ document := ParseMarkdownIntoAst (markdown )
60
+ metadata := ExtractYamlMetadataFromAst (document )
61
+
62
+ if metadata ["key" ] != "value" {
63
+ t .Errorf ("Metadata is wrong: %v" , metadata )
64
+ }
65
+
66
+ array := metadata ["array" ].([]interface {})
67
+ if array [0 ] != 1 || array [1 ] != 2 || array [2 ] != 3 {
68
+ t .Errorf ("Metadata is wrong: %v" , metadata )
69
+ }
70
+ })
71
+
72
+ t .Run ("Markdown without yaml metadata" , func (t * testing.T ) {
73
+ markdown := []byte (`# Hello World.` )
74
+ document := ParseMarkdownIntoAst (markdown )
75
+ metadata := ExtractYamlMetadataFromAst (document )
76
+
77
+ if len (metadata ) != 0 {
78
+ t .Errorf ("Metadata should be empty" )
79
+ }
80
+ })
81
+
82
+ t .Run ("yaml with nested properties" , func (t * testing.T ) {
83
+ markdown := []byte (`---
84
+ nested:
85
+ key: value
86
+ key.value: otherValue
87
+ ---
88
+ ` )
54
89
90
+ document := ParseMarkdownIntoAst (markdown )
91
+ metadata := ExtractYamlMetadataFromAst (document )
92
+
93
+ nested := metadata ["nested" ].(map [interface {}]interface {})
94
+ if nested ["key" ] != "value" {
95
+ t .Errorf ("Metadata is wrong: %v" , metadata )
96
+ }
97
+
98
+ if metadata ["key.value" ] != "otherValue" {
99
+ t .Errorf ("Metadata is wrong: %v" , metadata )
100
+ }
101
+ })
102
+ }
103
+
104
+ func TestParsingMarkdownCodeBlocks (t * testing.T ) {
55
105
t .Run ("Markdown with a valid bash code block" , func (t * testing.T ) {
56
106
markdown := []byte (fmt .Sprintf ("# Hello World\n ```bash\n %s\n ```" , "echo Hello" ))
57
107
@@ -74,13 +124,16 @@ func TestParsingMarkdownCodeBlocks(t *testing.T) {
74
124
)
75
125
}
76
126
})
77
-
78
127
}
79
128
80
129
func TestParsingMarkdownExpectedSimilarty (t * testing.T ) {
81
-
82
130
t .Run ("Markdown with a expected_similarty tag using float" , func (t * testing.T ) {
83
- markdown := []byte (fmt .Sprintf ("```bash\n %s\n ```\n <!--expected_similarity=0.8-->\n ```\n Hello\n ```\n " , "echo Hello" ))
131
+ markdown := []byte (
132
+ fmt .Sprintf (
133
+ "```bash\n %s\n ```\n <!--expected_similarity=0.8-->\n ```\n Hello\n ```\n " ,
134
+ "echo Hello" ,
135
+ ),
136
+ )
84
137
85
138
document := ParseMarkdownIntoAst (markdown )
86
139
codeBlocks := ExtractCodeBlocksFromAst (document , markdown , []string {"bash" })
@@ -92,16 +145,23 @@ func TestParsingMarkdownExpectedSimilarty(t *testing.T) {
92
145
block := codeBlocks [0 ].ExpectedOutput
93
146
expectedFloat := .8
94
147
if block .ExpectedSimilarity != expectedFloat {
95
- t .Errorf ("ExpectedSimilarity is wrong, got %f, expected %f" , block .ExpectedSimilarity , expectedFloat )
148
+ t .Errorf (
149
+ "ExpectedSimilarity is wrong, got %f, expected %f" ,
150
+ block .ExpectedSimilarity ,
151
+ expectedFloat ,
152
+ )
96
153
}
97
154
})
98
-
99
155
}
100
156
101
157
func TestParsingMarkdownExpectedRegex (t * testing.T ) {
102
-
103
158
t .Run ("Markdown with a expected_similarty tag using regex" , func (t * testing.T ) {
104
- markdown := []byte (fmt .Sprintf ("```bash\n %s\n ```\n <!--expected_similarity=\" Foo \\ w+\" -->\n ```\n Foo Bar\n ```\n " , "echo 'Foo Bar'" ))
159
+ markdown := []byte (
160
+ fmt .Sprintf (
161
+ "```bash\n %s\n ```\n <!--expected_similarity=\" Foo \\ w+\" -->\n ```\n Foo Bar\n ```\n " ,
162
+ "echo 'Foo Bar'" ,
163
+ ),
164
+ )
105
165
106
166
document := ParseMarkdownIntoAst (markdown )
107
167
codeBlocks := ExtractCodeBlocksFromAst (document , markdown , []string {"bash" })
@@ -121,5 +181,4 @@ func TestParsingMarkdownExpectedRegex(t *testing.T) {
121
181
t .Errorf ("ExpectedRegex is wrong, got %q, expected %q" , stringRegex , expectedRegex )
122
182
}
123
183
})
124
-
125
184
}
0 commit comments