tprefixmatches.nim 658 B

123456789101112131415161718192021222324252627282930313233
  1. import compiler/prefixmatches
  2. import macros
  3. macro check(val, body: untyped): untyped =
  4. result = newStmtList()
  5. expectKind body, nnkStmtList
  6. for b in body:
  7. expectKind b, nnkTupleConstr
  8. expectLen b, 2
  9. let p = b[0]
  10. let s = b[1]
  11. result.add quote do:
  12. doAssert prefixMatch(`p`, `s`) == `val`
  13. check PrefixMatch.Prefix:
  14. ("abc", "abc")
  15. ("a", "abc")
  16. ("xyz", "X_yzzzZe")
  17. check PrefixMatch.Substr:
  18. ("b", "abc")
  19. ("abc", "fooabcabc")
  20. ("abC", "foo_AB_c")
  21. check PrefixMatch.Abbrev:
  22. ("abc", "AxxxBxxxCxxx")
  23. ("xyz", "X_yabcZe")
  24. check PrefixMatch.None:
  25. ("foobar", "afkslfjd_as")
  26. ("xyz", "X_yuuZuuZe")
  27. ("ru", "remotes")