summary refs log tree commit diff stats
path: root/tests/stdlib/twith.nim
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2020-11-28 03:47:49 +0800
committerGitHub <noreply@github.com>2020-11-27 20:47:49 +0100
commitbc1db0d6f163e4aba51f27b2a8cefd05476bd5e4 (patch)
tree48887ae1fd2a47553aa53f176adc14f7d1876ffc /tests/stdlib/twith.nim
parentc9a10bb9e47c5227b32f49f5876e965cc2308541 (diff)
downloadNim-bc1db0d6f163e4aba51f27b2a8cefd05476bd5e4.tar.gz
move rest of tests to testament (#16140)
* move rest of tests to testament
* Update tests/stdlib/tsums.nim
Diffstat (limited to 'tests/stdlib/twith.nim')
-rw-r--r--tests/stdlib/twith.nim23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/stdlib/twith.nim b/tests/stdlib/twith.nim
new file mode 100644
index 000000000..80382f7c4
--- /dev/null
+++ b/tests/stdlib/twith.nim
@@ -0,0 +1,23 @@
+import std/with
+
+type
+  Foo = object
+    col, pos: string
+    name: string
+
+proc setColor(f: var Foo; r, g, b: int) = f.col = $(r, g, b)
+proc setPosition(f: var Foo; x, y: float) = f.pos = $(x, y)
+
+var f: Foo
+with(f, setColor(2, 3, 4), setPosition(0.0, 1.0))
+doAssert f.col == "(2, 3, 4)"
+doAssert f.pos == "(0.0, 1.0)"
+
+f = Foo()
+with f:
+  col = $(2, 3, 4)
+  pos = $(0.0, 1.0)
+  _.name = "bar"
+doAssert f.col == "(2, 3, 4)"
+doAssert f.pos == "(0.0, 1.0)"
+doAssert f.name == "bar"