"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/es.promise.js");

require("core-js/modules/es.array.join.js");

require("core-js/modules/es.array.sort.js");

require("regenerator-runtime/runtime.js");

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

Object.defineProperty(exports, "__esModule", {
  value: true
});

require("mocha");

var assert = require("assert");

var htmlFolding_1 = require("../modes/htmlFolding");

var languageModes_1 = require("../modes/languageModes");

var vscode_css_languageservice_1 = require("vscode-css-languageservice");

var nodeFs_1 = require("../node/nodeFs");

function assertRanges(_x, _x2, _x3, _x4) {
  return _assertRanges.apply(this, arguments);
}

function _assertRanges() {
  _assertRanges = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(lines, expected, message, nRanges) {
    var document, workspace, languageModes, actual, actualRanges, i;
    return regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            document = languageModes_1.TextDocument.create('test://foo/bar.html', 'html', 1, lines.join('\n'));
            workspace = {
              settings: {},
              folders: [{
                name: 'foo',
                uri: 'test://foo'
              }]
            };
            languageModes = (0, languageModes_1.getLanguageModes)({
              css: true,
              javascript: true
            }, workspace, vscode_css_languageservice_1.ClientCapabilities.LATEST, (0, nodeFs_1.getNodeFileFS)());
            _context9.next = 5;
            return (0, htmlFolding_1.getFoldingRanges)(languageModes, document, nRanges, null);

          case 5:
            actual = _context9.sent;
            actualRanges = [];

            for (i = 0; i < actual.length; i++) {
              actualRanges[i] = r(actual[i].startLine, actual[i].endLine, actual[i].kind);
            }

            actualRanges = actualRanges.sort(function (r1, r2) {
              return r1.startLine - r2.startLine;
            });
            assert.deepStrictEqual(actualRanges, expected, message);

          case 10:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _assertRanges.apply(this, arguments);
}

function r(startLine, endLine, kind) {
  return {
    startLine: startLine,
    endLine: endLine,
    kind: kind
  };
}

suite('HTML Folding', function () {
  test('Embedded JavaScript', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
    var input;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            input = [
            /*0*/
            '<html>',
            /*1*/
            '<head>',
            /*2*/
            '<script>',
            /*3*/
            'function f() {',
            /*4*/
            '}',
            /*5*/
            '</script>',
            /*6*/
            '</head>',
            /*7*/
            '</html>'];
            _context.next = 3;
            return assertRanges(input, [r(0, 6), r(1, 5), r(2, 4), r(3, 4)]);

          case 3:
            _context.next = 5;
            return _context.sent;

          case 5:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  test('Embedded JavaScript - multiple areas', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
    var input;
    return regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            input = [
            /* 0*/
            '<html>',
            /* 1*/
            '<head>',
            /* 2*/
            '<script>',
            /* 3*/
            '  var x = {',
            /* 4*/
            '    foo: true,',
            /* 5*/
            '    bar: {}',
            /* 6*/
            '  };',
            /* 7*/
            '</script>',
            /* 8*/
            '<script>',
            /* 9*/
            '  test(() => { // hello',
            /*10*/
            '    f();',
            /*11*/
            '  });',
            /*12*/
            '</script>',
            /*13*/
            '</head>',
            /*14*/
            '</html>'];
            _context2.next = 3;
            return assertRanges(input, [r(0, 13), r(1, 12), r(2, 6), r(3, 6), r(8, 11), r(9, 11), r(9, 11)]);

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  test('Embedded JavaScript - incomplete', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
    var input;
    return regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            input = [
            /* 0*/
            '<html>',
            /* 1*/
            '<head>',
            /* 2*/
            '<script>',
            /* 3*/
            '  var x = {',
            /* 4*/
            '</script>',
            /* 5*/
            '<script>',
            /* 6*/
            '  });',
            /* 7*/
            '</script>',
            /* 8*/
            '</head>',
            /* 9*/
            '</html>'];
            _context3.next = 3;
            return assertRanges(input, [r(0, 8), r(1, 7), r(2, 3), r(5, 6)]);

          case 3:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  })));
  test('Embedded JavaScript - regions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
    var input;
    return regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            input = [
            /* 0*/
            '<html>',
            /* 1*/
            '<head>',
            /* 2*/
            '<script>',
            /* 3*/
            '  // #region Lalala',
            /* 4*/
            '   //  #region',
            /* 5*/
            '   x = 9;',
            /* 6*/
            '  //  #endregion',
            /* 7*/
            '  // #endregion Lalala',
            /* 8*/
            '</script>',
            /* 9*/
            '</head>',
            /*10*/
            '</html>'];
            _context4.next = 3;
            return assertRanges(input, [r(0, 9), r(1, 8), r(2, 7), r(3, 7, 'region'), r(4, 6, 'region')]);

          case 3:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  })));
  test('Embedded CSS', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
    var input;
    return regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            input = [
            /* 0*/
            '<html>',
            /* 1*/
            '<head>',
            /* 2*/
            '<style>',
            /* 3*/
            '  foo {',
            /* 4*/
            '   display: block;',
            /* 5*/
            '   color: black;',
            /* 6*/
            '  }',
            /* 7*/
            '</style>',
            /* 8*/
            '</head>',
            /* 9*/
            '</html>'];
            _context5.next = 3;
            return assertRanges(input, [r(0, 8), r(1, 7), r(2, 6), r(3, 5)]);

          case 3:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  })));
  test('Embedded CSS - multiple areas', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
    var input;
    return regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            input = [
            /* 0*/
            '<html>',
            /* 1*/
            '<head style="color:red">',
            /* 2*/
            '<style>',
            /* 3*/
            '  /*',
            /* 4*/
            '    foo: true,',
            /* 5*/
            '    bar: {}',
            /* 6*/
            '  */',
            /* 7*/
            '</style>',
            /* 8*/
            '<style>',
            /* 9*/
            '  @keyframes mymove {',
            /*10*/
            '    from {top: 0px;}',
            /*11*/
            '  }',
            /*12*/
            '</style>',
            /*13*/
            '</head>',
            /*14*/
            '</html>'];
            _context6.next = 3;
            return assertRanges(input, [r(0, 13), r(1, 12), r(2, 6), r(3, 6, 'comment'), r(8, 11), r(9, 10)]);

          case 3:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  })));
  test('Embedded CSS - regions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
    var input;
    return regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            input = [
            /* 0*/
            '<html>',
            /* 1*/
            '<head>',
            /* 2*/
            '<style>',
            /* 3*/
            '  /* #region Lalala */',
            /* 4*/
            '   /*  #region*/',
            /* 5*/
            '   x = 9;',
            /* 6*/
            '  /*  #endregion*/',
            /* 7*/
            '  /* #endregion Lalala*/',
            /* 8*/
            '</style>',
            /* 9*/
            '</head>',
            /*10*/
            '</html>'];
            _context7.next = 3;
            return assertRanges(input, [r(0, 9), r(1, 8), r(2, 7), r(3, 7, 'region'), r(4, 6, 'region')]);

          case 3:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }))); // test('Embedded JavaScript - multi line comment', async () => {
  // 	const input = [
  // 		/* 0*/'<html>',
  // 		/* 1*/'<head>',
  // 		/* 2*/'<script>',
  // 		/* 3*/'  /*',
  // 		/* 4*/'   * Hello',
  // 		/* 5*/'   */',
  // 		/* 6*/'</script>',
  // 		/* 7*/'</head>',
  // 		/* 8*/'</html>',
  // 	];
  // 	await assertRanges(input, [r(0, 7), r(1, 6), r(2, 5), r(3, 5, 'comment')]);
  // });

  test('Test limit', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
    var input;
    return regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            input = [
            /* 0*/
            '<div>',
            /* 1*/
            ' <span>',
            /* 2*/
            '  <b>',
            /* 3*/
            '  ',
            /* 4*/
            '  </b>,',
            /* 5*/
            '  <b>',
            /* 6*/
            '   <pre>',
            /* 7*/
            '  ',
            /* 8*/
            '   </pre>,',
            /* 9*/
            '   <pre>',
            /*10*/
            '  ',
            /*11*/
            '   </pre>,',
            /*12*/
            '  </b>,',
            /*13*/
            '  <b>',
            /*14*/
            '  ',
            /*15*/
            '  </b>,',
            /*16*/
            '  <b>',
            /*17*/
            '  ',
            /*18*/
            '  </b>',
            /*19*/
            ' </span>',
            /*20*/
            '</div>'];
            _context8.next = 3;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(9, 10), r(13, 14), r(16, 17)], 'no limit', undefined);

          case 3:
            _context8.next = 5;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(9, 10), r(13, 14), r(16, 17)], 'limit 8', 8);

          case 5:
            _context8.next = 7;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(13, 14), r(16, 17)], 'limit 7', 7);

          case 7:
            _context8.next = 9;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14), r(16, 17)], 'limit 6', 6);

          case 9:
            _context8.next = 11;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14)], 'limit 5', 5);

          case 11:
            _context8.next = 13;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11)], 'limit 4', 4);

          case 13:
            _context8.next = 15;
            return assertRanges(input, [r(0, 19), r(1, 18), r(2, 3)], 'limit 3', 3);

          case 15:
            _context8.next = 17;
            return assertRanges(input, [r(0, 19), r(1, 18)], 'limit 2', 2);

          case 17:
            _context8.next = 19;
            return assertRanges(input, [r(0, 19)], 'limit 1', 1);

          case 19:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  })));
});