Fixed issues in quickstart and taglib

* Updated expected YAML in 02
 * Fixed duplicate TagIds in taglib
This commit is contained in:
Felix Krause 2016-10-09 11:48:52 +02:00
parent 0f2e077b87
commit 4bde3a7986
3 changed files with 16 additions and 8 deletions

View File

@ -2,15 +2,15 @@
---
!nim:system:seq(nim:custom:Person) [
!nim:custom:Person {
? !!str "name"
? !nim:field "name"
: !!str "Karl Koch",
? !!str "age"
? !nim:field "age"
: !nim:system:int32 "23"
},
!nim:custom:Person {
? !!str "name"
? !nim:field "name"
: !!str "Peter Pan",
? !!str "age"
? !nim:field "age"
: !nim:system:int32 "12"
}
]

View File

@ -46,6 +46,8 @@ proc outputTest(path: string): bool =
currentDir = getCurrentDir()
basePath = currentDir / ".."
absolutePath = currentDir / path
outFileExpected = path / "01-out.yaml"
outFileActual = path / "out.yaml"
copyFile(codeFileOrig, codeFileDest)
defer: removeFile(codeFileDest)
var process = startProcess("nim c --hints:off -p:" & escape(basePath) &
@ -69,9 +71,10 @@ proc outputTest(path: string): bool =
echo process.outputStream().readAll()
result = false
else:
defer: removeFile(outFileActual)
var
expected = open(path / "01-out.yaml", fmRead)
actual = open(path / "out.yaml", fmRead)
expected = open(outFileExpected, fmRead)
actual = open(outFileActual, fmRead)
lineNumber = 1
defer:
expected.close()

View File

@ -94,7 +94,10 @@ const
## for seqs that are nil. This tag is used regardless of the seq's generic
## type parameter.
yFirstCustomTagId* : TagId = 1000.TagId ## \
yFirstStaticTagId* : TagId = 1000.TagId ## \
## The first ``TagId`` assigned by the ``setTagId`` templates.
yFirstCustomTagId* : TagId = 10000.TagId ## \
## The first ``TagId`` which should be assigned to an URI that does not
## exist in the ``YamlTagLibrary`` which is used for parsing.
@ -217,7 +220,7 @@ var
## `serializable <#serializable,stmt,stmt>`_.
var
nextStaticTagId {.compileTime.} = 100.TagId ## \
nextStaticTagId {.compileTime.} = yFirstStaticTagId ## \
## used for generating unique TagIds with ``setTagUri``.
registeredUris {.compileTime.} = newSeq[string]() ## \
## Since Table doesn't really work at compile time, we also store
@ -249,6 +252,8 @@ template setTagUri*(t: typedesc, uri: string, idName: untyped): typed =
static:
registeredUris.add(uri)
nextStaticTagId = TagId(int(nextStaticTagId) + 1)
when nextStaticTagId == yFirstCustomTagId:
{.fatal: "Too many tags!".}
serializationTagLibrary.tags[uri] = idName
proc yamlTag*(T: typedesc[t]): TagId {.inline, raises: [].} = idName
## autogenerated