aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@vespa.ai>2023-09-27 17:28:13 +0200
committerJon Bratseth <bratseth@vespa.ai>2023-09-27 17:28:13 +0200
commit12f9d93fd13a74eb022e8ef0633ff3b1456d345b (patch)
tree82372d0c09dc09dedf9f55bf4290b2e12bbc3cb0 /config-model/src/test/java/com/yahoo/schema/processing
parentb4af421142168c36cc1e8c9bae735731a68fcb20 (diff)
Return the expected output
In if-else expressions, return the output of the executed branch rather than the input. The current behavior was undocumented and quite unexpected, so I suggest we treat that as a bug. Also return the last executed expression in a script as its output (rather than nothing. In addition, improve some error messages.
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/processing')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java62
1 files changed, 60 insertions, 2 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java
index d420623f233..0e6744ba8f9 100644
--- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java
@@ -1,12 +1,15 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.processing;
+import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.parser.ParseException;
+import com.yahoo.yolean.Exceptions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Simon Thoresen Hult
@@ -24,8 +27,8 @@ public class IndexingInputsTestCase {
@Test
void requireThatExtraFieldInputImplicitThrows() throws IOException, ParseException {
assertBuildFails("src/test/examples/indexing_extra_field_input_implicit.sd",
- "For schema 'indexing_extra_field_input_implicit', field 'foo': Indexing script refers to " +
- "field 'foo' which is neither a field in document type 'indexing_extra_field_input_implicit' nor a mutable attribute");
+ "For schema 'indexing_extra_field_input_implicit', field 'foo': " +
+ "For expression '{ tokenize normalize stem:\"BEST\" | index foo; }': Expected string input, but no input is specified");
}
@Test
@@ -42,4 +45,59 @@ public class IndexingInputsTestCase {
"'foo' which is neither a field in document type 'indexing_extra_field_input_self' nor a mutable attribute");
}
+ @Test
+ void testPlainInputInDerivedField() throws ParseException {
+ var schema = """
+ schema test {
+ document test {
+ field field1 type int {
+ }
+ }
+ field derived1 type int {
+ indexing: input field1 | attribute
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ }
+
+ @Test
+ void testWrappedInputInDerivedField() throws ParseException {
+ var schema = """
+ schema test {
+ document test {
+ field field1 type int {
+ }
+ }
+ field derived1 type int {
+ indexing: if (input field1 == 0) { 0 } else { 1 } | attribute
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ }
+
+ @Test
+ void testNoInputInDerivedField() throws ParseException {
+ try {
+ var schema = """
+ schema test {
+ document test {
+ field field1 type int {
+ }
+ }
+ field derived1 type int {
+ indexing: attribute
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'test', field 'derived1': For expression '{ attribute derived1; }': " +
+ "Expected any input, but no input is specified",
+ Exceptions.toMessageString(e));
+ }
+ }
+
}