@@ -0,0 +1,2731 @@
+/*%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 junit.framework.TestCase.assertFalse;%0Aimport static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class WhileTest %7B%0A%0A    public static final Token VALUES = seq(%0A            def(%22value%22, con(1)),%0A            def(%22value2%22, con(1), gtNum(con(8)))%0A    );%0A    private static final Token WHILE = seq(VALUES, whl(VALUES, ltNum(ref(%22value%22), con(1))));%0A%0A    @Test%0A    public void parseAll() throws IOException %7B%0A        // two sequences of two bytes would be parsed: %5B0,9%5D and %5B1,10%5D%0A        // the while stops because the second 'value' is %3E= 1%0A        final ParseResult result = WHILE.parse(stream(0, 9, 1, 10, 2, 11), enc());%0A%0A        assertThat(result.getEnvironment().offset, is(4L));%0A    %7D%0A%0A    @Test%0A    public void parseFails() throws IOException %7B%0A        final ParseResult result = WHILE.parse(stream(0, 9, 0, 8), enc());%0A%0A        // parsing fails because the nested token couldn't be parsed ('value2' %3C= 9)%0A        assertFalse(result.succeeded());%0A    %7D%0A%0A    @Test%0A    public void whileWithoutExpression() throws IOException %7B%0A        // passing null as predicate make this a while(true):%0A        final Token trueWhile = seq(VALUES, new While(VALUES, null, enc()));%0A        final ParseResult result = trueWhile.parse(stream(0, 9, 0, 8), enc());%0A%0A        // parsing fails, see parseFails() above%0A        assertFalse(result.succeeded());%0A    %7D%0A%0A    @Test%0A    public void testToString() %7B%0A        final Token simpleWhile = whl(def(%22value%22, con(1)), eq(con(1)));%0A        final String simpleWhileString = %22While(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%0A

Add While tests.