mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
fix Column parsing from celldefinition string, without cellwidth def.
(outofbound exception)
This commit is contained in:
parent
e0816ef2e5
commit
c9e81d2fa0
|
@ -62,6 +62,11 @@ public final class Column implements Cloneable, Serializable {
|
|||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create column from definiton string
|
||||
*
|
||||
* @param celldef syntax: "celltype cellname-cellwidth {encoder} \"descripton\""
|
||||
*/
|
||||
public Column(String celldef) {
|
||||
// define column with column syntax
|
||||
// example: <UDate-3>
|
||||
|
@ -127,8 +132,8 @@ public final class Column implements Cloneable, Serializable {
|
|||
this.nickname = celldef;
|
||||
celldef = "";
|
||||
} else {
|
||||
this.nickname = celldef.substring(0, p);
|
||||
celldef = celldef.substring(q + 1);
|
||||
this.nickname = celldef.substring(0, q);
|
||||
celldef = celldef.substring(q + 1).trim();
|
||||
}
|
||||
} else {
|
||||
this.nickname = celldef.substring(0, p);
|
||||
|
|
55
test/java/net/yacy/kelondro/index/ColumnTest.java
Normal file
55
test/java/net/yacy/kelondro/index/ColumnTest.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* ColumnTest.java
|
||||
* part of YaCy
|
||||
* Copyright 2016 by reger24; https://github.com/reger24
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.yacy.kelondro.index;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for ColumnTest class.
|
||||
*/
|
||||
public class ColumnTest {
|
||||
|
||||
|
||||
/**
|
||||
* Test of cell definition parsing and cellwidth assignment, of class Column.
|
||||
*/
|
||||
@Test
|
||||
public void testCellWidth() {
|
||||
// test cell definition
|
||||
// key=definition string, value= expected cellwidth
|
||||
Map<String, Integer> testcelldefs = new HashMap<String, Integer>();
|
||||
testcelldefs.put("long countA {b256}", 8); // simple
|
||||
testcelldefs.put("long countB-8 {b256}",8); // redundant cellwidth
|
||||
testcelldefs.put("long countC {b256}", 8); // spaces between definition
|
||||
testcelldefs.put("long countD {b256} \"Description\"", 8);
|
||||
testcelldefs.put("<long countE {b256} \"Description\">", 8);
|
||||
testcelldefs.put("int icountA {b256}", 4);
|
||||
|
||||
for (String celldef:testcelldefs.keySet()) {
|
||||
Column col = new Column(celldef);
|
||||
Integer expectedCellWidth = testcelldefs.get(celldef);
|
||||
assertEquals (celldef,expectedCellWidth.intValue(), col.cellwidth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user