@@ -0,0 +1,2669 @@
+/*%0A * Copyright 2013-2016 Netherlands Forensic Institute%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage io.parsingdata.metal.token;%0A%0Aimport io.parsingdata.metal.data.ParseResult;%0Aimport org.junit.Test;%0A%0Aimport java.io.IOException;%0A%0Aimport static io.parsingdata.metal.Shorthand.*;%0Aimport static io.parsingdata.metal.util.EncodingFactory.enc;%0Aimport static io.parsingdata.metal.util.EnvironmentFactory.stream;%0Aimport static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.*;%0A%0Apublic class PreTest %7B%0A%0A    private static final Token PRECONDITION = pre(def(%22value%22, 1, eq(con(1))), eq(ref(%22header%22), con(1)));%0A    private static final Token SEQUENCE = seq(def(%22header%22, 1), PRECONDITION);%0A%0A    @Test%0A    public void preconditionTrue() throws IOException %7B%0A        final ParseResult result = SEQUENCE.parse(stream(1, 1), enc());%0A%0A        // precondition is true, token is parsed%0A        assertThat(result.getEnvironment().offset, is(2L));%0A    %7D%0A%0A    @Test%0A    public void preconditionFalse() throws IOException %7B%0A        final ParseResult result = SEQUENCE.parse(stream(0, 1), enc());%0A%0A        // precondition is false, token is not parsed%0A        assertThat(result.getEnvironment().offset, is(1L));%0A    %7D%0A%0A    @Test%0A    public void preconditionTrueParseFails() throws IOException %7B%0A        final ParseResult result = SEQUENCE.parse(stream(1, 2), enc());%0A%0A        // precondition is true, but token can't be parsed%0A        assertFalse(result.succeeded());%0A    %7D%0A%0A    @Test%0A    public void preconditionNull() throws IOException %7B%0A        final Token noPrecondition = pre(def(%22value%22, 1), null);%0A        final ParseResult result = noPrecondition.parse(stream(0), enc());%0A%0A        // precondition null, always parse%0A        assertThat(result.getEnvironment().offset, is(1L));%0A    %7D%0A%0A    @Test%0A    public void testToString() %7B%0A        final Token simpleWhile = pre(def(%22value%22, con(1)), eq(con(1)));%0A        final String simpleWhileString = %22Pre(Def(%5C%22value%5C%22,Const(Value(01)),True,), Eq(Const(Value(01))))%22;%0A        assertThat(simpleWhile.toString(), is(equalTo(simpleWhileString)));%0A    %7D%0A%0A%7D

Add Pre tests.