Files
Nim/tests/compiler/tprefixmatches.nim
Arne Döring 159c06e045 unify tuple expressions (#13793)
* unify tuple expressions

* fix test

* fix test

* apply feedback

* Handle empty tuples

* Fix rendering named unary tuple

* Protect static NimNode against stripping

* Slightly less hacky

* Revert "Slightly less hacky"

This reverts commit 170c5aec0addc029f637afbc948700ca006b7942.

* Slightly less hacky

* Cleanup

* Fix test

* Fix another test

* Add condsym

* Rebase fallout

* changelog: Move from compiler changes to language changes

* Add stricter tests

* Add empty tuple example to doc/astspec

* Fix test

Co-authored-by: Clyybber <darkmine956@gmail.com>
2021-03-30 02:06:51 +02:00

33 lines
658 B
Nim

import compiler/prefixmatches
import macros
macro check(val, body: untyped): untyped =
result = newStmtList()
expectKind body, nnkStmtList
for b in body:
expectKind b, nnkTupleConstr
expectLen b, 2
let p = b[0]
let s = b[1]
result.add quote do:
doAssert prefixMatch(`p`, `s`) == `val`
check PrefixMatch.Prefix:
("abc", "abc")
("a", "abc")
("xyz", "X_yzzzZe")
check PrefixMatch.Substr:
("b", "abc")
("abc", "fooabcabc")
("abC", "foo_AB_c")
check PrefixMatch.Abbrev:
("abc", "AxxxBxxxCxxx")
("xyz", "X_yabcZe")
check PrefixMatch.None:
("foobar", "afkslfjd_as")
("xyz", "X_yuuZuuZe")
("ru", "remotes")