test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (function() {
  2. 'use strict';
  3. var assert = require('assert');
  4. var Vinyl = require('vinyl');
  5. var gulpRtlcss = require('./index');
  6. it('should convert LTR CSS to RTL', function (cb) {
  7. var stream = gulpRtlcss();
  8. stream.on('data', function (file) {
  9. assert.equal(file.contents.toString(), '.selector { float: right; /* comment */ }');
  10. cb();
  11. });
  12. stream.write(new Vinyl({
  13. path: 'styles.css',
  14. contents: new Buffer('.selector { float: left; /* comment */ }')
  15. }));
  16. });
  17. it('should accept rtlcss configuration', function (cb) {
  18. var stream = gulpRtlcss({
  19. "options": {
  20. "preserveComments": true,
  21. "preserveDirectives": false,
  22. "swapLeftRightInUrl": true,
  23. "swapLtrRtlInUrl": true,
  24. "swapWestEastInUrl": true,
  25. "autoRename": false,
  26. "greedy": false,
  27. "enableLogging": false,
  28. "minify": false
  29. },
  30. "rules": [ ],
  31. "declarations": [ ],
  32. "properties": [ ],
  33. "map": false
  34. });
  35. stream.on('data', function (file) {
  36. assert.equal(file.contents.toString(), ".pull-left {content: ' ';}");
  37. cb();
  38. });
  39. stream.write(new Vinyl({
  40. path: 'styles.css',
  41. contents: new Buffer(".pull-left {content: ' ';}")
  42. }));
  43. });
  44. it('should honour rtlcss directives', function (cb) {
  45. var stream = gulpRtlcss();
  46. stream.on('data', function (file) {
  47. assert.equal(file.contents.toString(), ".toRight {\n" +
  48. " text-align: left;\n" +
  49. "}\n");
  50. cb();
  51. });
  52. stream.write(new Vinyl({
  53. path: 'styles.css',
  54. contents: new Buffer(".toRight {\n" +
  55. " /*rtl:remove*/\n" +
  56. " direction: rtl;\n" +
  57. " \n" +
  58. " /*rtl:ignore*/\n" +
  59. " text-align: left;\n" +
  60. "}\n")
  61. }));
  62. });
  63. })();