-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#236: Basic, compiling and failing tests for the CurrentIndex ValueEx…
…pression.
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
core/src/main/java/io/parsingdata/metal/expression/value/reference/CurrentIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 io.parsingdata.metal.expression.value.reference; | ||
|
||
import java.util.Optional; | ||
|
||
import io.parsingdata.metal.Util; | ||
import io.parsingdata.metal.data.ImmutableList; | ||
import io.parsingdata.metal.data.ParseState; | ||
import io.parsingdata.metal.encoding.Encoding; | ||
import io.parsingdata.metal.expression.value.Value; | ||
import io.parsingdata.metal.expression.value.ValueExpression; | ||
|
||
/** | ||
* A {@link ValueExpression} that represents the current index in an iteration | ||
* (e.g. when inside a {@link io.parsingdata.metal.token.Rep} or | ||
* {@link io.parsingdata.metal.token.RepN}). | ||
*/ | ||
public class CurrentIndex implements ValueExpression { | ||
|
||
@Override | ||
public ImmutableList<Optional<Value>> eval(final ParseState parseState, final Encoding encoding) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
return Util.notNullAndSameClass(this, obj); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return getClass().hashCode(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
core/src/test/java/io/parsingdata/metal/expression/value/reference/CurrentIndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 io.parsingdata.metal.expression.value.reference; | ||
|
||
import static io.parsingdata.metal.Shorthand.CURRENT_INDEX; | ||
import static io.parsingdata.metal.Shorthand.con; | ||
import static io.parsingdata.metal.Shorthand.def; | ||
import static io.parsingdata.metal.Shorthand.eq; | ||
import static io.parsingdata.metal.Shorthand.rep; | ||
import static io.parsingdata.metal.Shorthand.repn; | ||
import static io.parsingdata.metal.Shorthand.seq; | ||
import static io.parsingdata.metal.util.EncodingFactory.enc; | ||
import static io.parsingdata.metal.util.ParseStateFactory.stream; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import org.junit.runners.Parameterized; | ||
|
||
import io.parsingdata.metal.token.Token; | ||
import io.parsingdata.metal.util.ParameterizedParse; | ||
|
||
public class CurrentIndexTest extends ParameterizedParse { | ||
|
||
public static final Token VALUE_EQ_INDEX = def("value", con(1), eq(CURRENT_INDEX)); | ||
|
||
@Parameterized.Parameters(name="{0} ({4})") | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][] { | ||
{ "[0, 1, 2, 3] rep(CURRENT_INDEX)", rep(VALUE_EQ_INDEX), stream(0, 1, 2, 3), enc(), true }, | ||
{ "[0, 1, 2, 3] repn(4, CURRENT_INDEX)", repn(VALUE_EQ_INDEX, con(4)), stream(0, 1, 2, 3), enc(), true }, | ||
{ "[0, 1, 2, 3] seq(CURRENT_INDEX, ...)", seq(VALUE_EQ_INDEX, VALUE_EQ_INDEX, VALUE_EQ_INDEX, VALUE_EQ_INDEX), stream(0, 1, 2, 3), enc(), true } | ||
}); | ||
} | ||
|
||
} |