mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
* 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>
33 lines
658 B
Nim
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")
|