Skip to content

Commit

Permalink
#280: Added and adapted unit tests for NotAValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdb committed Feb 10, 2019
1 parent 33d8584 commit 5b066d4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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;

import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static io.parsingdata.metal.data.ByteStreamSourceTest.DUMMY_BYTE_STREAM_SOURCE;
import static io.parsingdata.metal.data.ParseState.createFromByteStream;
import static io.parsingdata.metal.data.Slice.createFromBytes;
import static io.parsingdata.metal.expression.value.NotAValue.NOT_A_VALUE;
import static io.parsingdata.metal.util.EncodingFactory.enc;
import static io.parsingdata.metal.util.EncodingFactory.signed;
import static io.parsingdata.metal.util.TokenDefinitions.any;
Expand Down Expand Up @@ -148,7 +149,7 @@ public class AutoEqualityTest {
private static final List<Supplier<Object>> TOKEN_ARRAYS = Arrays.asList(() -> new Token[] { any("a"), any("b")}, () -> new Token[] { any("b"), any("c") }, () -> new Token[] { any("a"), any("b"), any("c") });
private static final List<Supplier<Object>> VALUE_EXPRESSIONS = Arrays.asList(() -> con(1), () -> con(2));
private static final List<Supplier<Object>> EXPRESSIONS = Arrays.asList(() -> TRUE, () -> not(TRUE));
private static final List<Supplier<Object>> VALUES = Arrays.asList(() -> ConstantFactory.createFromString("a", enc()), () -> ConstantFactory.createFromString("b", enc()), () -> ConstantFactory.createFromNumeric(1L, signed()));
private static final List<Supplier<Object>> VALUES = Arrays.asList(() -> ConstantFactory.createFromString("a", enc()), () -> ConstantFactory.createFromString("b", enc()), () -> ConstantFactory.createFromNumeric(1L, signed()), () -> NOT_A_VALUE);
private static final List<Supplier<Object>> REDUCERS = Arrays.asList(() -> (BinaryOperator<ValueExpression>) Shorthand::cat, () -> (BinaryOperator<ValueExpression>) Shorthand::div);
private static final List<Supplier<Object>> SLICES = Arrays.asList(() -> createFromBytes(new byte[] { 1, 2 }), () -> Slice.createFromSource(new DataExpressionSource(ref("a"), 1, createFromByteStream(DUMMY_STREAM).add(PARSE_VALUE).add(PARSE_VALUE), enc()), ZERO, BigInteger.valueOf(2)).get());
private static final List<Supplier<Object>> BYTE_ARRAYS = Arrays.asList(() -> new byte[] { 0 }, () -> new byte[] { 1, 2 }, () -> new byte[] {});
Expand Down
5 changes: 4 additions & 1 deletion core/src/test/java/io/parsingdata/metal/ToStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static io.parsingdata.metal.Shorthand.whl;
import static io.parsingdata.metal.data.ParseGraph.NONE;
import static io.parsingdata.metal.data.Slice.createFromBytes;
import static io.parsingdata.metal.expression.value.NotAValue.NOT_A_VALUE;
import static io.parsingdata.metal.util.EncodingFactory.enc;
import static io.parsingdata.metal.util.ParseStateFactory.stream;
import static io.parsingdata.metal.util.TokenDefinitions.any;
Expand Down Expand Up @@ -123,7 +124,7 @@ private Token t() {
}

private ValueExpression v() {
return fold(foldLeft(foldRight(rev(bytes(neg(add(div(mod(mul(sub(cat(last(ref(n()))), first(nth(exp(ref(n()), con(1)), con(1)))), sub(CURRENT_ITERATION, con(1))), cat(ref(n()), ref(t()))), add(SELF, add(offset(ref(n())), add(CURRENT_OFFSET, count(ref(n())))))), elvis(ref(n()), ref(n())))))), Shorthand::add, ref(n())), Shorthand::add), Shorthand::add, ref(n()));
return fold(foldLeft(foldRight(rev(bytes(neg(add(div(mod(mul(sub(cat(last(ref(n()))), first(nth(exp(ref(n()), con(NOT_A_VALUE)), con(1)))), sub(CURRENT_ITERATION, con(1))), cat(ref(n()), ref(t()))), add(SELF, add(offset(ref(n())), add(CURRENT_OFFSET, count(ref(n())))))), elvis(ref(n()), ref(n())))))), Shorthand::add, ref(n())), Shorthand::add), Shorthand::add, ref(n()));
}

@Test
Expand Down Expand Up @@ -152,6 +153,8 @@ public void specialExpressions() {
assertEquals("CurrentOffset", CURRENT_OFFSET.toString());
assertTrue(v().toString().contains("CurrentIteration"));
assertEquals("CurrentIteration", CURRENT_ITERATION.toString());
assertTrue(v().toString().contains("NOT_A_VALUE"));
assertEquals("NOT_A_VALUE", NOT_A_VALUE.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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;

import static io.parsingdata.metal.expression.value.NotAValue.NOT_A_VALUE;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class NotAValueTest {

@Rule
public final ExpectedException thrown = ExpectedException.none();

@Test
public void getSlice() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.getSlice();
}

@Test
public void getEncoding() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.getEncoding();
}

@Test
public void getValue() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.getValue();
}

@Test
public void getLength() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.getLength();
}

@Test
public void asNumeric() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.asNumeric();
}

@Test
public void asString() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.asString();
}

@Test
public void asBitSet() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("NOT_A_VALUE does not support any Value operation.");
NOT_A_VALUE.asBitSet();
}

}

0 comments on commit 5b066d4

Please sign in to comment.