package org.forge.text.syntax.encoder;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.forge.text.syntax.Encoder;
import org.forge.text.syntax.Theme;
import org.forge.text.syntax.TokenType;
import org.junit.Assert;

public class AssertEncoder extends Encoder.AbstractEncoder {

   public AssertEncoder(OutputStream out, Theme theme) {
      super(out, theme);
      textTokens.clear();
   }

   @Override
   public void textToken(String text, TokenType type) {
      textTokens.add(new TokenPair(text, type));
   }

   @Override
   public void beginGroup(TokenType type) {
   }

   @Override
   public void endGroup(TokenType type) {
   }

   @Override
   public void beginLine(TokenType type) {
   }

   @Override
   public void endLine(TokenType type) {
   }

   private static List<TokenPair> textTokens = new ArrayList<TokenPair>();

   private static class TokenPair {
      private String text;
      private TokenType type;

      public TokenPair(String text, TokenType type) {
         this.text = text;
         this.type= type;
      }

      @Override
      public String toString() {
         return "[text=" + text + ", type=" + type + "]";
      }
   }

   public static void assertTextToken(TokenType type, String... texts) {
      for(String text : texts) {
         boolean found = false;
         List<TokenPair> textMatches = new ArrayList<TokenPair>();
         for(TokenPair pair : textTokens) {
            if(pair.text.equals(text)) {
               textMatches.add(pair);
               if(pair.type == type) {
                  found = true;
                  break;
               }
            }
         }
         if(!found) {
            Assert.fail("Expected [" + text + "] of type [" + type + "]: Found matches: " + textMatches);
         }
      }
   }
   
   public static void dump() {
      System.out.println(textTokens);
   }
}

@@ -118,46 +118,8 @@
 t;%0A%0A
-import org.forge.text.syntax.Encoder;%0A
 impo
@@ -150,16 +150,16 @@
 .Theme;%0A
+
 import o
@@ -255,24 +255,13 @@
 nds 
-Encoder.Abstract
+Debug
 Enco
@@ -506,250 +506,39 @@
 %0A   
-%7D%0A%0A   @Override%0A   public void beginGroup(TokenType type) %7B%0A   %7D%0A%0A   @Override%0A   public void endGroup(TokenType type) %7B%0A   %7D%0A%0A   @Override%0A   public void beginLine(TokenType type) %7B%0A   %7D%0A%0A   @Override%0A   public void endLine(TokenType
+   super.textToken(text,
  type)
- %7B
+;
 %0A   

Make AssertEncoder extend DebugEncoder for easy debug in IDE