aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/hitfield/test/HitFieldTestCase.java
blob: add495939a6facf3cd34a680b4b203c627ece15d (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
71
72
73
74
75
76
77
78
79
80
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.hitfield.test;

import java.util.ArrayList;
import java.util.List;

import com.yahoo.prelude.hitfield.HitField;

import static org.junit.jupiter.api.Assertions.assertEquals;
import com.yahoo.prelude.hitfield.StringFieldPart;
import org.junit.jupiter.api.Test;

/**
 * Tests the HitField class
 *
 * @author Lars Chr Jensen
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public class HitFieldTestCase {

    @Test
    void testHitField() {
        HitField hf = new HitField("boo", "hei paa deg");
        assertEquals(3, hf.getTokenizedContent().size());
        List l = new ArrayList();
        l.add(new StringFieldPart("foo", true));
        l.add(new StringFieldPart(" ", false));
        l.add(new StringFieldPart("bar", true));
        hf.setTokenizedContent(l);
        assertEquals("foo bar", hf.getContent());
        assertEquals("hei paa deg", hf.getRawContent());
    }

    @Test
    void testCjk() {
        HitField hf = new HitField("boo", "hmm\u001fgr");
        assertEquals(2, hf.getTokenizedContent().size());
        assertEquals("hmmgr", hf.getContent());
        List l = new ArrayList();
        l.add(new StringFieldPart("foo", true));
        l.add(new StringFieldPart("bar", true));
        hf.setTokenizedContent(l);
        assertEquals("foobar", hf.getContent());
    }

    @Test
    void testAnnotateField() {
        HitField hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
        assertEquals(11, hf.getTokenizedContent().size());
        hf = new HitField("boo", "\uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
        assertEquals(6, hf.getTokenizedContent().size());
        hf = new HitField("boo", "clude\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
        assertEquals(5, hf.getTokenizedContent().size());
        hf = new HitField("boo", "\uFFFAincludes\uFFFB the <hi>Eclipse</hi> Platform");
        assertEquals(5, hf.getTokenizedContent().size());
        hf = new HitField("boo", "cludes\uFFFB the <hi>Eclipse</hi> Platform");
        assertEquals(5, hf.getTokenizedContent().size());
        hf = new HitField("boo", "\uFFFB the <hi>Eclipse</hi> Platform");
        assertEquals(5, hf.getTokenizedContent().size());
        hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB");
        assertEquals(6, hf.getTokenizedContent().size());
        hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincl");
        assertEquals(6, hf.getTokenizedContent().size());
        hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFA");
        assertEquals(6, hf.getTokenizedContent().size());
        hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9incl");
        assertEquals(6, hf.getTokenizedContent().size());
        hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9");
        assertEquals(6, hf.getTokenizedContent().size());
        hf = new HitField("boo", "The <hi>Eclipse</hi> SDK \uFFF9include\uFFFAincludes\uFFFB the <hi>Eclipse</hi> \uFFF9platform\uFFFAPlatforms\uFFFB test");
        assertEquals(12, hf.getTokenizedContent().size());
    }

    @Test
    void testEmptyField() {
        HitField hf = new HitField("boo", "");
        assertEquals(0, hf.getTokenizedContent().size());
    }

}