Beispiel #1
0
        private CodeRange GetSelectedRange()
        {
            int start, end;

            azuki.GetSelection(out start, out end);
            return(CodeRange.ConvertFromIndiciesSkippingWhitespaces(Code, ref start, ref end));
        }
Beispiel #2
0
        private static void ConvertIndiciesToRange(
            CstNode node, string code, int inclusiveStart, int exclusiveEnd, CodeRange range)
        {
            var newRange          = CodeRange.ConvertFromIndicies(code, inclusiveStart, exclusiveEnd);
            var newInclusiveStart = char.IsWhiteSpace(code[inclusiveStart - 1])
                    ? inclusiveStart - 1 : inclusiveStart;
            var newExclusiveEnd = char.IsWhiteSpace(code[exclusiveEnd])
                    ? exclusiveEnd + 1 : exclusiveEnd;
            var elem = CodeRange.ConvertFromIndiciesSkippingWhitespaces(
                code, ref newInclusiveStart, ref newExclusiveEnd)
                       .FindInnermostNode(node);

            Assert.That(CodeRange.Locate(elem), Is.EqualTo(newRange));

            newRange.ConvertToIndicies(code, out newInclusiveStart, out newExclusiveEnd);
            Assert.That(newRange, Is.EqualTo(range));
            Assert.That(newInclusiveStart, Is.EqualTo(inclusiveStart));
            Assert.That(newExclusiveEnd, Is.EqualTo(exclusiveEnd));

            var scode = new StructuredCode(code);

            Assert.That(
                CodeRange.ConvertFromIndicies(scode, inclusiveStart, exclusiveEnd),
                Is.EqualTo(range));
            newRange.ConvertToIndicies(scode, out newInclusiveStart, out newExclusiveEnd);
            Assert.That(newInclusiveStart, Is.EqualTo(inclusiveStart));
            Assert.That(newExclusiveEnd, Is.EqualTo(exclusiveEnd));
        }