Search in sources :

Example 41 with SimpleTestAdapter

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

the class ScriptTestCase method requireThatVariablesReplaceOthersOutsideScript.

@Test
public void requireThatVariablesReplaceOthersOutsideScript() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newStatement(new SetValueExpression(new IntegerFieldValue(6)), new SetVarExpression("tmp"), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)), new SetVarExpression("tmp"))), new GetVarExpression("tmp"), new AttributeExpression("out")).execute(adapter);
    assertEquals(new IntegerFieldValue(9), adapter.getInputValue("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 42 with SimpleTestAdapter

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

the class ScriptTestCase method requireThatVariablesAreAvailableInScript.

@Test
public void requireThatVariablesAreAvailableInScript() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newScript(newStatement(new SetValueExpression(new IntegerFieldValue(69)), new SetVarExpression("tmp")), newStatement(new GetVarExpression("tmp"), new AttributeExpression("out"))).execute(adapter);
    assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 43 with SimpleTestAdapter

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

the class ScriptTestCase method requireThatScriptEvaluatesToInputValue.

@Test
public void requireThatScriptEvaluatesToInputValue() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newStatement(new SetValueExpression(new IntegerFieldValue(6)), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)))), new AttributeExpression("out")).execute(adapter);
    assertEquals(new IntegerFieldValue(6), adapter.getInputValue("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 44 with SimpleTestAdapter

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

the class SetLanguageTestCase method testsettingEnglish.

@Test
public void testsettingEnglish() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("en"));
    new SetLanguageExpression().execute(ctx);
    assertEquals(Language.ENGLISH, ctx.getLanguage());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 45 with SimpleTestAdapter

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

the class SetVarTestCase method requireThatVariableTypeCanNotChange.

@Test
public void requireThatVariableTypeCanNotChange() {
    VerificationContext ctx = new VerificationContext(new SimpleTestAdapter());
    ctx.setValue(DataType.INT);
    new SetVarExpression("out").verify(ctx);
    try {
        ctx.setValue(DataType.STRING);
        new SetVarExpression("out").verify(ctx);
        fail();
    } catch (VerificationException e) {
        assertTrue(e.getExpression() instanceof SetVarExpression);
        assertEquals("Attempting to assign conflicting types to variable 'out', int vs string.", e.getMessage());
    }
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

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