blob: b656935749526bd586783cc85431cadaea887fb0 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// 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.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author geirst
*/
public class TensorFieldTestCase {
@Test
public void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException {
try {
SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}"));
fail("Expected exception");
}
catch (IllegalArgumentException e) {
assertEquals("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead.",
e.getMessage());
}
}
@Test
public void requireThatTensorFieldCannotBeIndexField() throws ParseException {
try {
SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }"));
fail("Expected exception");
}
catch (IllegalArgumentException e) {
assertEquals("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field.",
e.getMessage());
}
}
@Test
public void requireThatTensorAttributeCannotBeFastSearch() throws ParseException {
try {
SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }"));
fail("Expected exception");
}
catch (IllegalArgumentException e) {
assertEquals("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'.", e.getMessage());
}
}
@Test
public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException {
try {
SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }"));
fail("Expected exception");
}
catch (IllegalArgumentException e) {
assertStartsWith("Field type: Illegal tensor type spec:", e.getMessage());
}
}
private static String getSd(String field) {
return "search test {\n document test {\n" + field + "}\n}\n";
}
private void assertStartsWith(String prefix, String string) {
assertEquals(prefix, string.substring(0, Math.min(prefix.length(), string.length())));
}
}
|