/*
 * Copyright 2013-2016 Netherlands Forensic Institute
 *
 * 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 nl.minvenj.nfi.ddrx;

import static nl.minvenj.nfi.ddrx.Shorthand.*;
import static nl.minvenj.nfi.ddrx.util.EncodingFactory.enc;
import static nl.minvenj.nfi.ddrx.util.EnvironmentFactory.stream;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import nl.minvenj.nfi.ddrx.token.Token;

@RunWith(JUnit4.class)
public class Shorthands {

    private final Token multiSequence = seq(
                                            def("a", con(1), eq(con(1))),
                                            def("b", con(1), eq(con(2))),
                                            def("c", con(1), eq(con(3))));

    private final Token multiChoice = cho(
                                          def("a", con(1), eq(con(1))),
                                          def("b", con(1), eq(con(2))),
                                          def("c", con(1), eq(con(3))));

    @Test
    public void sequenceMultiMatch() throws IOException {
        Assert.assertTrue(multiSequence.parse(stream(1, 2, 3), enc()));
    }

    @Test
    public void sequenceMultiNoMatch() throws IOException {
        Assert.assertFalse(multiSequence.parse(stream(1, 2, 2), enc()));
    }

    @Test
    public void choiceMultiMatch() throws IOException {
        Assert.assertTrue(multiChoice.parse(stream(3, 2, 1), enc()));
    }

    @Test
    public void choiceMultiNoMatch() throws IOException {
        Assert.assertFalse(multiChoice.parse(stream(42, 63, 84), enc()));
    }

}

@@ -687,17 +687,265 @@
 orthand.
-*
+cho;%0Aimport static nl.minvenj.nfi.ddrx.Shorthand.con;%0Aimport static nl.minvenj.nfi.ddrx.Shorthand.def;%0Aimport static nl.minvenj.nfi.ddrx.Shorthand.eq;%0Aimport static nl.minvenj.nfi.ddrx.Shorthand.gtNum;%0Aimport static nl.minvenj.nfi.ddrx.Shorthand.seq
 ;%0Aimport
@@ -1094,16 +1094,102 @@
 ption;%0A%0A
+import nl.minvenj.nfi.ddrx.data.Environment;%0Aimport nl.minvenj.nfi.ddrx.token.Token;%0A%0A
 import o
@@ -1299,49 +1299,8 @@
 4;%0A%0A
-import nl.minvenj.nfi.ddrx.token.Token;%0A%0A
 @Run
@@ -1712,32 +1712,35 @@
 a%22, con(1), 
-eq
+gtNum
 (con(
-1
+2
 ))),%0A       
@@ -1787,32 +1787,35 @@
 b%22, con(1), 
-eq
+gtNum
 (con(
-2
+1
 ))),%0A       
@@ -1862,32 +1862,35 @@
 c%22, con(1), 
-eq
+gtNum
 (con(
-3
+0
 ))));%0A%0A    @
@@ -2215,32 +2215,33 @@
 choiceMultiMatch
+A
 () throws IOExce
@@ -2260,66 +2260,481 @@
     
-Assert.assertTrue(multiChoice.parse(stream(3, 2, 1), enc()
+runChoice(3, %22a%22);%0A    %7D%0A%0A    @Test%0A    public void choiceMultiMatchB() throws IOException %7B%0A        runChoice(2, %22b%22);%0A    %7D%0A%0A    @Test%0A    public void choiceMultiMatchC() throws IOException %7B%0A        runChoice(1, %22c%22);%0A    %7D%0A%0A    private void runChoice(int data, String matched) throws IOException %7B%0A        Environment enva = stream(data);%0A        Assert.assertTrue(multiChoice.parse(enva, enc()));%0A        Assert.assertTrue(enva.current().get().getName().equals(matched
 ));%0A
@@ -2864,18 +2864,9 @@
 eam(
-42, 63, 84
+0
 ), e

Test refactoring.