-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparser_test.go
63 lines (56 loc) · 2.3 KB
/
parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package json_markd
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateMarkdownBlockList(t *testing.T) {
SetTabSpaceValue(2)
SetupLogger()
t.Run("when correct data list is passed", func(t *testing.T) {
lineDataList := []string{
" - data: object",
}
t.Run("it should return correct response", func(t *testing.T) {
expectedResponse := []markdownBlock{markdownBlock{TabCount: 0, Key: "\"data\"", Value: 0}}
markdownBlock, _ := createMarkdownBlockList(lineDataList)
assert.Equal(t, expectedResponse, markdownBlock)
})
})
t.Run("when incorrect data list is passed", func(t *testing.T) {
lineDataList := []string{
"data object",
}
SetTabSpaceValue(2)
t.Run("it should return error", func(t *testing.T) {
expectedResponse := errors.New(".errors.invalid_markdown_list_format")
_, err := createMarkdownBlockList(lineDataList)
assert.Equal(t, expectedResponse, err)
})
})
}
func TestParseMarkdown(t *testing.T) {
SetTabSpaceValue(2)
SetupLogger()
t.Run("when correct file is passed", func(t *testing.T) {
t.Run("it should return correct response", func(t *testing.T) {
expectedResponse := "{\n \"data\" : {\n \"name\" : \"random string\",\n \"age\" : 0,\n \"income\" : 0.0,\n \"vehicles\" : [\n {\n \"name\" : \"random string\",\n \"price\" : 0.0\n }\n ],\n \"apps\" : [\n [\n \"random string\",\n \"random string\"\n ],\n [\n \"random string\",\n \"random string\"\n ]\n ]\n },\n \"errors\" : {\n \"type\" : \"random string\"\n }\n}"
result, _ := ParseMarkdown("./test_data/sample.md")
assert.Equal(t, expectedResponse, result)
})
})
t.Run("when incorrect file is passed", func(t *testing.T) {
t.Run("it should return correct response", func(t *testing.T) {
expectedResponse := "open ./test_data/sample_1.md: no such file or directory"
_, err := ParseMarkdown("./test_data/sample_1.md")
assert.Equal(t, expectedResponse, err.Error())
})
})
t.Run("when file data is invalid", func(t *testing.T) {
t.Run("it should return correct response", func(t *testing.T) {
expectedResponse := ".errors.invalid_markdown_list_format"
_, err := ParseMarkdown("./test_data/sample_invalid.md")
assert.Equal(t, expectedResponse, err.Error())
})
})
}