option.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* jshint node: true */
  2. /* global it */
  3. var json = require('../');
  4. var gulp = require("gulp");
  5. require('should');
  6. require('mocha');
  7. it('should pass-through second argument to js-beautify', function(done) {
  8. var stream = gulp.src('test/test.json').pipe(json({
  9. version: '2.0.0',
  10. description: 'this is test',
  11. array: [
  12. '1234567890', '1234567890', '1234567890', '1234567890', '1234567890', '1234567890', '1234567890', '1234567890'
  13. ],
  14. nested: {
  15. version: '2.0.1',
  16. description: 'this is test for nested'
  17. }
  18. },
  19. {
  20. 'indent_size': 3,
  21. 'indent_char': '\t',
  22. 'brace_style': 'expand',
  23. 'preserve_newlines' : false,
  24. 'wrap_line_length': 80
  25. }));
  26. stream.on('data', function(file) {
  27. var expected =
  28. '{\n' +
  29. '\t\t\t"name": "test object",\n' +
  30. '\t\t\t"version": "2.0.0",\n' +
  31. '\t\t\t"nested":\n' +
  32. '\t\t\t{\n' +
  33. '\t\t\t\t\t\t"name": "nested object",\n' +
  34. '\t\t\t\t\t\t"version": "2.0.1",\n' +
  35. '\t\t\t\t\t\t"description": "this is test for nested"\n' +
  36. '\t\t\t},\n' +
  37. '\t\t\t"description": "this is test",\n' +
  38. '\t\t\t"array": ["1234567890", "1234567890", "1234567890", "1234567890",\n' +
  39. '\t\t\t\t\t\t"1234567890", "1234567890", "1234567890", "1234567890"\n' +
  40. '\t\t\t]\n' +
  41. '}';
  42. file.contents.toString().should.eql(expected);
  43. done();
  44. });
  45. });
  46. it('should keep indentation', function(done) {
  47. var stream = gulp.src('test/test.json').pipe(json({
  48. version: '2.0.0',
  49. description: 'this is test',
  50. array: [
  51. '1234567890', '1234567890', '1234567890', '1234567890', '1234567890', '1234567890', '1234567890', '1234567890'
  52. ],
  53. nested: {
  54. version: '2.0.1',
  55. description: 'this is test for nested'
  56. }
  57. },
  58. {
  59. 'brace_style': 'expand',
  60. 'preserve_newlines' : false,
  61. 'wrap_line_length': 80
  62. }));
  63. stream.on('data', function(file) {
  64. var expected =
  65. '{\n' +
  66. ' "name": "test object",\n' +
  67. ' "version": "2.0.0",\n' +
  68. ' "nested":\n' +
  69. ' {\n' +
  70. ' "name": "nested object",\n' +
  71. ' "version": "2.0.1",\n' +
  72. ' "description": "this is test for nested"\n' +
  73. ' },\n' +
  74. ' "description": "this is test",\n' +
  75. ' "array": ["1234567890", "1234567890", "1234567890", "1234567890",\n' +
  76. ' "1234567890", "1234567890", "1234567890", "1234567890"\n' +
  77. ' ]\n' +
  78. '}';
  79. file.contents.toString().should.eql(expected);
  80. done();
  81. });
  82. });