summary refs log tree commit diff stats
path: root/tests/constructors
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-06-06 07:54:07 +0300
committerGitHub <noreply@github.com>2023-06-06 06:54:07 +0200
commitb97d603cd00a210547bda1a2a1c3e09f97fcc49e (patch)
tree080b4ad7b5826b88a9483c6a0e4d697096f12cc1 /tests/constructors
parent2ab948ce53e3d9b80bf9b02644c8ec8991f34d0a (diff)
downloadNim-b97d603cd00a210547bda1a2a1c3e09f97fcc49e.tar.gz
some test cleanups & category reorganization (#22010)
* clean up some test categories

* mention exact slice issue

* magics into system

* move trangechecks into overflow

* move tmemory to system

* try fix CI

* try fix CI

* final CI fix
Diffstat (limited to 'tests/constructors')
-rw-r--r--tests/constructors/a.nim2
-rw-r--r--tests/constructors/b.nim2
-rw-r--r--tests/constructors/t18990.nim3
-rw-r--r--tests/constructors/tconstr1.nim28
-rw-r--r--tests/constructors/tconstr2.nim22
5 files changed, 57 insertions, 0 deletions
diff --git a/tests/constructors/a.nim b/tests/constructors/a.nim
new file mode 100644
index 000000000..03788fc57
--- /dev/null
+++ b/tests/constructors/a.nim
@@ -0,0 +1,2 @@
+type A* = object
+  a: uint8
\ No newline at end of file
diff --git a/tests/constructors/b.nim b/tests/constructors/b.nim
new file mode 100644
index 000000000..437dd0550
--- /dev/null
+++ b/tests/constructors/b.nim
@@ -0,0 +1,2 @@
+type B* = object
+proc A*(a, b: float): B = discard
\ No newline at end of file
diff --git a/tests/constructors/t18990.nim b/tests/constructors/t18990.nim
new file mode 100644
index 000000000..2f60f3c2c
--- /dev/null
+++ b/tests/constructors/t18990.nim
@@ -0,0 +1,3 @@
+import a, b
+discard A(1f, 1f) # works
+proc x(b = A(1f, 1f)) = discard # doesn't work
\ No newline at end of file
diff --git a/tests/constructors/tconstr1.nim b/tests/constructors/tconstr1.nim
new file mode 100644
index 000000000..a169bf453
--- /dev/null
+++ b/tests/constructors/tconstr1.nim
@@ -0,0 +1,28 @@
+discard """
+  errormsg: "type mismatch"
+  file: "tconstr1.nim"
+  line: 25
+"""
+# Test array, record constructors
+
+type
+  TComplexRecord = tuple[
+    s: string,
+    x, y: int,
+    z: float,
+    chars: set[char]]
+
+proc testSem =
+  var
+    things: array[0..1, TComplexRecord] = [
+      (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
+      (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
+  write(stdout, things[0].x)
+
+const
+  things: array[0..1, TComplexRecord] = [
+    (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
+    (s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
+  otherThings = [  # the same
+    (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
+    (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
diff --git a/tests/constructors/tconstr2.nim b/tests/constructors/tconstr2.nim
new file mode 100644
index 000000000..2557d7db9
--- /dev/null
+++ b/tests/constructors/tconstr2.nim
@@ -0,0 +1,22 @@
+discard """
+  output: "69"
+"""
+# Test array, record constructors
+
+type
+  TComplexRecord = tuple[
+    s: string,
+    x, y: int,
+    z: float,
+    chars: set[char]]
+
+const
+  things: array[0..1, TComplexRecord] = [
+    (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
+    (s: "hi", x: 69, y: 45, z: 1.0, chars: {})]
+  otherThings = [  # the same
+    (s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
+    (s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
+
+writeLine(stdout, things[0].x)
+#OUT 69