Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
e92883466a
38 changed files with 339 additions and 106 deletions
|
|
@ -4,7 +4,7 @@ discard """
|
|||
3
|
||||
@[(Field0: 1, Field1: 2), (Field0: 3, Field1: 5)]
|
||||
2
|
||||
@[a, new one, c]
|
||||
@["a", "new one", "c"]
|
||||
@[1, 2, 3]'''
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
cmd: "nim c -r -d:fulldebug -d:smokeCycles --gc:refc $file"
|
||||
output: '''@[a]'''
|
||||
output: '''@["a"]'''
|
||||
"""
|
||||
|
||||
# bug #6279
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ discard """
|
|||
0
|
||||
0
|
||||
0
|
||||
x = [a, b, c, 0, 1, 2, 3, 4, 5, 6] and y = [a, b, c, 0, 1, 2, 3, 4, 5, 6]'''
|
||||
x = ['a', 'b', 'c', '0', '1', '2', '3', '4', '5', '6'] and y = ['a', 'b', 'c', '0', '1', '2', '3', '4', '5', '6']'''
|
||||
"""
|
||||
|
||||
proc `1/1`() = echo(1 div 1)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: '''(FirstName: James, LastName: Franco)'''
|
||||
output: '''(FirstName: "James", LastName: "Franco")'''
|
||||
"""
|
||||
|
||||
# bug #1547
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: "@[(username: user, role: admin, description: desc, email_addr: email), (username: user, role: admin, description: desc, email_addr: email)]"
|
||||
output: '''@[(username: "user", role: "admin", description: "desc", email_addr: "email"), (username: "user", role: "admin", description: "desc", email_addr: "email")]'''
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
|
|||
106
tests/collections/tcollections_to_string.nim
Normal file
106
tests/collections/tcollections_to_string.nim
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
discard """
|
||||
exitcode: 0
|
||||
output: ""
|
||||
"""
|
||||
import sets
|
||||
import tables
|
||||
import deques
|
||||
import lists
|
||||
import critbits
|
||||
|
||||
# Tests for tuples
|
||||
doAssert $(1, 2, 3) == "(Field0: 1, Field1: 2, Field2: 3)"
|
||||
doAssert $("1", "2", "3") == """(Field0: "1", Field1: "2", Field2: "3")"""
|
||||
doAssert $('1', '2', '3') == """(Field0: '1', Field1: '2', Field2: '3')"""
|
||||
|
||||
# Tests for seqs
|
||||
doAssert $(@[1, 2, 3]) == "@[1, 2, 3]"
|
||||
doAssert $(@["1", "2", "3"]) == """@["1", "2", "3"]"""
|
||||
doAssert $(@['1', '2', '3']) == """@['1', '2', '3']"""
|
||||
|
||||
# Tests for sets
|
||||
doAssert $(toSet([1])) == "{1}"
|
||||
doAssert $(toSet(["1"])) == """{"1"}"""
|
||||
doAssert $(toSet(['1'])) == """{'1'}"""
|
||||
doAssert $(toOrderedSet([1, 2, 3])) == "{1, 2, 3}"
|
||||
doAssert $(toOrderedSet(["1", "2", "3"])) == """{"1", "2", "3"}"""
|
||||
doAssert $(toOrderedSet(['1', '2', '3'])) == """{'1', '2', '3'}"""
|
||||
|
||||
# Tests for tables
|
||||
doAssert $({1: "1", 2: "2"}.toTable) == """{1: "1", 2: "2"}"""
|
||||
doAssert $({"1": 1, "2": 2}.toTable) == """{"1": 1, "2": 2}"""
|
||||
|
||||
# Tests for deques
|
||||
block:
|
||||
var d = initDeque[int]()
|
||||
d.addLast(1)
|
||||
doAssert $d == "[1]"
|
||||
block:
|
||||
var d = initDeque[string]()
|
||||
d.addLast("1")
|
||||
doAssert $d == """["1"]"""
|
||||
block:
|
||||
var d = initDeque[char]()
|
||||
d.addLast('1')
|
||||
doAssert $d == "['1']"
|
||||
|
||||
# Tests for lists
|
||||
block:
|
||||
var l = initDoublyLinkedList[int]()
|
||||
l.append(1)
|
||||
l.append(2)
|
||||
l.append(3)
|
||||
doAssert $l == "[1, 2, 3]"
|
||||
block:
|
||||
var l = initDoublyLinkedList[string]()
|
||||
l.append("1")
|
||||
l.append("2")
|
||||
l.append("3")
|
||||
doAssert $l == """["1", "2", "3"]"""
|
||||
block:
|
||||
var l = initDoublyLinkedList[char]()
|
||||
l.append('1')
|
||||
l.append('2')
|
||||
l.append('3')
|
||||
doAssert $l == """['1', '2', '3']"""
|
||||
|
||||
# Tests for critbits
|
||||
block:
|
||||
var t: CritBitTree[int]
|
||||
t["a"] = 1
|
||||
doAssert $t == "{a: 1}"
|
||||
block:
|
||||
var t: CritBitTree[string]
|
||||
t["a"] = "1"
|
||||
doAssert $t == """{a: "1"}"""
|
||||
block:
|
||||
var t: CritBitTree[char]
|
||||
t["a"] = '1'
|
||||
doAssert $t == "{a: '1'}"
|
||||
|
||||
|
||||
# Test escaping behavior
|
||||
block:
|
||||
var s = ""
|
||||
s.addQuoted('\0')
|
||||
s.addQuoted('\31')
|
||||
s.addQuoted('\127')
|
||||
s.addQuoted('\255')
|
||||
doAssert s == "'\\x00''\\x1F''\\x7F''\\xFF'"
|
||||
block:
|
||||
var s = ""
|
||||
s.addQuoted('\\')
|
||||
s.addQuoted('\'')
|
||||
s.addQuoted('\"')
|
||||
doAssert s == """'\\''\'''\"'"""
|
||||
|
||||
# Test customized element representation
|
||||
type CustomString = object
|
||||
|
||||
proc addQuoted(s: var string, x: CustomString) =
|
||||
s.add("<CustomString>")
|
||||
|
||||
block:
|
||||
let s = @[CustomString()]
|
||||
doAssert $s == "@[<CustomString>]"
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ block tableTest1:
|
|||
for y in 0..1:
|
||||
assert t[(x,y)] == $x & $y
|
||||
assert($t ==
|
||||
"{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}")
|
||||
"{(x: 0, y: 1): \"01\", (x: 0, y: 0): \"00\", (x: 1, y: 0): \"10\", (x: 1, y: 1): \"11\"}")
|
||||
|
||||
block tableTest2:
|
||||
var t = initTable[string, float]()
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ block tableTest1:
|
|||
for y in 0..1:
|
||||
assert t[(x,y)] == $x & $y
|
||||
assert($t ==
|
||||
"{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}")
|
||||
"{(x: 0, y: 1): \"01\", (x: 0, y: 0): \"00\", (x: 1, y: 0): \"10\", (x: 1, y: 1): \"11\"}")
|
||||
|
||||
block tableTest2:
|
||||
var t = newTable[string, float]()
|
||||
|
|
@ -139,7 +139,7 @@ proc orderedTableSortTest() =
|
|||
block anonZipTest:
|
||||
let keys = @['a','b','c']
|
||||
let values = @[1, 2, 3]
|
||||
doAssert "{a: 1, b: 2, c: 3}" == $ toTable zip(keys, values)
|
||||
doAssert "{'a': 1, 'b': 2, 'c': 3}" == $ toTable zip(keys, values)
|
||||
|
||||
block clearTableTest:
|
||||
var t = newTable[string, float]()
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ but expected one of:
|
|||
proc test(foo: Foo[int])
|
||||
t3330.nim(25, 8) Hint: Non-matching candidates for add(k, string, T)
|
||||
proc add(x: var string; y: string)
|
||||
proc add(result: var string; x: float)
|
||||
proc add(x: var string; y: char)
|
||||
proc add(result: var string; x: int64)
|
||||
proc add(x: var string; y: cstring)
|
||||
proc add(result: var string; x: float)
|
||||
proc add[T](x: var seq[T]; y: openArray[T])
|
||||
proc add[T](x: var seq[T]; y: T)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
output: '''24
|
||||
(bar: bar)
|
||||
(bar: "bar")
|
||||
1244
|
||||
6
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: '''(foo: 38, other: string here)
|
||||
output: '''(foo: 38, other: "string here")
|
||||
43
|
||||
100
|
||||
90'''
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
output: '''
|
||||
(Field0: 10, Field1: (Field0: test, Field1: 1.2))
|
||||
(Field0: 10, Field1: (Field0: "test", Field1: 1.2))
|
||||
3x3 Matrix [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0], [2.0, 0.0, 5.0]]
|
||||
|
||||
2x3 Matrix [[0.0, 2.0, 3.0], [2.0, 0.0, 5.0]]
|
||||
|
|
@ -43,7 +43,7 @@ type
|
|||
|
||||
Matrix*[M: static[int]; N: static[int]; T] =
|
||||
Vector[M, Vector[N, T]]
|
||||
|
||||
|
||||
proc arrayTest =
|
||||
# every kind of square matrix works just fine
|
||||
let mat_good: Matrix[3, 3, float] = [[0.0, 2.0, 3.0],
|
||||
|
|
|
|||
|
|
@ -66,4 +66,4 @@ proc initTypeA1(a: int; b: string; c: pointer = nil): TypeA1 =
|
|||
result.c_impl = c
|
||||
|
||||
let x = initTypeA1(1, "a")
|
||||
doAssert($x == "(a_impl: 1, b_impl: a, c_impl: ...)")
|
||||
doAssert($x == "(a_impl: 1, b_impl: \"a\", c_impl: ...)")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: "(x: a)"
|
||||
output: '''(x: 'a')'''
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: "(x: string here, a: 1)"
|
||||
output: '''(x: "string here", a: 1)'''
|
||||
"""
|
||||
|
||||
proc simple[T](a: T) =
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
discard """
|
||||
output: '''(k: kindA, a: (x: abc, z: [1, 1, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 2, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 3, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 4, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 5, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 6, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 7, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 8, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 9, 3]), method: ())
|
||||
(k: kindA, a: (x: abc, z: [1, 10, 3]), method: ())
|
||||
output: '''(k: kindA, a: (x: "abc", z: [1, 1, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 2, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 3, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 4, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 5, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 6, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 7, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 8, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 9, 3]), method: ())
|
||||
(k: kindA, a: (x: "abc", z: [1, 10, 3]), method: ())
|
||||
(x: 123)
|
||||
(x: 123)
|
||||
(z: 89, y: 0, x: 128)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: '''(a: 3, b: 4, s: abc)'''
|
||||
output: '''(a: 3, b: 4, s: "abc")'''
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ block SinglyLinkedListTest1:
|
|||
block SinglyLinkedListTest2:
|
||||
var L: TSinglyLinkedList[string]
|
||||
for d in items(data): L.prepend($d)
|
||||
assert($L == "[6, 5, 4, 3, 2, 1]")
|
||||
assert($L == """["6", "5", "4", "3", "2", "1"]""")
|
||||
|
||||
assert("4" in L)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: "@[(, +, 1, 2, )]"
|
||||
output: '''@["(", "+", " 1", " 2", ")"]'''
|
||||
"""
|
||||
|
||||
import re
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ discard """
|
|||
|
||||
doAssert "@[23, 45]" == $(@[23, 45])
|
||||
doAssert "[32, 45]" == $([32, 45])
|
||||
doAssert "@[, foo, bar]" == $(@["", "foo", "bar"])
|
||||
doAssert "[, foo, bar]" == $(["", "foo", "bar"])
|
||||
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
|
||||
doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
|
||||
|
||||
# bug #2395
|
||||
let alphaSet: set[char] = {'a'..'c'}
|
||||
doAssert "{a, b, c}" == $alphaSet
|
||||
doAssert "{'a', 'b', 'c'}" == $alphaSet
|
||||
doAssert "2.3242" == $(2.3242)
|
||||
doAssert "2.982" == $(2.982)
|
||||
doAssert "123912.1" == $(123912.1)
|
||||
|
|
@ -49,5 +49,5 @@ import strutils
|
|||
# array test
|
||||
|
||||
let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
|
||||
doAssert $arr == "[H, e, l, l, o, , W, o, r, l, d, !, \0]"
|
||||
doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\\x00']"
|
||||
doAssert $cstring(unsafeAddr arr) == "Hello World!"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: '''@[a, c]'''
|
||||
output: '''@["a", "c"]'''
|
||||
"""
|
||||
|
||||
# bug #3230
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
output: '''(c: hello, a: 10, b: 12.0)
|
||||
(a: 15.5, b: hello)
|
||||
output: '''(c: "hello", a: 10, b: 12.0)
|
||||
(a: 15.5, b: "hello")
|
||||
(a: 11.75, b: 123)'''
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ discard """
|
|||
output: '''(width: 11, color: 13)
|
||||
(width: 15, weight: 13, taste: 11, color: 14)
|
||||
(width: 17, color: 16)
|
||||
(width: 12.0, taste: yummy, color: 13)
|
||||
(width: 12.0, taste: "yummy", color: 13)
|
||||
(width: 0, tast_e: 0.0, kind: Smooth, skin: 1.5, color: 12)'''
|
||||
"""
|
||||
# bug #5264
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ discard """
|
|||
nimout: '''0
|
||||
0
|
||||
0
|
||||
{hallo: 123, welt: 456}'''
|
||||
{"hallo": "123", "welt": "456"}'''
|
||||
"""
|
||||
|
||||
import tables
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
output: '''(name: hello)
|
||||
output: '''(name: "hello")
|
||||
(-1, 0)'''
|
||||
"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue