test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var assert = require('better-assert');
  2. var expect = require('expect.js');
  3. var parseuri = require('./index.js');
  4. describe('my suite', function(){
  5. it('should parse an uri', function () {
  6. var http = parseuri('http://google.com')
  7. , https = parseuri('https://www.google.com:80')
  8. , query = parseuri('google.com:8080/foo/bar?foo=bar')
  9. , localhost = parseuri('localhost:8080')
  10. , ipv6 = parseuri('2001:0db8:85a3:0042:1000:8a2e:0370:7334')
  11. , ipv6short = parseuri('2001:db8:85a3:42:1000:8a2e:370:7334')
  12. , ipv6port = parseuri('2001:db8:85a3:42:1000:8a2e:370:7334:80')
  13. , ipv6abbrev = parseuri('2001::7334:a:80')
  14. , ipv6http = parseuri('http://[2001::7334:a]:80')
  15. , ipv6query = parseuri('http://[2001::7334:a]:80/foo/bar?foo=bar')
  16. expect(http.protocol).to.be('http');
  17. expect(http.port).to.be('');
  18. expect(http.host).to.be('google.com');
  19. expect(https.protocol).to.be('https');
  20. expect(https.port).to.be('80');
  21. expect(https.host).to.be('www.google.com');
  22. expect(query.port).to.be('8080');
  23. expect(query.query).to.be('foo=bar');
  24. expect(query.path).to.be('/foo/bar');
  25. expect(query.relative).to.be('/foo/bar?foo=bar');
  26. expect(query.queryKey.foo).to.be('bar');
  27. expect(query.pathNames[0]).to.be('foo');
  28. expect(query.pathNames[1]).to.be('bar');
  29. expect(localhost.protocol).to.be('');
  30. expect(localhost.host).to.be('localhost');
  31. expect(localhost.port).to.be('8080');
  32. expect(ipv6.protocol).to.be('');
  33. expect(ipv6.host).to.be('2001:0db8:85a3:0042:1000:8a2e:0370:7334');
  34. expect(ipv6.port).to.be('');
  35. expect(ipv6short.protocol).to.be('');
  36. expect(ipv6short.host).to.be('2001:db8:85a3:42:1000:8a2e:370:7334');
  37. expect(ipv6short.port).to.be('');
  38. expect(ipv6port.protocol).to.be('');
  39. expect(ipv6port.host).to.be('2001:db8:85a3:42:1000:8a2e:370:7334');
  40. expect(ipv6port.port).to.be('80');
  41. expect(ipv6abbrev.protocol).to.be('');
  42. expect(ipv6abbrev.host).to.be('2001::7334:a:80');
  43. expect(ipv6abbrev.port).to.be('');
  44. expect(ipv6http.protocol).to.be('http');
  45. expect(ipv6http.port).to.be('80');
  46. expect(ipv6http.host).to.be('2001::7334:a');
  47. expect(ipv6query.protocol).to.be('http');
  48. expect(ipv6query.port).to.be('80');
  49. expect(ipv6query.host).to.be('2001::7334:a');
  50. expect(ipv6query.relative).to.be('/foo/bar?foo=bar');
  51. });
  52. });