blob: 82650598f2917016db1c6283f74a3f2c42787bcc (
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
|
// 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.Schema;
import com.yahoo.schema.derived.IndexingScript;
import com.yahoo.vespa.indexinglanguage.expressions.Expression;
import com.yahoo.vespa.indexinglanguage.parser.ParseException;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Simon Thoresen Hult
*/
public abstract class AssertIndexingScript {
public static void assertIndexing(List<String> expected, Schema schema) {
assertIndexing(expected, new IndexingScript(schema).expressions());
}
public static void assertIndexing(List<String> expected, IndexingScript script) {
assertIndexing(expected, script.expressions());
}
public static void assertIndexing(List<String> expected, Iterable<Expression> actual) {
List<String> parsedExpected = new LinkedList<>();
for (String str : expected) {
try {
parsedExpected.add(Expression.fromString(str).toString());
} catch (ParseException e) {
fail(e.getMessage());
}
}
for (Expression actualExp : actual) {
String str = actualExp.toString();
assertTrue("Unexpected: " + str, parsedExpected.remove(str));
}
assertTrue("Missing: " + parsedExpected.toString(), parsedExpected.isEmpty());
}
}
|