rename lenTuple and lenVarargs (#13639)
* rename 'lenTuple' to 'tupleLen' Rationale: `lenTuple` is a tuple consisting of lengths (e.g. `(1, 5, 0)`), `tupleLen` is a length of a tuple (e.g. `tupleLen((1, 5, 0) == 3`) * rename 'lenVarargs' to 'varargsLen' The same rationale as a previous commit. Consistency.
This commit is contained in:
parent
f0cd50f9c4
commit
14b2354b7d
6 changed files with 33 additions and 32 deletions
|
|
@ -92,40 +92,40 @@ block distinctBase:
|
|||
doAssert($distinctBase(typeof(b2)) == "string")
|
||||
doAssert($distinctBase(typeof(c2)) == "int")
|
||||
|
||||
block: # lenTuple
|
||||
doAssert not compiles(lenTuple(int))
|
||||
block: # tupleLen
|
||||
doAssert not compiles(tupleLen(int))
|
||||
|
||||
type
|
||||
MyTupleType = (int,float,string)
|
||||
|
||||
static: doAssert MyTupleType.lenTuple == 3
|
||||
static: doAssert MyTupleType.tupleLen == 3
|
||||
|
||||
type
|
||||
MyGenericTuple[T] = (T,int,float)
|
||||
MyGenericAlias = MyGenericTuple[string]
|
||||
static: doAssert MyGenericAlias.lenTuple == 3
|
||||
static: doAssert MyGenericAlias.tupleLen == 3
|
||||
|
||||
type
|
||||
MyGenericTuple2[T,U] = (T,U,string)
|
||||
MyGenericTuple2Alias[T] = MyGenericTuple2[T,int]
|
||||
|
||||
MyGenericTuple2Alias2 = MyGenericTuple2Alias[float]
|
||||
static: doAssert MyGenericTuple2Alias2.lenTuple == 3
|
||||
static: doAssert MyGenericTuple2Alias2.tupleLen == 3
|
||||
|
||||
static: doAssert (int, float).lenTuple == 2
|
||||
static: doAssert (1, ).lenTuple == 1
|
||||
static: doAssert ().lenTuple == 0
|
||||
static: doAssert (int, float).tupleLen == 2
|
||||
static: doAssert (1, ).tupleLen == 1
|
||||
static: doAssert ().tupleLen == 0
|
||||
|
||||
let x = (1,2,)
|
||||
doAssert x.lenTuple == 2
|
||||
doAssert ().lenTuple == 0
|
||||
doAssert (1,).lenTuple == 1
|
||||
doAssert (int,).lenTuple == 1
|
||||
doAssert type(x).lenTuple == 2
|
||||
doAssert type(x).default.lenTuple == 2
|
||||
doAssert x.tupleLen == 2
|
||||
doAssert ().tupleLen == 0
|
||||
doAssert (1,).tupleLen == 1
|
||||
doAssert (int,).tupleLen == 1
|
||||
doAssert type(x).tupleLen == 2
|
||||
doAssert type(x).default.tupleLen == 2
|
||||
type T1 = (int,float)
|
||||
type T2 = T1
|
||||
doAssert T2.lenTuple == 2
|
||||
doAssert T2.tupleLen == 2
|
||||
|
||||
block genericParams:
|
||||
type Foo[T1, T2]=object
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
discard """
|
||||
output: '''
|
||||
tlenvarargs.nim:35:9 (1, 2)
|
||||
tlenvarargs.nim:36:9 12
|
||||
tlenvarargs.nim:37:9 1
|
||||
tlenvarargs.nim:38:8
|
||||
tvarargslen.nim:35:9 (1, 2)
|
||||
tvarargslen.nim:36:9 12
|
||||
tvarargslen.nim:37:9 1
|
||||
tvarargslen.nim:38:8
|
||||
done
|
||||
'''
|
||||
"""
|
||||
|
|
@ -14,19 +14,19 @@ template myecho*(a: varargs[untyped]) =
|
|||
## on macros.nim) so can be used in more contexts
|
||||
const info = instantiationInfo(-1, false)
|
||||
const loc = info.filename & ":" & $info.line & ":" & $info.column & " "
|
||||
when lenVarargs(a) > 0:
|
||||
when varargsLen(a) > 0:
|
||||
echo(loc, a)
|
||||
else:
|
||||
echo(loc)
|
||||
|
||||
template fun*(a: varargs[untyped]): untyped =
|
||||
lenVarargs(a)
|
||||
varargsLen(a)
|
||||
|
||||
template fun2*(a: varargs[typed]): untyped =
|
||||
a.lenVarargs
|
||||
a.varargsLen
|
||||
|
||||
template fun3*(a: varargs[int]): untyped =
|
||||
a.lenVarargs
|
||||
a.varargsLen
|
||||
|
||||
template fun4*(a: varargs[untyped]): untyped =
|
||||
len(a)
|
||||
|
|
@ -49,11 +49,12 @@ proc main()=
|
|||
doAssert fun3(10) == 1
|
||||
doAssert fun3(10, 11) == 2
|
||||
|
||||
## shows why `lenVarargs` can't be named `len`
|
||||
## shows why `varargsLen` can't be named `len`
|
||||
doAssert fun4("abcdef") == len("abcdef")
|
||||
|
||||
## workaround for BUG:D20191218T171447 whereby if testament expected output ends
|
||||
## in space, testament strips it from expected output but not actual output,
|
||||
## which leads to a mismatch when running test via megatest
|
||||
echo "done"
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue