summary refs log tree commit diff stats
path: root/tests/sets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sets')
-rw-r--r--tests/sets/trangeincompatible.nim32
-rw-r--r--tests/sets/twrongenumrange.nim5
2 files changed, 34 insertions, 3 deletions
diff --git a/tests/sets/trangeincompatible.nim b/tests/sets/trangeincompatible.nim
new file mode 100644
index 000000000..554a50235
--- /dev/null
+++ b/tests/sets/trangeincompatible.nim
@@ -0,0 +1,32 @@
+block: # issue #20142
+  let
+    s1: set['a' .. 'g'] = {'a', 'e'}
+    s2: set['a' .. 'g'] = {'b', 'c', 'd', 'f'} # this works fine
+    s3 = {'b', 'c', 'd', 'f'}
+
+  doAssert s1 != s2
+  doAssert s1 == {range['a'..'g'] 'a', 'e'}
+  doAssert s2 == {range['a'..'g'] 'b', 'c', 'd', 'f'}
+  # literal conversion:
+  doAssert s1 == {'a', 'e'}
+  doAssert s2 == {'b', 'c', 'd', 'f'}
+  doAssert s3 == {'b', 'c', 'd', 'f'}
+  doAssert not compiles(s1 == s3)
+  doAssert not compiles(s2 == s3)
+  # can't convert literal 'z', overload match fails
+  doAssert not compiles(s1 == {'a', 'z'})
+
+block: # issue #18396
+  var s1: set[char] = {'a', 'b'}
+  var s2: set['a'..'z'] = {'a', 'b'}
+  doAssert s1 == {'a', 'b'}
+  doAssert s2 == {range['a'..'z'] 'a', 'b'}
+  doAssert s2 == {'a', 'b'}
+  doAssert not compiles(s1 == s2)
+
+block: # issue #16270
+  var s1: set[char] = {'a', 'b'}
+  var s2: set['a'..'z'] = {'a', 'c'}
+  doAssert not (compiles do: s2 = s2 + s1)
+  s2 = s2 + {'a', 'b'}
+  doAssert s2 == {'a', 'b', 'c'}
diff --git a/tests/sets/twrongenumrange.nim b/tests/sets/twrongenumrange.nim
index fc90c142f..a8d64ac44 100644
--- a/tests/sets/twrongenumrange.nim
+++ b/tests/sets/twrongenumrange.nim
@@ -45,7 +45,6 @@ block:
     TNoteKind = range[k1..k2]
   var notes: set[TNoteKind]
   notes = {k0} #[tt.Error
-           ^ cannot convert 'k0' to 'TNoteKind = range 1..2(TMsgKind)]#
+          ^ type mismatch: got <set[TMsgKind]> but expected 'set[TNoteKind]']#
   notes = {k0..k3} #[tt.Error
-           ^ cannot convert 'k0' to 'TNoteKind = range 1..2(TMsgKind)'; tt.Error
-               ^ cannot convert 'k3' to 'TNoteKind = range 1..2(TMsgKind)']#
+          ^ type mismatch: got <set[TMsgKind]> but expected 'set[TNoteKind]']#