path-parsing.spec.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*global describe, context, it, helper */
  2. "use strict";
  3. require("./spec-helper");
  4. var Path = require("path");
  5. describe("gulp-rename path parsing", function () {
  6. describe("dirname", function () {
  7. context("when src pattern contains no globs", function () {
  8. it("dirname is '.'", function (done) {
  9. var srcPattern = "test/fixtures/hello.txt";
  10. var obj = function (path) {
  11. path.dirname.should.equal(".");
  12. };
  13. helper(srcPattern, obj, null, done);
  14. });
  15. });
  16. context("when src pattern contains filename glob", function () {
  17. it("dirname is '.'", function (done) {
  18. var srcPattern = "test/fixtures/*.min.txt";
  19. var obj = function (path) {
  20. path.dirname.should.equal(".");
  21. };
  22. helper(srcPattern, obj, null, done);
  23. });
  24. });
  25. var dirname_helper = function (srcPattern, expectedPath) {
  26. it("dirname is path from directory glob to file", function (done) {
  27. var obj = function (path) {
  28. path.dirname.should.match(/^fixtures[0-9]?$/);
  29. };
  30. helper(srcPattern, obj, null, done);
  31. });
  32. }
  33. context("when src pattern matches a directory with *", function () {
  34. dirname_helper("test/*/*.min.txt");
  35. });
  36. context("when src pattern matches a directory with **", function () {
  37. dirname_helper("test/**/*.min.txt");
  38. });
  39. context("when src pattern matches a directory with [...]", function () {
  40. dirname_helper("test/fixt[a-z]res/*.min.txt");
  41. });
  42. /* SKIP: glob2base does not handle brace expansion as expected. See wearefractal/glob2base#1 */
  43. context.skip("when src pattern matches a directory with {...,...}", function () {
  44. dirname_helper("test/f{ri,ixtur}es/*.min.txt");
  45. });
  46. /* SKIP: glob2base does not handle brace expansion as expected. See wearefractal/glob2base#1 */
  47. context.skip("when src pattern matches a directory with {#..#}", function () {
  48. dirname_helper("test/fixtures{0..9}/*.min.txt");
  49. });
  50. context("when src pattern matches a directory with an extglob", function () {
  51. dirname_helper("test/f+(ri|ixtur)es/*.min.txt");
  52. });
  53. /* requires glob-stream >= 3.1.0 */
  54. context.skip("when src pattern includes `base` option", function () {
  55. it("dirname is path from given directory to file", function (done) {
  56. var srcPattern = "test/**/*.min.txt";
  57. var srcOptions = {base: process.cwd()};
  58. var obj = function (path) {
  59. path.dirname.should.equal("test/fixtures");
  60. };
  61. helper({pattern: srcPattern, options: srcOptions}, obj, null, done);
  62. });
  63. });
  64. });
  65. describe("basename", function () {
  66. it("strips extension like Path.basename(path, ext)", function (done) {
  67. var srcPattern = "test/fixtures/hello.min.txt";
  68. var obj = function (path) {
  69. path.basename.should.equal("hello.min");
  70. path.basename.should.equal(Path.basename(srcPattern, Path.extname(srcPattern)));
  71. };
  72. helper(srcPattern, obj, null, done);
  73. });
  74. });
  75. describe("extname", function () {
  76. it("includes '.' like Path.extname", function (done) {
  77. var srcPattern = "test/fixtures/hello.txt";
  78. var obj = function (path) {
  79. path.extname.should.equal(".txt");
  80. path.extname.should.equal(Path.extname(srcPattern));
  81. };
  82. helper(srcPattern, obj, null, done);
  83. });
  84. it("excludes multiple extensions like Path.extname", function (done) {
  85. var srcPattern = "test/fixtures/hello.min.txt";
  86. var obj = function (path) {
  87. path.extname.should.equal(".txt");
  88. path.extname.should.equal(Path.extname(srcPattern));
  89. };
  90. helper(srcPattern, obj, null, done);
  91. });
  92. });
  93. });