tcgi.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. """
  4. import std/unittest
  5. import std/[cgi, strtabs, sugar]
  6. import std/assertions
  7. block: # Test cgi module
  8. const queryString = "foo=bar&фу=бар&checked=✓&list=1,2,3&with_space=text%20with%20space"
  9. block: # test query parsing with readData
  10. let parsedQuery = readData(queryString)
  11. check parsedQuery["foo"] == "bar"
  12. check parsedQuery["фу"] == "бар"
  13. check parsedQuery["checked"] == "✓"
  14. check parsedQuery["list"] == "1,2,3"
  15. check parsedQuery["with_space"] == "text with space"
  16. expect KeyError:
  17. discard parsedQuery["not_existing_key"]
  18. # bug #15369
  19. let queryString = "a=1&b=0&c=3&d&e&a=5&a=t%20e%20x%20t&e=http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab"
  20. doAssert collect(for pair in decodeData(queryString): pair) ==
  21. @[("a", "1"), ("b", "0"), ("c", "3"),
  22. ("d", ""),("e", ""), ("a", "5"), ("a", "t e x t"),
  23. ("e", "http://w3schools.com/my test.asp?name=ståle&car=saab")
  24. ]