options-reader.tests.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var assert = require("assert");
  2. var _ = require("underscore");
  3. var optionsReader = require("../lib/options-reader");
  4. var standardOptions = optionsReader._standardOptions;
  5. var readOptions = optionsReader.readOptions;
  6. var test = require("./test")(module);
  7. test('standard options are used if options is undefined', function() {
  8. var options = readOptions(undefined);
  9. assert.deepEqual(standardOptions, _.omit(options, "customStyleMap", "readStyleMap"));
  10. assert.deepEqual(options.customStyleMap, []);
  11. });
  12. test('standard options are used if options is empty', function() {
  13. var options = readOptions({});
  14. assert.deepEqual(standardOptions, _.omit(options, "customStyleMap", "readStyleMap"));
  15. assert.deepEqual(options.customStyleMap, []);
  16. });
  17. test('custom style map as string is prepended to standard style map', function() {
  18. var options = readOptions({
  19. styleMap: "p.SectionTitle => h2"
  20. });
  21. var styleMap = options.readStyleMap();
  22. assert.deepEqual("p.SectionTitle => h2", styleMap[0]);
  23. assert.deepEqual(optionsReader._defaultStyleMap, styleMap.slice(1));
  24. });
  25. test('custom style map as array is prepended to standard style map', function() {
  26. var options = readOptions({
  27. styleMap: ["p.SectionTitle => h2"]
  28. });
  29. var styleMap = options.readStyleMap();
  30. assert.deepEqual("p.SectionTitle => h2", styleMap[0]);
  31. assert.deepEqual(optionsReader._defaultStyleMap, styleMap.slice(1));
  32. });
  33. test('lines starting with # in custom style map are ignored', function() {
  34. var options = readOptions({
  35. styleMap: "# p.SectionTitle => h3\np.SectionTitle => h2"
  36. });
  37. var styleMap = options.readStyleMap();
  38. assert.deepEqual("p.SectionTitle => h2", styleMap[0]);
  39. assert.deepEqual(optionsReader._defaultStyleMap, styleMap.slice(1));
  40. });
  41. test('blank lines in custom style map are ignored', function() {
  42. var options = readOptions({
  43. styleMap: "\n\n"
  44. });
  45. assert.deepEqual(optionsReader._defaultStyleMap, options.readStyleMap());
  46. });
  47. test('default style mappings are ignored if includeDefaultStyleMap is false', function() {
  48. var options = readOptions({
  49. styleMap: "p.SectionTitle => h2",
  50. includeDefaultStyleMap: false
  51. });
  52. assert.deepEqual(["p.SectionTitle => h2"], options.readStyleMap());
  53. });