mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-12 12:51:22 +08:00
Add json reader and its tests
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
angular.module("sideBySide").factory("jsonReader", () ->
|
||||
return (source) ->
|
||||
parsed = eval('(' + source + ')')
|
||||
|
||||
new_content = []
|
||||
for verse in parsed.content
|
||||
if typeof(verse) == "string"
|
||||
new_content.push({ section: "", text: verse })
|
||||
else
|
||||
if "section" not of verse
|
||||
verse.section = ""
|
||||
new_content.push(verse)
|
||||
|
||||
parsed.content = new_content
|
||||
return parsed
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
test("jsonReader", () ->
|
||||
injector = angular.injector(["ng", "sideBySide"])
|
||||
jsonReader = injector.get("jsonReader")
|
||||
|
||||
testCases = [{
|
||||
tested: """
|
||||
{
|
||||
meta: {
|
||||
Title: "Test leading text"
|
||||
},
|
||||
content: [
|
||||
"<p><strong>This</strong> is leading text.</p>",
|
||||
{ section: "I", text: "<p>First section.</p>" },
|
||||
{ section: "II", text: "<p>Second section.</p>" },
|
||||
{ text: "<p>Another section.</p>" },
|
||||
],
|
||||
}"""
|
||||
expected: {
|
||||
meta: {
|
||||
Title: "Test leading text"
|
||||
}
|
||||
content: [
|
||||
{ section: "", text: "<p><strong>This</strong> is leading text.</p>" }
|
||||
{ section: "I", text: "<p>First section.</p>" }
|
||||
{ section: "II", text: "<p>Second section.</p>" }
|
||||
{ section: "", text: "<p>Another section.</p>" }
|
||||
]
|
||||
}
|
||||
}]
|
||||
|
||||
for testCase in testCases
|
||||
deepEqual(jsonReader(testCase.tested), testCase.expected)
|
||||
)
|
||||
Reference in New Issue
Block a user