01: /*
02: * FixedLengthLineParserTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import junit.framework.TestCase;
15:
16: /**
17: *
18: * @author thomas
19: */
20: public class FixedLengthLineParserTest extends TestCase {
21:
22: public FixedLengthLineParserTest(String testName) {
23: super (testName);
24: }
25:
26: public void testParser() {
27: try {
28: int[] cols = new int[] { 5, 1, 10 };
29: FixedLengthLineParser parser = new FixedLengthLineParser(
30: cols);
31: String line = "12345H1234567890";
32: parser.setLine(line);
33: String first = parser.getNext();
34: assertEquals("12345", first);
35: String second = parser.getNext();
36: assertEquals("H", second);
37: String third = parser.getNext();
38: assertEquals("1234567890", third);
39:
40: line = " 1H 10";
41: parser.setLine(line);
42: parser.setTrimValues(true);
43: first = parser.getNext();
44: assertEquals("1", first);
45: second = parser.getNext();
46: assertEquals("H", second);
47: third = parser.getNext();
48: assertEquals("10", third);
49:
50: parser.setLine(line);
51: parser.setTrimValues(false);
52: first = parser.getNext();
53: assertEquals(" 1", first);
54: second = parser.getNext();
55: assertEquals("H", second);
56: third = parser.getNext();
57: assertEquals(" 10", third);
58:
59: } catch (Exception e) {
60: e.printStackTrace();
61: fail(e.getMessage());
62: }
63: }
64: }
|