xref: /OpenGrok/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/DefinitionsTest.java (revision 52d10766ed1db3b0fd2c59a0da7292a32f244b50)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * See LICENSE.txt included in this distribution for the specific
9  * language governing permissions and limitations under the License.
10  *
11  * When distributing Covered Code, include this CDDL HEADER in each
12  * file and include the License file at LICENSE.txt.
13  * If applicable, add the following below this CDDL HEADER, with the
14  * fields enclosed by brackets "[]" replaced with your own identifying
15  * information: Portions Copyright [yyyy] [name of copyright owner]
16  *
17  * CDDL HEADER END
18  */
19 
20 /*
21  * Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
22  * Portions Copyright (c) 2018, Chris Fraire <cfraire@me.com>.
23  */
24 package org.opengrok.indexer.analysis;
25 
26 import org.junit.jupiter.api.Test;
27 
28 import java.util.Set;
29 
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertFalse;
32 import static org.junit.jupiter.api.Assertions.assertNotNull;
33 import static org.junit.jupiter.api.Assertions.assertTrue;
34 
35 /**
36  * @author austvik
37  */
38 public class DefinitionsTest {
39 
40     /**
41      * Test of getSymbols method, of class Definitions.
42      */
43     @Test
getSymbols()44     public void getSymbols() {
45         Definitions instance = new Definitions();
46         Set<String> result = instance.getSymbols();
47         assertNotNull(result);
48         assertEquals(0, result.size());
49         instance.addTag(1, "found", "", "", 0, 0);
50         result = instance.getSymbols();
51         assertNotNull(result);
52         assertEquals(1, result.size());
53     }
54 
55     /**
56      * Test of hasSymbol method, of class Definitions.
57      */
58     @Test
hasSymbol()59     public void hasSymbol() {
60         Definitions instance = new Definitions();
61         instance.addTag(1, "found", "", "", 0, 0);
62         assertFalse(instance.hasSymbol("notFound"));
63         assertTrue(instance.hasSymbol("found"));
64     }
65 
66     /**
67      * Test of hasDefinitionAt method, of class Definitions.
68      */
69     @Test
hasDefinitionAt()70     public void hasDefinitionAt() {
71         Definitions instance = new Definitions();
72         String[] type = {""};
73         instance.addTag(1, "found", "", "", 0, 0);
74         assertFalse(instance.hasDefinitionAt("found", 0, type));
75         assertTrue(instance.hasDefinitionAt("found", 1, type));
76         assertFalse(instance.hasDefinitionAt("found", 2, type));
77         assertFalse(instance.hasDefinitionAt("notFound", 0, type));
78         assertFalse(instance.hasDefinitionAt("notFound", 1, type));
79     }
80 
81     /**
82      * Test of occurrences method, of class Definitions.
83      */
84     @Test
occurrences()85     public void occurrences() {
86         Definitions instance = new Definitions();
87         instance.addTag(1, "one", "", "", 0, 0);
88         instance.addTag(1, "two", "", "", 0, 0);
89         instance.addTag(3, "two", "", "", 0, 0);
90         assertEquals(1, instance.occurrences("one"));
91         assertEquals(2, instance.occurrences("two"));
92         assertEquals(0, instance.occurrences("notFound"));
93     }
94 
95     /**
96      * Test of numberOfSymbols method, of class Definitions.
97      */
98     @Test
numberOfSymbols()99     public void numberOfSymbols() {
100         Definitions instance = new Definitions();
101         assertEquals(0, instance.numberOfSymbols());
102         instance.addTag(1, "one", "", "", 0, 0);
103         assertEquals(1, instance.numberOfSymbols());
104         instance.addTag(1, "two", "", "", 0, 0);
105         instance.addTag(3, "two", "", "", 0, 0);
106         assertEquals(2, instance.numberOfSymbols());
107     }
108 
109     /**
110      * Test of getTags method, of class Definitions.
111      */
112     @Test
getTags()113     public void getTags() {
114         Definitions instance = new Definitions();
115         assertEquals(0, instance.getTags().size());
116         instance.addTag(1, "one", "", "", 0, 0);
117         assertEquals(1, instance.getTags().size());
118         instance.addTag(1, "two", "", "", 0, 0);
119         assertEquals(2, instance.getTags().size());
120         instance.addTag(3, "two", "", "", 0, 0);
121         assertEquals(3, instance.getTags().size());
122     }
123 
124     /**
125      * Test of addTag method, of class Definitions.
126      */
127     @Test
addTag()128     public void addTag() {
129         Definitions instance = new Definitions();
130         assertEquals(0, instance.getTags().size());
131         instance.addTag(1, "one", "", "", 0, 0);
132         assertEquals(1, instance.getTags().size());
133     }
134 
135     /**
136      * Test of serialize method, of class Definitions.
137      */
138     @Test
serialize()139     public void serialize() throws Exception {
140         Definitions instance = new Definitions();
141         instance.addTag(1, "one", "", "", 0, 0);
142         byte[] serial = instance.serialize();
143         Definitions instance2 = Definitions.deserialize(serial);
144         assertEquals(instance.getTags().size(), instance2.getTags().size());
145         assertEquals(instance.getSymbols().size(), instance2.getSymbols().size());
146     }
147 
148 }
149