@@ -10,7 +10,6 @@ func TestParsingMarkdownHeaders(t *testing.T) {
1010 markdown := []byte (`# Hello World` )
1111 document := ParseMarkdownIntoAst (markdown )
1212 title , err := ExtractScenarioTitleFromAst (document , markdown )
13-
1413 if err != nil {
1514 t .Errorf ("Error parsing title: %s" , err )
1615 }
@@ -24,7 +23,6 @@ func TestParsingMarkdownHeaders(t *testing.T) {
2423 markdown := []byte ("# Hello World \n # Hello again" )
2524 document := ParseMarkdownIntoAst (markdown )
2625 title , err := ExtractScenarioTitleFromAst (document , markdown )
27-
2826 if err != nil {
2927 t .Errorf ("Error parsing title: %s" , err )
3028 }
@@ -50,8 +48,60 @@ func TestParsingMarkdownHeaders(t *testing.T) {
5048 })
5149}
5250
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+ ` )
5489
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 ) {
55105 t .Run ("Markdown with a valid bash code block" , func (t * testing.T ) {
56106 markdown := []byte (fmt .Sprintf ("# Hello World\n ```bash\n %s\n ```" , "echo Hello" ))
57107
@@ -74,13 +124,16 @@ func TestParsingMarkdownCodeBlocks(t *testing.T) {
74124 )
75125 }
76126 })
77-
78127}
79128
80129func TestParsingMarkdownExpectedSimilarty (t * testing.T ) {
81-
82130 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+ )
84137
85138 document := ParseMarkdownIntoAst (markdown )
86139 codeBlocks := ExtractCodeBlocksFromAst (document , markdown , []string {"bash" })
@@ -92,16 +145,23 @@ func TestParsingMarkdownExpectedSimilarty(t *testing.T) {
92145 block := codeBlocks [0 ].ExpectedOutput
93146 expectedFloat := .8
94147 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+ )
96153 }
97154 })
98-
99155}
100156
101157func TestParsingMarkdownExpectedRegex (t * testing.T ) {
102-
103158 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+ )
105165
106166 document := ParseMarkdownIntoAst (markdown )
107167 codeBlocks := ExtractCodeBlocksFromAst (document , markdown , []string {"bash" })
@@ -121,5 +181,4 @@ func TestParsingMarkdownExpectedRegex(t *testing.T) {
121181 t .Errorf ("ExpectedRegex is wrong, got %q, expected %q" , stringRegex , expectedRegex )
122182 }
123183 })
124-
125184}
0 commit comments