RangeAddressParser { public RangeRef parse(final String address) throws ParseException, UnsupportedEncodingException { final int tableSepIndex = address.lastIndexOf(TABLE_CELL_SEP); final String localRangeAddress; final TableRef tableRef; if (tableSepIndex == -1) { tableRef = null; localRangeAddress = address; } else { final String tableAddress = address.substring(0, tableSepIndex); tableRef = this.tableAddressParser.parse(tableAddress); localRangeAddress = address.substring(tableSepIndex + 1); } final int colonSepIndex = localRangeAddress.indexOf(RANGE_SEP); if (colonSepIndex == -1) { throw new ParseException("Expected a `:` symbol: " + localRangeAddress, 0); } final LocalCellRef localFromCellRef = this.localCellAddressParser.parse(localRangeAddress.substring(0, colonSepIndex)); final LocalCellRef localToCellRef = this.localCellAddressParser.parse(localRangeAddress.substring(colonSepIndex + 1)); return new RangeRef(tableRef, localFromCellRef, localToCellRef); } RangeAddressParser(final TableAddressParser tableAddressParser,
                              final LocalCellAddressParser localCellAddressParser); static RangeAddressParser create(final TableNameUtil tableNameUtil); RangeRef parse(final String address);  }
@Test(expected = ParseException.class) public void testMissingQuote() throws ParseException, IOException { this.parser.parse("'f'f'#t.A1:D3"); }
@Test(expected = ParseException.class) public void testMissingQuote2() throws ParseException, IOException { this.parser.parse("'f''#t.A1:D3"); }
@Test(expected = ParseException.class) public void testRandomQuote2() throws ParseException, IOException { this.parser.parse("f'f#t.A1:D3"); }
@Test public void test() throws ParseException, IOException { final TableRef tableRef = new TableRef(this.tableNameUtil, "f'", "t't", 4); final LocalCellRef localCellRef = new LocalCellRef(2, 3, 3); Assert.assertEquals(new RangeRef(tableRef, A1, localCellRef), this.parser.parse("'f'''#'$t''t'.A1:$D$3")); }
@Test public void testA2() throws ParseException, UnsupportedEncodingException { Assert.assertEquals(new RangeRef(null, A1, new LocalCellRef(1, 0, 0)), this.parser.parse("A1:A2")); }
@Test public void testdB3() throws ParseException, UnsupportedEncodingException { Assert.assertEquals(new RangeRef(null, A1, new LocalCellRef(2, 1, 1)), this.parser.parse("A1:$B3")); }
@Test public void testCd4() throws ParseException, UnsupportedEncodingException { Assert.assertEquals(new RangeRef(null, A1, new LocalCellRef(3, 2, 2)), this.parser.parse("A1:C$4")); }
@Test public void testdDd5() throws ParseException, UnsupportedEncodingException { Assert.assertEquals(new RangeRef(null, A1, new LocalCellRef(4, 3, 3)), this.parser.parse("A1:$D$5")); }
@Test public void testShort() throws ParseException, UnsupportedEncodingException { this.exception.expect(ParseException.class); this.exception.expectMessage("Expected a `:` symbol: $D$"); this.parser.parse("$D$"); }
@Test public void testWrongChar() throws ParseException, UnsupportedEncodingException { this.exception.expect(ParseException.class); this.exception.expectMessage("Expected digit (not 0) or $: $D[@]$5"); this.parser.parse("A1:$D@$5"); }
@Test public void testA0() throws ParseException, UnsupportedEncodingException { this.exception.expect(ParseException.class); this.exception.expectMessage("Expected digit (not 0) or $: A[0]"); this.parser.parse("A1:A0"); }
@Test public void test0A() throws ParseException, UnsupportedEncodingException { this.exception.expect(ParseException.class); this.exception.expectMessage("Expected letter or $: [0]A"); this.parser.parse("A1:0A"); }
@Test public void testA1A() throws ParseException, UnsupportedEncodingException { this.exception.expect(ParseException.class); this.exception.expectMessage("Expected digit: A1[A]"); this.parser.parse("A1:A1A"); }