// Path: src/main/java/com/damnhandy/uri/template/MalformedUriTemplateException.java
// public class MalformedUriTemplateException extends RuntimeException
// {
// 
//    /** The serialVersionUID */
//    private static final long serialVersionUID = 5883174281977078450L;
// 
//    private final int location;
//    /**
//     * Create a new UriTemplateParseException.
//     *
//     * @param message
//     * @param cause
//     */
//    public MalformedUriTemplateException(String message, final int location, Throwable cause)
//    {
//       super(message, cause);
//       this.location = location;
//    }
// 
//    /**
//     * Create a new UriTemplateParseException.
//     *
//     * @param message
//     */
//    public MalformedUriTemplateException(String message, int location)
//    {
//       super(message);
//       this.location = location;
//    }
// 
//    public int getLocation()
//    {
//       return this.location;
//    }
// }


import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Assert;
import org.junit.Test;
import com.damnhandy.uri.template.MalformedUriTemplateException;
import com.damnhandy.uri.template.UriTemplateComponent;
   {
      String template = "http://example.com/{expr}/thing/{other}";
      UriTemplateParser e = new UriTemplateParser();
      List<UriTemplateComponent> expressions = e.scan(template);
      List<String> regExExpr = scanWithRegEx(template);
      Assert.assertEquals(4, expressions.size());
      Assert.assertEquals("http://example.com/", expressions.get(0).getValue());
      Assert.assertEquals(regExExpr.get(0), expressions.get(1).getValue());
      Assert.assertEquals("/thing/", expressions.get(2).getValue());
      Assert.assertEquals(regExExpr.get(1), expressions.get(3).getValue());
   }


   @Test
   public void testGoodTemplateWithOperators() throws Exception
   {
      UriTemplateParser e = new UriTemplateParser();
      List<UriTemplateComponent> expressions = e.scan("http://example.com/{expr}/thing/{?other,thing}");
      Assert.assertEquals(4, expressions.size());
      Assert.assertEquals("http://example.com/", expressions.get(0).getValue());
      Assert.assertEquals("{expr}", expressions.get(1).getValue());
      Assert.assertEquals("/thing/", expressions.get(2).getValue());
      Assert.assertEquals("{?other,thing}", expressions.get(3).getValue());
   }

   /**
    * Checking that we correctly catch an unbalanced expression
    * 
    * @throws Exception
    */
// Path: src/main/java/com/damnhandy/uri/template/MalformedUriTemplateException.java
// public class MalformedUriTemplateException extends RuntimeException
// {
// 
//    /** The serialVersionUID */
//    private static final long serialVersionUID = 5883174281977078450L;
// 
//    private final int location;
//    /**
//     * Create a new UriTemplateParseException.
//     *
//     * @param message
//     * @param cause
//     */
//    public MalformedUriTemplateException(String message, final int location, Throwable cause)
//    {
//       super(message, cause);
//       this.location = location;
//    }
// 
//    /**
//     * Create a new UriTemplateParseException.
//     *
//     * @param message
//     */
//    public MalformedUriTemplateException(String message, int location)
//    {
//       super(message);
//       this.location = location;
//    }
// 
//    public int getLocation()
//    {
//       return this.location;
//    }
// }


// Path: src/test/java/com/damnhandy/uri/template/impl/TestUriTemplateParser.java
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Assert;
import org.junit.Test;
import com.damnhandy.uri.template.MalformedUriTemplateException;
import com.damnhandy.uri.template.UriTemplateComponent;

   {
      String template = "http://example.com/{expr}/thing/{other}";
      UriTemplateParser e = new UriTemplateParser();
      List<UriTemplateComponent> expressions = e.scan(template);
      List<String> regExExpr = scanWithRegEx(template);
      Assert.assertEquals(4, expressions.size());
      Assert.assertEquals("http://example.com/", expressions.get(0).getValue());
      Assert.assertEquals(regExExpr.get(0), expressions.get(1).getValue());
      Assert.assertEquals("/thing/", expressions.get(2).getValue());
      Assert.assertEquals(regExExpr.get(1), expressions.get(3).getValue());
   }


   @Test
   public void testGoodTemplateWithOperators() throws Exception
   {
      UriTemplateParser e = new UriTemplateParser();
      List<UriTemplateComponent> expressions = e.scan("http://example.com/{expr}/thing/{?other,thing}");
      Assert.assertEquals(4, expressions.size());
      Assert.assertEquals("http://example.com/", expressions.get(0).getValue());
      Assert.assertEquals("{expr}", expressions.get(1).getValue());
      Assert.assertEquals("/thing/", expressions.get(2).getValue());
      Assert.assertEquals("{?other,thing}", expressions.get(3).getValue());
   }

   /**
    * Checking that we correctly catch an unbalanced expression
    * 
    * @throws Exception
    */
   @Test(expected = MalformedUriTemplateException.class)