mirror of
https://github.com/status-im/NimYAML.git
synced 2025-02-05 07:54:15 +00:00
Fixed issues in quickstart and taglib
* Updated expected YAML in 02 * Fixed duplicate TagIds in taglib
This commit is contained in:
parent
0f2e077b87
commit
4bde3a7986
@ -2,15 +2,15 @@
|
|||||||
---
|
---
|
||||||
!nim:system:seq(nim:custom:Person) [
|
!nim:system:seq(nim:custom:Person) [
|
||||||
!nim:custom:Person {
|
!nim:custom:Person {
|
||||||
? !!str "name"
|
? !nim:field "name"
|
||||||
: !!str "Karl Koch",
|
: !!str "Karl Koch",
|
||||||
? !!str "age"
|
? !nim:field "age"
|
||||||
: !nim:system:int32 "23"
|
: !nim:system:int32 "23"
|
||||||
},
|
},
|
||||||
!nim:custom:Person {
|
!nim:custom:Person {
|
||||||
? !!str "name"
|
? !nim:field "name"
|
||||||
: !!str "Peter Pan",
|
: !!str "Peter Pan",
|
||||||
? !!str "age"
|
? !nim:field "age"
|
||||||
: !nim:system:int32 "12"
|
: !nim:system:int32 "12"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -46,6 +46,8 @@ proc outputTest(path: string): bool =
|
|||||||
currentDir = getCurrentDir()
|
currentDir = getCurrentDir()
|
||||||
basePath = currentDir / ".."
|
basePath = currentDir / ".."
|
||||||
absolutePath = currentDir / path
|
absolutePath = currentDir / path
|
||||||
|
outFileExpected = path / "01-out.yaml"
|
||||||
|
outFileActual = path / "out.yaml"
|
||||||
copyFile(codeFileOrig, codeFileDest)
|
copyFile(codeFileOrig, codeFileDest)
|
||||||
defer: removeFile(codeFileDest)
|
defer: removeFile(codeFileDest)
|
||||||
var process = startProcess("nim c --hints:off -p:" & escape(basePath) &
|
var process = startProcess("nim c --hints:off -p:" & escape(basePath) &
|
||||||
@ -69,9 +71,10 @@ proc outputTest(path: string): bool =
|
|||||||
echo process.outputStream().readAll()
|
echo process.outputStream().readAll()
|
||||||
result = false
|
result = false
|
||||||
else:
|
else:
|
||||||
|
defer: removeFile(outFileActual)
|
||||||
var
|
var
|
||||||
expected = open(path / "01-out.yaml", fmRead)
|
expected = open(outFileExpected, fmRead)
|
||||||
actual = open(path / "out.yaml", fmRead)
|
actual = open(outFileActual, fmRead)
|
||||||
lineNumber = 1
|
lineNumber = 1
|
||||||
defer:
|
defer:
|
||||||
expected.close()
|
expected.close()
|
||||||
|
@ -94,7 +94,10 @@ const
|
|||||||
## for seqs that are nil. This tag is used regardless of the seq's generic
|
## for seqs that are nil. This tag is used regardless of the seq's generic
|
||||||
## type parameter.
|
## 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
|
## The first ``TagId`` which should be assigned to an URI that does not
|
||||||
## exist in the ``YamlTagLibrary`` which is used for parsing.
|
## exist in the ``YamlTagLibrary`` which is used for parsing.
|
||||||
|
|
||||||
@ -217,7 +220,7 @@ var
|
|||||||
## `serializable <#serializable,stmt,stmt>`_.
|
## `serializable <#serializable,stmt,stmt>`_.
|
||||||
|
|
||||||
var
|
var
|
||||||
nextStaticTagId {.compileTime.} = 100.TagId ## \
|
nextStaticTagId {.compileTime.} = yFirstStaticTagId ## \
|
||||||
## used for generating unique TagIds with ``setTagUri``.
|
## used for generating unique TagIds with ``setTagUri``.
|
||||||
registeredUris {.compileTime.} = newSeq[string]() ## \
|
registeredUris {.compileTime.} = newSeq[string]() ## \
|
||||||
## Since Table doesn't really work at compile time, we also store
|
## 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:
|
static:
|
||||||
registeredUris.add(uri)
|
registeredUris.add(uri)
|
||||||
nextStaticTagId = TagId(int(nextStaticTagId) + 1)
|
nextStaticTagId = TagId(int(nextStaticTagId) + 1)
|
||||||
|
when nextStaticTagId == yFirstCustomTagId:
|
||||||
|
{.fatal: "Too many tags!".}
|
||||||
serializationTagLibrary.tags[uri] = idName
|
serializationTagLibrary.tags[uri] = idName
|
||||||
proc yamlTag*(T: typedesc[t]): TagId {.inline, raises: [].} = idName
|
proc yamlTag*(T: typedesc[t]): TagId {.inline, raises: [].} = idName
|
||||||
## autogenerated
|
## autogenerated
|
||||||
|
Loading…
x
Reference in New Issue
Block a user