Search in sources :

Example 6 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class ForEachTestCase method requireThatEachTokenIsExecutedSeparately.

@Test
public void requireThatEachTokenIsExecutedSeparately() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    Array<StringFieldValue> arr = new Array<>(DataType.getArray(DataType.STRING));
    arr.add(new StringFieldValue("6"));
    arr.add(new StringFieldValue("9"));
    ctx.setValue(arr);
    MyCollector exp = new MyCollector();
    new ForEachExpression(exp).execute(ctx);
    assertEquals(2, exp.lst.size());
    FieldValue val = exp.lst.get(0);
    assertTrue(val instanceof StringFieldValue);
    assertEquals("6", ((StringFieldValue) val).getString());
    val = exp.lst.get(1);
    assertTrue(val instanceof StringFieldValue);
    assertEquals("9", ((StringFieldValue) val).getString());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

Example 7 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class GetVarTestCase method requireThatSymbolIsRead.

@Test
public void requireThatSymbolIsRead() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setVariable("in", new IntegerFieldValue(69));
    new GetVarExpression("in").execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(69, ((IntegerFieldValue) val).getInteger());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 8 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class EchoTestCase method requireThatValueIsEchoed.

@Test
public void requireThatValueIsEchoed() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69"));
    new EchoExpression(new PrintStream(out)).execute(ctx);
    assertEquals("69" + System.getProperty("line.separator"), out.toString());
}
Also used : PrintStream(java.io.PrintStream) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class HexEncodeTestCase method requireThatInputIsEncoded.

@Test
public void requireThatInputIsEncoded() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new LongFieldValue(489210573L));
    new HexEncodeExpression().execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof StringFieldValue);
    assertEquals("1d28c2cd", ((StringFieldValue) val).getString());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Example 10 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class IfThenTestCase method evaluateIfThen.

private static boolean evaluateIfThen(FieldValue lhs, Comparator cmp, FieldValue rhs) {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    new StatementExpression(new SetValueExpression(new IntegerFieldValue(1)), new IfThenExpression(new SetValueExpression(lhs), cmp, new SetValueExpression(rhs), new SetVarExpression("true"), new SetVarExpression("false"))).execute(ctx);
    return ctx.getVariable("true") != null;
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)

Aggregations

SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)67 Test (org.junit.Test)59 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)42 FieldValue (com.yahoo.document.datatypes.FieldValue)30 Field (com.yahoo.document.Field)14 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)7 Array (com.yahoo.document.datatypes.Array)4 StructDataType (com.yahoo.document.StructDataType)3 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)3 Pair (com.yahoo.collections.Pair)1 ArrayDataType (com.yahoo.document.ArrayDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)1 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)1 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 AnnotatorConfig (com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1