From 4bde3a79867796cfa7edcdfd95c051deadf06de7 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Sun, 9 Oct 2016 11:48:52 +0200 Subject: [PATCH] Fixed issues in quickstart and taglib * Updated expected YAML in 02 * Fixed duplicate TagIds in taglib --- doc/snippets/quickstart/02/01-out.yaml | 8 ++++---- test/tquickstart.nim | 7 +++++-- yaml/taglib.nim | 9 +++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/snippets/quickstart/02/01-out.yaml b/doc/snippets/quickstart/02/01-out.yaml index ac7ffcd..89d97a6 100644 --- a/doc/snippets/quickstart/02/01-out.yaml +++ b/doc/snippets/quickstart/02/01-out.yaml @@ -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" } ] diff --git a/test/tquickstart.nim b/test/tquickstart.nim index fd88c43..d33c1ba 100644 --- a/test/tquickstart.nim +++ b/test/tquickstart.nim @@ -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() diff --git a/yaml/taglib.nim b/yaml/taglib.nim index 25f99e8..e077ef8 100644 --- a/yaml/taglib.nim +++ b/yaml/taglib.nim @@ -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