aboutsummaryrefslogtreecommitdiffstats
path: root/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/parser/NumberTestCase.java
blob: b337e816fd01ee98031f2bf4679ec20ff1826ebf (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.parser;

import com.yahoo.document.datatypes.*;
import com.yahoo.vespa.indexinglanguage.expressions.Expression;
import com.yahoo.vespa.indexinglanguage.parser.ParseException;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

/**
 * @author Simon Thoresen Hult
 */
public class NumberTestCase {

    @Test
    public void requireThatCorrectNumberTypeIsParsed() throws ParseException {
        assertTrue(Expression.fromString("6.9").execute() instanceof DoubleFieldValue);
        assertTrue(Expression.fromString("6.9f").execute() instanceof FloatFieldValue);
        assertTrue(Expression.fromString("6.9F").execute() instanceof FloatFieldValue);
        assertTrue(Expression.fromString("69").execute() instanceof IntegerFieldValue);
        assertTrue(Expression.fromString("69l").execute() instanceof LongFieldValue);
        assertTrue(Expression.fromString("69L").execute() instanceof LongFieldValue);
        assertTrue(Expression.fromString("0x69").execute() instanceof IntegerFieldValue);
        assertTrue(Expression.fromString("0x69l").execute() instanceof LongFieldValue);
        assertTrue(Expression.fromString("0x69L").execute() instanceof LongFieldValue);
        assertTrue(Expression.fromString("'69'").execute() instanceof StringFieldValue);
        assertTrue(Expression.fromString("\"69\"").execute() instanceof StringFieldValue);
    }
}