You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.3 KiB

8 years ago
  1. describe('requires-port', function () {
  2. 'use strict';
  3. var assume = require('assume')
  4. , required = require('./');
  5. it('is exported as a function', function () {
  6. assume(required).is.a('function');
  7. });
  8. it('does not require empty ports', function () {
  9. assume(required('', 'http')).false();
  10. assume(required('', 'wss')).false();
  11. assume(required('', 'ws')).false();
  12. assume(required('', 'cowsack')).false();
  13. });
  14. it('assumes true for unknown protocols',function () {
  15. assume(required('808', 'foo')).true();
  16. assume(required('80', 'bar')).true();
  17. });
  18. it('never requires port numbers for file', function () {
  19. assume(required(8080, 'file')).false();
  20. });
  21. it('does not require port 80 for http', function () {
  22. assume(required('80', 'http')).false();
  23. assume(required(80, 'http')).false();
  24. assume(required(80, 'http://')).false();
  25. assume(required(80, 'http://www.google.com')).false();
  26. assume(required('8080', 'http')).true();
  27. assume(required(8080, 'http')).true();
  28. assume(required(8080, 'http://')).true();
  29. assume(required(8080, 'http://www.google.com')).true();
  30. });
  31. it('does not require port 80 for ws', function () {
  32. assume(required('80', 'ws')).false();
  33. assume(required(80, 'ws')).false();
  34. assume(required(80, 'ws://')).false();
  35. assume(required(80, 'ws://www.google.com')).false();
  36. assume(required('8080', 'ws')).true();
  37. assume(required(8080, 'ws')).true();
  38. assume(required(8080, 'ws://')).true();
  39. assume(required(8080, 'ws://www.google.com')).true();
  40. });
  41. it('does not require port 443 for https', function () {
  42. assume(required('443', 'https')).false();
  43. assume(required(443, 'https')).false();
  44. assume(required(443, 'https://')).false();
  45. assume(required(443, 'https://www.google.com')).false();
  46. assume(required('8080', 'https')).true();
  47. assume(required(8080, 'https')).true();
  48. assume(required(8080, 'https://')).true();
  49. assume(required(8080, 'https://www.google.com')).true();
  50. });
  51. it('does not require port 443 for wss', function () {
  52. assume(required('443', 'wss')).false();
  53. assume(required(443, 'wss')).false();
  54. assume(required(443, 'wss://')).false();
  55. assume(required(443, 'wss://www.google.com')).false();
  56. assume(required('8080', 'wss')).true();
  57. assume(required(8080, 'wss')).true();
  58. assume(required(8080, 'wss://')).true();
  59. assume(required(8080, 'wss://www.google.com')).true();
  60. });
  61. it('does not require port 21 for ftp', function () {
  62. assume(required('21', 'ftp')).false();
  63. assume(required(21, 'ftp')).false();
  64. assume(required(21, 'ftp://')).false();
  65. assume(required(21, 'ftp://www.google.com')).false();
  66. assume(required('8080', 'ftp')).true();
  67. assume(required(8080, 'ftp')).true();
  68. assume(required(8080, 'ftp://')).true();
  69. assume(required(8080, 'ftp://www.google.com')).true();
  70. });
  71. it('does not require port 70 for gopher', function () {
  72. assume(required('70', 'gopher')).false();
  73. assume(required(70, 'gopher')).false();
  74. assume(required(70, 'gopher://')).false();
  75. assume(required(70, 'gopher://www.google.com')).false();
  76. assume(required('8080', 'gopher')).true();
  77. assume(required(8080, 'gopher')).true();
  78. assume(required(8080, 'gopher://')).true();
  79. assume(required(8080, 'gopher://www.google.com')).true();
  80. });
  81. });