// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShifted.java
// public class MatchResultShifted implements MatchResult {
// 
//     private MatchResult delegate;
// 
//     private StringBuilder input;
// 
//     private int shift;
// 
//     /**
//      * 
//      * @param delegate
//      *            the original match result
//      * @param input
//      *            the input where some character before the match have been inserted or removed
//      * @param shift
//      *            the number of characters that are inserted or removed. If the characters are removed, the shift must
//      *            be negative number.
//      */
//     public MatchResultShifted(MatchResult delegate, StringBuilder input, int shift) {
//         super();
//         this.delegate = delegate;
//         this.input = input;
//         this.shift = shift;
//     }
// 
//     @Override
//     public int start() {
//         int result = delegate.start();
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public int start(int group) {
//         int result = delegate.start(group);
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public int end() {
//         int result = delegate.end();
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public int end(int group) {
//         int result = delegate.end(group);
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public String group() {
//         int start = start();
//         int end = end();
//         if (start == -1 || end == -1) {
//             return null;
//         } else {
//             return input.substring(start, end);
//         }
//     }
// 
//     @Override
//     public String group(int group) {
//         int start = start(group);
//         int end = end(group);
//         if (start == -1 || end == -1) {
//             return null;
//         } else {
//             return input.substring(start, end);
//         }
//     }
// 
//     @Override
//     public int groupCount() {
//         return delegate.groupCount();
//     }
// 
//     /*
//      * (non-Javadoc)
//      * 
//      * @see java.lang.Object#toString()
//      */
//     @Override
//     public String toString() {
//         return "MatchResultShifted [group=" + group() + ", start=" + start() + ", end=" + end() + "]";
//     }
// 
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.github.rwitzel.streamflyer.experimental.range2.MatchResultShifted;

/**
 * Copyright (C) 2011 rwitzel75@googlemail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.rwitzel.streamflyer.experimental.range2;





/**
 * Tests {@link MatchResultShifted}.
 * 
 * @author rwoo
 * 
 */
public class MatchResultShiftedTest {

    @Test
    public void testGroupCountAndMore() throws Exception {
        StringBuilder input = new StringBuilder("1234567890123451xx2yy5aa6bb");
        String regex = "(1xx(2yy((4zz)|(5aa)))(6bb))";
        Matcher matcher = Pattern.compile(regex).matcher(input);
        assertTrue(matcher.find());
        assertEquals(6, matcher.groupCount());
        assertEquals("1xx2yy5aa6bb", matcher.group());

        {
            assertGroups(matcher, 0);
        }

        // delete the first ten characters from the input
        input.delete(0, 10);
        assertEquals(6, matcher.groupCount());
        try {
            // learning test: the matcher works directly on the string builder (it does not cache groups)
            assertEquals("1xx2yy5aa6bb", matcher.group());
            fail("StringIndexOutOfBoundsException expected");
        } catch (StringIndexOutOfBoundsException e) {

        }

        {
            // offset = 0 -> "1xx2yy5aa6bb" will be the match result

// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShifted.java
// public class MatchResultShifted implements MatchResult {
// 
//     private MatchResult delegate;
// 
//     private StringBuilder input;
// 
//     private int shift;
// 
//     /**
//      * 
//      * @param delegate
//      *            the original match result
//      * @param input
//      *            the input where some character before the match have been inserted or removed
//      * @param shift
//      *            the number of characters that are inserted or removed. If the characters are removed, the shift must
//      *            be negative number.
//      */
//     public MatchResultShifted(MatchResult delegate, StringBuilder input, int shift) {
//         super();
//         this.delegate = delegate;
//         this.input = input;
//         this.shift = shift;
//     }
// 
//     @Override
//     public int start() {
//         int result = delegate.start();
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public int start(int group) {
//         int result = delegate.start(group);
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public int end() {
//         int result = delegate.end();
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public int end(int group) {
//         int result = delegate.end(group);
//         if (result == -1) {
//             return result;
//         } else {
//             return result + shift;
//         }
//     }
// 
//     @Override
//     public String group() {
//         int start = start();
//         int end = end();
//         if (start == -1 || end == -1) {
//             return null;
//         } else {
//             return input.substring(start, end);
//         }
//     }
// 
//     @Override
//     public String group(int group) {
//         int start = start(group);
//         int end = end(group);
//         if (start == -1 || end == -1) {
//             return null;
//         } else {
//             return input.substring(start, end);
//         }
//     }
// 
//     @Override
//     public int groupCount() {
//         return delegate.groupCount();
//     }
// 
//     /*
//      * (non-Javadoc)
//      * 
//      * @see java.lang.Object#toString()
//      */
//     @Override
//     public String toString() {
//         return "MatchResultShifted [group=" + group() + ", start=" + start() + ", end=" + end() + "]";
//     }
// 
// }


// Path: streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShiftedTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.github.rwitzel.streamflyer.experimental.range2.MatchResultShifted;

/**
 * Copyright (C) 2011 rwitzel75@googlemail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.rwitzel.streamflyer.experimental.range2;





/**
 * Tests {@link MatchResultShifted}.
 * 
 * @author rwoo
 * 
 */
public class MatchResultShiftedTest {

    @Test
    public void testGroupCountAndMore() throws Exception {
        StringBuilder input = new StringBuilder("1234567890123451xx2yy5aa6bb");
        String regex = "(1xx(2yy((4zz)|(5aa)))(6bb))";
        Matcher matcher = Pattern.compile(regex).matcher(input);
        assertTrue(matcher.find());
        assertEquals(6, matcher.groupCount());
        assertEquals("1xx2yy5aa6bb", matcher.group());

        {
            assertGroups(matcher, 0);
        }

        // delete the first ten characters from the input
        input.delete(0, 10);
        assertEquals(6, matcher.groupCount());
        try {
            // learning test: the matcher works directly on the string builder (it does not cache groups)
            assertEquals("1xx2yy5aa6bb", matcher.group());
            fail("StringIndexOutOfBoundsException expected");
        } catch (StringIndexOutOfBoundsException e) {

        }

        {
            // offset = 0 -> "1xx2yy5aa6bb" will be the match result

            MatchResult result = new MatchResultShifted(matcher, input, -10);
