2024-11-20 20:33:22 +00:00
|
|
|
oats = require "oats"
|
|
|
|
|
|
|
|
describe "OATS", ->
|
|
|
|
it "parses a basic file", ->
|
|
|
|
assert.same {{name: "person", {name: "name"}, {name: "age"}}}, oats.decodefile("spec/fixtures/files/basic.oats")
|
|
|
|
deep = {
|
|
|
|
name: "first"
|
|
|
|
{
|
|
|
|
name: "second"
|
|
|
|
{ name: "third" }
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name: "second",
|
|
|
|
{ name: "third" }
|
|
|
|
{ name: "third" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.same {deep}, oats.decodefile("spec/fixtures/files/deep.oats")
|
|
|
|
|
|
|
|
it "parses basic text nodes", ->
|
|
|
|
bob = {name: "person", {name: "name", "Bob"}, {name: "age", "20"}}
|
|
|
|
assert.same {bob}, oats.decodefile("spec/fixtures/files/bob.oats")
|
2024-12-20 22:21:46 +00:00
|
|
|
|
|
|
|
it "parses multiple lines into separate nodes", ->
|
|
|
|
assert.same {"multi", "line", "strings"}, oats.decodefile("spec/fixtures/files/multi.oats")
|
2024-11-20 20:33:22 +00:00
|
|
|
|
|
|
|
it "parses one-line nodes", ->
|
|
|
|
rose = {name: "person", {name: "name", "Rose"}, {name: "age", "22"}}
|
|
|
|
assert.same {rose}, oats.decodefile("spec/fixtures/files/rose.oats")
|
|
|
|
|
2024-12-20 22:21:46 +00:00
|
|
|
it "parses inline nodes", ->
|
2024-11-20 20:33:22 +00:00
|
|
|
document = {
|
|
|
|
name: "document"
|
2024-12-20 22:21:46 +00:00
|
|
|
{
|
|
|
|
name: "section"
|
|
|
|
"Text with a "
|
|
|
|
{name: "inline", "inline"}
|
|
|
|
" node"
|
|
|
|
"Text with an "
|
|
|
|
{name: "inline"}
|
|
|
|
" empty nested node"
|
|
|
|
{name: "one-line", "with ", {name: "inline"}, " node"}
|
|
|
|
}
|
2024-11-20 20:33:22 +00:00
|
|
|
}
|
2024-12-20 22:21:46 +00:00
|
|
|
assert.same document, oats.decodefile("spec/fixtures/files/document.oats")[1]
|
|
|
|
|
|
|
|
it "errors for endless inline nodes", ->
|
|
|
|
assert.has.error (-> oats.decode("line with [endless tag")), "Endless inline tag on 1:11"
|
2024-11-20 20:33:22 +00:00
|
|
|
|
|
|
|
it "parses strings files", ->
|
|
|
|
assert.same {{name: "tester"}}, oats.decode("[tester]")
|
|
|
|
assert.same {{name: "tester", {name: "nested", "text"}}}, oats.decode("[tester]\n\t[nested] text")
|
|
|
|
|
|
|
|
it "errors when indentation increases by more than one", ->
|
|
|
|
assert.error ->
|
|
|
|
oats.decode("[outer]\n\t\t[nested]")
|
|
|
|
|
|
|
|
it "ignores empty lines", ->
|
|
|
|
assert.same {{name: "tester", {name: "nested", "text"}}}, oats.decode("[tester]\n\n\t[nested] text")
|