t18616.nim 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. discard """
  2. matrix: "--mm:refc; --mm:arc"
  3. joinable: false
  4. """
  5. import std/[unittest, asyncdispatch]
  6. # bug #18616
  7. type
  8. ClientResponse = object
  9. status*: int
  10. data*: string
  11. template asyncTest*(name: string, body: untyped): untyped =
  12. test name:
  13. waitFor((
  14. proc() {.async, gcsafe.} =
  15. body
  16. )())
  17. suite "Test suite":
  18. asyncTest "test1":
  19. const PostVectors = [
  20. (
  21. ("/test/post", "somebody0908", "text/html",
  22. "app/type1;q=0.9,app/type2;q=0.8"),
  23. ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
  24. ),
  25. (
  26. ("/test/post", "somebody0908", "text/html",
  27. "app/type2;q=0.8,app/type1;q=0.9"),
  28. ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
  29. ),
  30. (
  31. ("/test/post", "somebody09", "text/html",
  32. "app/type2,app/type1;q=0.9"),
  33. ClientResponse(status: 200, data: "type2[text/html,somebody09]")
  34. ),
  35. (
  36. ("/test/post", "somebody09", "text/html", "app/type1;q=0.9,app/type2"),
  37. ClientResponse(status: 200, data: "type2[text/html,somebody09]")
  38. ),
  39. (
  40. ("/test/post", "somebody", "text/html", "*/*"),
  41. ClientResponse(status: 200, data: "type1[text/html,somebody]")
  42. ),
  43. (
  44. ("/test/post", "somebody", "text/html", ""),
  45. ClientResponse(status: 200, data: "type1[text/html,somebody]")
  46. ),
  47. (
  48. ("/test/post", "somebody", "text/html", "app/type2"),
  49. ClientResponse(status: 200, data: "type2[text/html,somebody]")
  50. ),
  51. (
  52. ("/test/post", "somebody", "text/html", "app/type3"),
  53. ClientResponse(status: 406, data: "")
  54. )
  55. ]
  56. for item in PostVectors:
  57. discard item
  58. asyncTest "test2":
  59. const PostVectors = [
  60. (
  61. "/test/post", "somebody0908", "text/html",
  62. "app/type1;q=0.9,app/type2;q=0.8",
  63. ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
  64. ),
  65. (
  66. "/test/post", "somebody0908", "text/html",
  67. "app/type2;q=0.8,app/type1;q=0.9",
  68. ClientResponse(status: 200, data: "type1[text/html,somebody0908]")
  69. ),
  70. (
  71. "/test/post", "somebody09", "text/html",
  72. "app/type2,app/type1;q=0.9",
  73. ClientResponse(status: 200, data: "type2[text/html,somebody09]")
  74. ),
  75. (
  76. "/test/post", "somebody09", "text/html", "app/type1;q=0.9,app/type2",
  77. ClientResponse(status: 200, data: "type2[text/html,somebody09]")
  78. ),
  79. (
  80. "/test/post", "somebody", "text/html", "*/*",
  81. ClientResponse(status: 200, data: "type1[text/html,somebody]")
  82. ),
  83. (
  84. "/test/post", "somebody", "text/html", "",
  85. ClientResponse(status: 200, data: "type1[text/html,somebody]")
  86. ),
  87. (
  88. "/test/post", "somebody", "text/html", "app/type2",
  89. ClientResponse(status: 200, data: "type2[text/html,somebody]")
  90. ),
  91. (
  92. "/test/post", "somebody", "text/html", "app/type3",
  93. ClientResponse(status: 406, data: "")
  94. )
  95. ]
  96. for item in PostVectors:
  97. discard item