import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import test from 'ava';
import { Pos } from 'codemirror';
import fixDangerousChange from './fixDangerousChange';
var safeInputChars = '0123456789{}-^¥;:[]'.split('');
var zenkakus = '　！”＃＄％＆’（）＊＋、ー。・０：；＜＝＞？＠Ａ「」＾＿｀ａ『｜』〜'.split('');
var specialChars = "\n!\"%&'()*+,-./:;<=>?@[\\]^`{|}~".split('');
var cases = [].concat(_toConsumableArray(safeInputChars.map(function (char) {
  return makeCase(char, '+input', {});
})), _toConsumableArray(zenkakus.map(function (char) {
  return makeCase(char, '+input', {
    hankaku: true
  });
})), _toConsumableArray(specialChars.map(function (char) {
  return makeCase(char, '+delete', {
    canceled: true
  });
})));
test('fixDangerChange', function (t) {
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = cases[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var _step$value = _step.value,
          _input = _step$value.input,
          _expected = _step$value.expected;
      var result = fixDangerousChange(_input.change, _input.removed);
      t.is(result.hankaku, _expected.hankaku, JSON.stringify(_input));
      t.is(result.canceled, _expected.canceled, JSON.stringify(_input));
    }
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return != null) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }
});

function makeCase(text, origin, expected) {
  return {
    input: {
      change: mockChange(text, origin),
      removed: origin === '+delete' ? text : undefined
    },
    expected: expected
  };
}

function mockChange(text, origin) {
  return {
    to: new Pos(0),
    from: new Pos(0),
    text: origin === '+delete' ? [] : [text],
    origin: origin,
    update: function update() {},
    cancel: function cancel() {}
  };
}