diff options
author | Daniil Yarancev <21169548+Yardanico@users.noreply.github.com> | 2018-06-05 21:25:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-05 21:25:45 +0300 |
commit | 642641359821b6a63c6cf7edaaa45873b7ea59c7 (patch) | |
tree | 627af3020528cb916b3174bd94304307ca875c77 /tests/tuples | |
parent | fb44c522e6173528efa8035ecc459c84887d0167 (diff) | |
parent | 3cbc07ac7877b03c605498760fe198e3200cc197 (diff) | |
download | Nim-642641359821b6a63c6cf7edaaa45873b7ea59c7.tar.gz |
Merge pull request #2 from nim-lang/devel
Update
Diffstat (limited to 'tests/tuples')
-rw-r--r-- | tests/tuples/tanontuples.nim | 14 | ||||
-rw-r--r-- | tests/tuples/tuple_with_nil.nim | 8 |
2 files changed, 17 insertions, 5 deletions
diff --git a/tests/tuples/tanontuples.nim b/tests/tuples/tanontuples.nim index 49803e5ac..f514670d3 100644 --- a/tests/tuples/tanontuples.nim +++ b/tests/tuples/tanontuples.nim @@ -1,7 +1,10 @@ discard """ - output: '''61, 125''' + output: '''61, 125 +(Field0: 0) (Field0: 13)''' """ +import macros + proc `^` (a, b: int): int = result = 1 for i in 1..b: result = result * a @@ -12,3 +15,12 @@ var n = (56, 3) m = (n[0] + m[1], m[1] ^ n[1]) echo m[0], ", ", m[1] + +# also test we can produce unary anon tuples in a macro: +macro mm(): untyped = + result = newTree(nnkTupleConstr, newLit(13)) + +proc nowTuple(): (int,) = + result = (0,) + +echo nowTuple(), " ", mm() diff --git a/tests/tuples/tuple_with_nil.nim b/tests/tuples/tuple_with_nil.nim index eb265f420..ec48337bd 100644 --- a/tests/tuples/tuple_with_nil.nim +++ b/tests/tuples/tuple_with_nil.nim @@ -353,7 +353,7 @@ proc writeformat(o: var Writer; p: pointer; fmt: Format) = f.baseprefix = true writeformat(o, add, cast[uint](p), f) -proc writeformat(o: var Writer; x: SomeReal; fmt: Format) = +proc writeformat(o: var Writer; x: SomeFloat; fmt: Format) = ## Write real number `x` according to format `fmt` using output ## object `o` and output function `add`. var fmt = fmt @@ -401,8 +401,8 @@ proc writeformat(o: var Writer; x: SomeReal; fmt: Format) = else: len += 4 # exponent # shift y so that 1 <= abs(y) < 2 - if exp > 0: y /= pow(10.SomeReal, abs(exp).SomeReal) - elif exp < 0: y *= pow(10.SomeReal, abs(exp).SomeReal) + if exp > 0: y /= pow(10.SomeFloat, abs(exp).SomeFloat) + elif exp < 0: y *= pow(10.SomeFloat, abs(exp).SomeFloat) elif fmt.typ == ftPercent: len += 1 # percent sign @@ -413,7 +413,7 @@ proc writeformat(o: var Writer; x: SomeReal; fmt: Format) = var mult = 1'i64 for i in 1..prec: mult *= 10 var num = y.int64 - var fr = ((y - num.SomeReal) * mult.SomeReal).int64 + var fr = ((y - num.SomeFloat) * mult.SomeFloat).int64 # build integer part string while num != 0: numstr[numlen] = ('0'.int + (num mod 10)).char |