Fix styleCheck:usage (#27)

This commit is contained in:
Tanguy 2022-08-02 17:38:16 +02:00 committed by GitHub
parent ae13ff450b
commit 27b400fdf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 10 deletions

View File

@ -14,9 +14,15 @@ requires "nim >= 1.2.0",
"serialization",
"combparser"
const styleCheckStyle =
if (NimMajor, NimMinor) < (1, 6):
"hint"
else:
"error"
proc test(args, path: string) =
exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " " & args &
" -r --hints:off --skipParentCfg " & path
" -r --hints:off --skipParentCfg --styleCheck:usages --styleCheck:" & styleCheckStyle & " " & path
task test, "Run all tests":
#Explicitly specify the call depth limit in case the default changes in the future.

View File

@ -120,7 +120,7 @@ proc protoToTypesInternal*(filepath: string, proto: string): NimNode =
result.add(
newNimNode(nnkTypeDef).add(
newNimNode(nnkPragmaExpr).add(
newNimNode(nnkPostFix).add(ident("*"), ident(name)),
newNimNode(nnkPostfix).add(ident("*"), ident(name)),
newNimNode(nnkPragma).add(ident("protobuf3"))
),
newEmptyNode(),

View File

@ -119,7 +119,7 @@ func viSizeof(base: VarIntWrapped, raw: uint32 or uint64): int =
result = max((log2trunc(raw) + 7) div 7, 1)
func encodeVarInt*(
res: var openarray[byte],
res: var openArray[byte],
outLen: var int,
value: VarIntWrapped
): VarIntStatus =
@ -175,7 +175,7 @@ func encodeVarInt*(value: VarIntWrapped): seq[byte] =
var outLen: int
if encodeVarInt(result, outLen, value) != VarIntStatus.Success:
when value is LUIntWrapped:
{.fatal: "LibP2P VarInts require using the following signature: `encodeVarInt(var openarray[byte], outLen: var int, value: VarIntWrapped): VarIntStatus`.".}
{.fatal: "LibP2P VarInts require using the following signature: `encodeVarInt(var openArray[byte], outLen: var int, value: VarIntWrapped): VarIntStatus`.".}
else:
doAssert(false)
result.setLen(outLen)
@ -219,7 +219,7 @@ func decodeBinaryValue[E](
return VarIntStatus.Success
func decodeVarInt*(
bytes: openarray[byte],
bytes: openArray[byte],
inLen: var int,
res: var VarIntWrapped
): VarIntStatus =

View File

@ -16,7 +16,7 @@ proc encodeNumber[T](stream: OutputStream, value: T) =
else:
{.fatal: "Trying to encode a number which isn't wrapped. This should never happen.".}
proc stdLibToProtobuf[R](
proc stdlibToProtobuf[R](
stream: OutputStream,
_: typedesc[R],
unusedFieldName: static string,
@ -124,7 +124,7 @@ proc stdlibToProtobuf[R, T](
var seqInstance: seq[T]
for value in setInstance:
seqInstance.add(value)
stream.stdLibToProtobuf(ty, fieldName, fieldNumber, seqInstance)
stream.stdlibToProtobuf(ty, fieldName, fieldNumber, seqInstance)
proc stdlibToProtobuf[R, T](
stream: OutputStream,
@ -133,4 +133,4 @@ proc stdlibToProtobuf[R, T](
fieldNumber: int,
setInstance: HashSet[T]
) {.inline.} =
stream.stdLibToProtobuf(ty, fieldName, fieldNumber, setInstance.toSeq())
stream.stdlibToProtobuf(ty, fieldName, fieldNumber, setInstance.toSeq())

View File

@ -73,12 +73,12 @@ suite "Test Standard Lib Objects Encoding/Decoding":
check Protobuf.decode(Protobuf.encode(setInstance), type(HashSet[string])) == setInstance
test "Can encode/decode stdlib fields where a pragma was used to specify encoding":
let pragmad = PragmadStdLib(
let pragmad = PragmadStdlib(
x: @[5'i32, -3'i32, 300'i32, -612'i32],
#y: [6'u32, 4'u32, 301'u32, 613'u32, 216'u32],
z: @[5.5'f32, 3.2'f32, 925.123].toHashSet()
)
check Protobuf.decode(Protobuf.encode(pragmad), PragmadStdLib) == pragmad
check Protobuf.decode(Protobuf.encode(pragmad), PragmadStdlib) == pragmad
test "Can encode boolean seqs": #/arrays":
let boold = BooldStdlib(