summary refs log tree commit diff stats
path: root/tests/misc
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-08-24 21:50:40 -0700
committerGitHub <noreply@github.com>2021-08-25 06:50:40 +0200
commit3aa16c1de00c723d48e48fe3fdf07a276d1b4b6a (patch)
treed4547a8ab662981357d06334bf46f935f18e65d4 /tests/misc
parent3d1bba04ab1092630983695734d6984ddff4688c (diff)
downloadNim-3aa16c1de00c723d48e48fe3fdf07a276d1b4b6a.tar.gz
fix RFC #341: dot-like operators are now parsed with same precedence as `.` (#18711)
* fix RFC #341: dot-like operators are now parsed with same precedence as `.`

* fixup

* [skip ci] address comment in changelog

* address comment

* update grammmar

* add manual entry

* fixup

* -d:nimPreviewDotLikeOps

* address comment to unblock PR: move nimPreviewDotLikeOps out of config/config.nims
Diffstat (limited to 'tests/misc')
-rw-r--r--tests/misc/trfc_341.nim27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/misc/trfc_341.nim b/tests/misc/trfc_341.nim
new file mode 100644
index 000000000..37cf675c6
--- /dev/null
+++ b/tests/misc/trfc_341.nim
@@ -0,0 +1,27 @@
+# test for https://github.com/nim-lang/RFCs/issues/341
+import std/json
+import std/jsonutils
+import std/macros
+
+macro fn1(a: untyped): string = newLit a.lispRepr
+
+doAssert fn1(a.?b.c) == """(DotExpr (Infix (Ident ".?") (Ident "a") (Ident "b")) (Ident "c"))"""
+
+template `.?`(a: JsonNode, b: untyped{ident}): JsonNode =
+  a[astToStr(b)]
+
+proc identity[T](a: T): T = a
+proc timesTwo[T](a: T): T = a * 2
+
+template main =
+  let a = (a1: 1, a2: "abc", a3: (a4: 2.5))
+  let j = a.toJson
+  doAssert j.?a1.getInt == 1
+  doAssert j.?a3.?a4.getFloat == 2.5
+  doAssert j.?a3.?a4.getFloat.timesTwo == 5.0
+  doAssert j.?a3.identity.?a4.getFloat.timesTwo == 5.0
+  doAssert j.identity.?a3.identity.?a4.identity.getFloat.timesTwo == 5.0
+  doAssert j.identity.?a3.?a4.identity.getFloat.timesTwo == 5.0
+
+static: main()
+main()