tcstrutils.nim 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. import std/cstrutils
  5. proc main() =
  6. let s = cstring "abcdef"
  7. doAssert s.startsWith("a")
  8. doAssert not s.startsWith("b")
  9. doAssert s.endsWith("f")
  10. doAssert not s.endsWith("a")
  11. doAssert s.startsWith("")
  12. doAssert s.endsWith("")
  13. let a = cstring "abracadabra"
  14. doAssert a.startsWith("abra")
  15. doAssert not a.startsWith("bra")
  16. doAssert a.endsWith("abra")
  17. doAssert not a.endsWith("dab")
  18. doAssert a.startsWith("")
  19. doAssert a.endsWith("")
  20. doAssert cmpIgnoreCase(cstring "FooBar", "foobar") == 0
  21. doAssert cmpIgnoreCase(cstring "bar", "Foo") < 0
  22. doAssert cmpIgnoreCase(cstring "Foo5", "foo4") > 0
  23. doAssert cmpIgnoreStyle(cstring "foo_bar", "FooBar") == 0
  24. doAssert cmpIgnoreStyle(cstring "foo_bar_5", "FooBar4") > 0
  25. doAssert cmpIgnoreCase(cstring "", cstring "") == 0
  26. doAssert cmpIgnoreCase(cstring "", cstring "Hello") < 0
  27. doAssert cmpIgnoreCase(cstring "wind", cstring "") > 0
  28. static: main()
  29. main()