"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var assert = require("assert");
var oniguruma_1 = require("../src/oniguruma");
describe('OnigRegExp', function () {
    describe('::searchSync(string, index)', function () {
        it('returns an array of the match and all capture groups', function () {
            var regex = new oniguruma_1.OnigRegExp('\\w(\\d+)');
            var result = regex.searchSync('----a123----');
            if (!result) {
                throw new Error('!result');
            }
            assert.equal(result.length, 2);
            assert.equal(result[0].match, 'a123');
            assert.equal(result[0].start, 4);
            assert.equal(result[0].end, 8);
            assert.equal(result[0].index, 0);
            assert.equal(result[0].length, 4);
            assert.equal(result[1].match, '123');
            assert.equal(result[1].start, 5);
            assert.equal(result[1].end, 8);
            assert.equal(result[1].index, 1);
            assert.equal(result[1].length, 3);
        });
        it('returns null if it does not match', function () {
            var regex = new oniguruma_1.OnigRegExp('\\w(\\d+)');
            var result = regex.searchSync('--------');
            assert.equal(result, null);
        });
        describe('when the string being searched contains a unicode character', function () {
            return it('returns correct indices and lengths', function () {
                var regex = new oniguruma_1.OnigRegExp('a');
                var firstMatch = regex.searchSync('ç√Ωa', 0);
                assert.equal(firstMatch[0].start, 3);
                assert.equal(firstMatch[0].match, 'a');
                var secondMatch = regex.searchSync('ç√Ωabcd≈ßåabcd', 5);
                assert.equal(secondMatch[0].start, 10);
                assert.equal(secondMatch[0].match, 'a');
            });
        });
        describe('when the string being searched contains non-Basic Multilingual Plane characters', function () {
            return it('returns correct indices and matches', function () {
                var regex = new oniguruma_1.OnigRegExp("'");
                var match = regex.searchSync("'\uD835\uDF97'", 0);
                assert.equal(match[0].start, 0);
                assert.equal(match[0].match, "'");
                match = regex.searchSync("'\uD835\uDF97'", 1);
                assert.equal(match[0].start, 3);
                assert.equal(match[0].match, "'");
                match = regex.searchSync("'\uD835\uDF97'", 2);
                assert.equal(match[0].start, 3);
                assert.equal(match[0].match, "'");
                match = regex.searchSync("'\uD835\uDF97'", 3);
                assert.equal(match[0].start, 3);
                assert.equal(match[0].match, "'");
            });
        });
    });
    describe('::testSync(string)', function () {
        return it('returns true if the string matches the pattern', function () {
            assert.equal(new oniguruma_1.OnigRegExp('a[b-d]c').testSync('aec'), false);
            assert.equal(new oniguruma_1.OnigRegExp('a[b-d]c').testSync('abc'), true);
        });
    });
});
//# sourceMappingURL=regexp_test.js.map