summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/sets/tsets2.nim12
-rw-r--r--tests/stdlib/tmarshal.nim2
-rw-r--r--tests/stdlib/tstrutil.nim12
-rw-r--r--tests/vm/tstring_openarray.nim34
4 files changed, 58 insertions, 2 deletions
diff --git a/tests/sets/tsets2.nim b/tests/sets/tsets2.nim
index 9c73dbe03..f28822840 100644
--- a/tests/sets/tsets2.nim
+++ b/tests/sets/tsets2.nim
@@ -37,16 +37,26 @@ block setTest2:
   t.incl("111")
   t.incl("123")
   t.excl("111")
-
   t.incl("012")
   t.incl("123") # test duplicates
 
   assert "123" in t
   assert "111" notin t # deleted
 
+  assert t.missingOrExcl("000") == true
+  assert "000" notin t
+  assert t.missingOrExcl("012") == false
+  assert "012" notin t
+
+  assert t.containsOrIncl("012") == false 
+  assert t.containsOrIncl("012") == true
+  assert "012" in t # added back 
+
   for key in items(data): t.incl(key)
   for key in items(data): assert key in t
 
+  for key in items(data): t.excl(key)
+  for key in items(data): assert key notin t
 
 block orderedSetTest1:
   var t = data.toOrderedSet
diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim
index 434caa281..38937590f 100644
--- a/tests/stdlib/tmarshal.nim
+++ b/tests/stdlib/tmarshal.nim
@@ -1,5 +1,5 @@
 discard """
-  output: '''{"age": 12, "bio": "\u042F Cletus", "blob": [65, 66, 67, 128], "name": "Cletus"}
+  output: '''{"age": 12, "bio": "Я Cletus", "blob": [65, 66, 67, 128], "name": "Cletus"}
 true
 true
 alpha 100
diff --git a/tests/stdlib/tstrutil.nim b/tests/stdlib/tstrutil.nim
index b5e3db4e2..fef1b38c2 100644
--- a/tests/stdlib/tstrutil.nim
+++ b/tests/stdlib/tstrutil.nim
@@ -89,9 +89,21 @@ proc testRFind =
   assert "0123456789ABCDEFGAH".rfind({'A'..'C'}, 13) == 12
   assert "0123456789ABCDEFGAH".rfind({'G'..'H'}, 13) == -1
 
+proc testCountLines =
+  proc assertCountLines(s: string) = assert s.countLines == s.splitLines.len
+  assertCountLines("")
+  assertCountLines("\n")
+  assertCountLines("\n\n")
+  assertCountLines("abc")
+  assertCountLines("abc\n123")
+  assertCountLines("abc\n123\n")
+  assertCountLines("\nabc\n123")
+  assertCountLines("\nabc\n123\n")
+
 testDelete()
 testFind()
 testRFind()
+testCountLines()
 
 assert(insertSep($1000_000) == "1_000_000")
 assert(insertSep($232) == "232")
diff --git a/tests/vm/tstring_openarray.nim b/tests/vm/tstring_openarray.nim
new file mode 100644
index 000000000..1b8a1304c
--- /dev/null
+++ b/tests/vm/tstring_openarray.nim
@@ -0,0 +1,34 @@
+
+# tests various bug when passing string to openArray argument in VM.
+# bug #6086
+proc map*[T, S](data: openArray[T], op: proc (x: T): S {.closure.}):
+                                                            seq[S]{.inline.} =
+# map inlined from sequtils
+  newSeq(result, data.len)
+  for i in 0..data.len-1: result[i] = op(data[i])
+
+
+proc set_all[T](s: var openArray[T]; val: T) =
+  for i in 0..<s.len:
+    s[i] = val
+
+proc test() =
+    var a0 = "hello_world"
+    var a1 = [1,2,3,4,5,6,7,8,9]
+    var a2 = @[1,2,3,4,5,6,7,8,9]
+    a0.set_all('i')
+    a1.set_all(4)
+    a2.set_all(4)
+    doAssert a0 == "iiiiiiiiiii"
+    doAssert a1 == [4,4,4,4,4,4,4,4,4]
+    doAssert a2 == @[4,4,4,4,4,4,4,4,4]
+
+const constval0 = "hello".map(proc(x: char): char = x)
+const constval1 = [1,2,3,4].map(proc(x: int): int = x)
+
+doAssert("hello".map(proc(x: char): char = x) == constval0)
+doAssert([1,2,3,4].map(proc(x: int): int = x) == constval1)
+
+test()
+static:
+    test()