test.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. /* eslint-disable no-sync */
  23. var fs = __importStar(require("fs"));
  24. var __1 = require("..");
  25. function test(language, code) {
  26. it("should color " + language + " correctly", function () {
  27. var highlighted = __1.highlight(code);
  28. if (process.env.OUTPUT_CODE_SAMPLES) {
  29. console.log(language + ':\n\n' + highlighted);
  30. }
  31. expect(highlighted).toMatchSnapshot();
  32. });
  33. }
  34. describe('highlight()', function () {
  35. var fixtures = fs.readdirSync(__dirname + "/__fixtures__");
  36. for (var _i = 0, fixtures_1 = fixtures; _i < fixtures_1.length; _i++) {
  37. var fixture = fixtures_1[_i];
  38. var fixturePath = __dirname + "/__fixtures__/" + fixture;
  39. if (fs.statSync(fixturePath).isFile()) {
  40. var language = fixture.split('.')[0];
  41. test(language, fs.readFileSync(fixturePath, 'utf8'));
  42. }
  43. }
  44. });
  45. describe('listLanguages()', function () {
  46. it('should list the supported languages', function () {
  47. var languages = __1.listLanguages();
  48. expect(languages).toBeInstanceOf(Array);
  49. expect(languages.length).toBeGreaterThan(0);
  50. });
  51. });
  52. describe('supportsLanguage()', function () {
  53. it('should return true if the language is supported', function () {
  54. var supports = __1.supportsLanguage('json');
  55. expect(supports).toBe(true);
  56. });
  57. it('should return false if the language is not supported', function () {
  58. var supports = __1.supportsLanguage('notsupported');
  59. expect(supports).toBe(false);
  60. });
  61. });
  62. //# sourceMappingURL=test.js.map