// Path: src/main/java/immanix/matchers/UntilMatcher.java
// public class UntilMatcher<T> extends StaxMatcher<T> {
//     private final StaxMatcher<T> delegate;
// 
//     public UntilMatcher(StaxMatcher<T> delegate) {
//         this.delegate = delegate;
//     }
// 
//     @Override
//     public MatcherResult<T> match(EventReader reader) throws XMLStreamException {
//         MatcherResult<T> res = null;
// 
//         while ((res = delegate.match(reader)).isFailure()) {
//             reader = res.reader.unwrap();
//             if (reader.hasNext()) {
//                 reader.next();
//             } else {
//                 return MatcherResult.failure(reader,
//                         res.errorMessage+"\n"+
//                         toString() + " failed: the stream was consumed without the delegate matcher '" + delegate +
//                         "' matching");
//             }
//         }
//         return res;
//     }
// 
//     @Override
//     public String toString() {
//         return "(Until " + delegate + ")";
//     }
// }
// 
// Path: src/main/java/immanix/readers/ReplayEventReader.java
// @SuppressWarnings("restriction")
// public class ReplayEventReader implements EventReader {
// 
//     private Iterator<? extends XMLEvent> events;
// 
//     public ReplayEventReader(List<? extends XMLEvent> events) {
//         super();
//         this.events = new ArrayList(events).iterator();
//     }
// 
//     public boolean hasNext() {
//         return events.hasNext();
//     }
// 
//     public XMLEvent next() throws XMLStreamException {
//         return events.next();
//     }
// 
//     public EventReader unwrap() {
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return "Replayer";
//     }
// }
// 
// Path: src/test/java/immanix/utils/LatentPacman.java
// public class LatentPacman extends StaxMatcher<Object> {
//     int count;
// 
//     public LatentPacman(int count) {
//         this.count = count;
//     }
// 
//     @Override
//     public MatcherResult<Object> match(EventReader reader) throws XMLStreamException {
//         if (count-- <= 0) {
//             return MatcherResult.<Object>success("S", reader, Collections.EMPTY_LIST);
//         } else {
//             return MatcherResult.failure(reader, "");
//         }
//     }
// }
// 
// Path: src/test/java/immanix/utils/XMLEventsUtils.java
// public static XMLEvent c(String val) {
//     return eventFactory.createCharacters(val);
// }
// 
// Path: src/test/java/immanix/utils/XMLEventsUtils.java
// public static XMLEvent se(String name) {
//     return eventFactory.createStartElement(new QName(name), null, null);
// }


import immanix.matchers.UntilMatcher;
import immanix.readers.ReplayEventReader;
import immanix.utils.LatentPacman;
import org.junit.Test;
import javax.xml.stream.events.XMLEvent;
import java.util.Arrays;
import java.util.List;
import static immanix.utils.XMLEventsUtils.c;
import static immanix.utils.XMLEventsUtils.se;
import static org.junit.Assert.*;
package immanix;




public class UntilMatcherTest {
    @Test
    public void testSuccessMatch() throws Exception {
        UntilMatcher<Object> m = new UntilMatcher<Object>(new LatentPacman(2));
        List<XMLEvent> events = Arrays.asList(se("42"), c("hi"), se("remains"));
        ReplayEventReader reader = new ReplayEventReader(events);
        MatcherResult<Object> res = m.match(reader);
        //must match
        assertFalse(res.isFailure());

        assertEquals("S", res.data);
        //reader must return next element
        assertTrue(res.reader.hasNext());
// Path: src/main/java/immanix/matchers/UntilMatcher.java
// public class UntilMatcher<T> extends StaxMatcher<T> {
//     private final StaxMatcher<T> delegate;
// 
//     public UntilMatcher(StaxMatcher<T> delegate) {
//         this.delegate = delegate;
//     }
// 
//     @Override
//     public MatcherResult<T> match(EventReader reader) throws XMLStreamException {
//         MatcherResult<T> res = null;
// 
//         while ((res = delegate.match(reader)).isFailure()) {
//             reader = res.reader.unwrap();
//             if (reader.hasNext()) {
//                 reader.next();
//             } else {
//                 return MatcherResult.failure(reader,
//                         res.errorMessage+"\n"+
//                         toString() + " failed: the stream was consumed without the delegate matcher '" + delegate +
//                         "' matching");
//             }
//         }
//         return res;
//     }
// 
//     @Override
//     public String toString() {
//         return "(Until " + delegate + ")";
//     }
// }
// 
// Path: src/main/java/immanix/readers/ReplayEventReader.java
// @SuppressWarnings("restriction")
// public class ReplayEventReader implements EventReader {
// 
//     private Iterator<? extends XMLEvent> events;
// 
//     public ReplayEventReader(List<? extends XMLEvent> events) {
//         super();
//         this.events = new ArrayList(events).iterator();
//     }
// 
//     public boolean hasNext() {
//         return events.hasNext();
//     }
// 
//     public XMLEvent next() throws XMLStreamException {
//         return events.next();
//     }
// 
//     public EventReader unwrap() {
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return "Replayer";
//     }
// }
// 
// Path: src/test/java/immanix/utils/LatentPacman.java
// public class LatentPacman extends StaxMatcher<Object> {
//     int count;
// 
//     public LatentPacman(int count) {
//         this.count = count;
//     }
// 
//     @Override
//     public MatcherResult<Object> match(EventReader reader) throws XMLStreamException {
//         if (count-- <= 0) {
//             return MatcherResult.<Object>success("S", reader, Collections.EMPTY_LIST);
//         } else {
//             return MatcherResult.failure(reader, "");
//         }
//     }
// }
// 
// Path: src/test/java/immanix/utils/XMLEventsUtils.java
// public static XMLEvent c(String val) {
//     return eventFactory.createCharacters(val);
// }
// 
// Path: src/test/java/immanix/utils/XMLEventsUtils.java
// public static XMLEvent se(String name) {
//     return eventFactory.createStartElement(new QName(name), null, null);
// }


// Path: src/test/java/immanix/UntilMatcherTest.java
import immanix.matchers.UntilMatcher;
import immanix.readers.ReplayEventReader;
import immanix.utils.LatentPacman;
import org.junit.Test;
import javax.xml.stream.events.XMLEvent;
import java.util.Arrays;
import java.util.List;
import static immanix.utils.XMLEventsUtils.c;
import static immanix.utils.XMLEventsUtils.se;
import static org.junit.Assert.*;

package immanix;




public class UntilMatcherTest {
    @Test
    public void testSuccessMatch() throws Exception {
        UntilMatcher<Object> m = new UntilMatcher<Object>(new LatentPacman(2));
        List<XMLEvent> events = Arrays.asList(se("42"), c("hi"), se("remains"));
        ReplayEventReader reader = new ReplayEventReader(events);
        MatcherResult<Object> res = m.match(reader);
        //must match
        assertFalse(res.isFailure());

        assertEquals("S", res.data);
        //reader must return next element
        assertTrue(res.reader.hasNext());
        assertEquals(se("remains"), res.reader.next());