aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java
blob: f53ca15635f0c1e1b57c1e90370665f68679b922 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;

import com.yahoo.searchdefinition.SearchBuilder;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * @author geirst
 */
public class TensorFieldTestCase {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Test
    public void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead.");
        SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}"));
    }

    @Test
    public void requireThatTensorFieldCannotBeIndexField() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field.");
        SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }"));
    }

    @Test
    public void requireThatTensorAttributeCannotBeFastSearch() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'.");
        SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }"));
    }

    @Test
    public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("Field type: Illegal tensor type spec: A tensor type spec must be on the form tensor[<valuetype>]?(dimensionidentifier[{}|[length?]*), but was 'tensor(invalid)'. Dimension 'invalid' is on the wrong format. Examples: tensor(x[]), tensor<float>(name{}, x[10])");
        SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }"));
    }

    private static String getSd(String field) {
        return "search test {\n document test {\n" + field + "}\n}\n";
    }

}