for (Boolean flowStyle : new Boolean[] { Boolean.FALSE, Boolean.TRUE }) {
for (DumperOptions.ScalarStyle style : DumperOptions.ScalarStyle.values()) {
List<Event> styledEvents = new ArrayList<Event>();
for (Event event : events) {
if (event instanceof ScalarEvent) {
ScalarEvent scalar = (ScalarEvent) event;
event = new ScalarEvent(scalar.getAnchor(), scalar.getTag(),
scalar.getImplicit(), scalar.getValue(),
scalar.getStartMark(), scalar.getEndMark(), style.getChar());
} else if (event instanceof SequenceStartEvent) {
SequenceStartEvent seqStart = (SequenceStartEvent) event;
event = new SequenceStartEvent(seqStart.getAnchor(),
seqStart.getTag(), seqStart.getImplicit(),
seqStart.getStartMark(), seqStart.getEndMark(), flowStyle);
} else if (event instanceof MappingStartEvent) {
MappingStartEvent mapStart = (MappingStartEvent) event;
event = new MappingStartEvent(mapStart.getAnchor(),
mapStart.getTag(), mapStart.getImplicit(),
mapStart.getStartMark(), mapStart.getEndMark(), flowStyle);
}
styledEvents.add(event);
}
// emit
String data = emit(styledEvents);
List<Event> newEvents = parse(data);
assertEquals("Events must not change. File: " + file, events.size(),
newEvents.size());
Iterator<Event> oldIter = events.iterator();
Iterator<Event> newIter = newEvents.iterator();
while (oldIter.hasNext()) {
Event event = oldIter.next();
Event newEvent = newIter.next();
assertEquals(event.getClass(), newEvent.getClass());
if (event instanceof NodeEvent) {
assertEquals(((NodeEvent) event).getAnchor(),
((NodeEvent) newEvent).getAnchor());
}
if (event instanceof CollectionStartEvent) {
assertEquals(((CollectionStartEvent) event).getTag(),
((CollectionStartEvent) newEvent).getTag());
}
if (event instanceof ScalarEvent) {
ScalarEvent scalarOld = (ScalarEvent) event;
ScalarEvent scalarNew = (ScalarEvent) newEvent;
if (scalarOld.getImplicit().bothFalse()
&& scalarNew.getImplicit().bothFalse()) {
assertEquals(scalarOld.getTag(), scalarNew.getTag());
}
assertEquals(scalarOld.getValue(), scalarNew.getValue());
}
}
}
}