// test methods
public void testSegment() throws Exception {
TextSegmenter ts = new TextSegmenter( "foobarbazbeebob", "[", "]" );
assertTrue( !ts.hasMoreSegments() );
assertEquals( null, ts.nextSegment() );
ts.replaceSegment( "X" );
assertTrue( "foobarbazbeebob".equals( ts.getReplacedContent() ) );
ts = new TextSegmenter( "foobarbazbeebob", "[", "]" );
assertTrue( !ts.hasMoreSegments() );
assertTrue( "foobarbazbeebob".equals( ts.getReplacedContent() ) );
ts = new TextSegmenter( "foo[bar]baz[bee]bob", "[", "]" );
assertTrue( ts.hasMoreSegments() );
assertEquals( "bar", ts.nextSegment() );
assertTrue( ts.hasMoreSegments() );
assertEquals( "bee", ts.nextSegment() );
assertTrue( !ts.hasMoreSegments() );
ts = new TextSegmenter( "[bar]baz[bee]bob[foo]", "[", "]" );
assertTrue( ts.hasMoreSegments() );
assertEquals( "bar", ts.nextSegment() );
assertTrue( ts.hasMoreSegments() );
assertEquals( "bee", ts.nextSegment() );
assertTrue( ts.hasMoreSegments() );
assertEquals( "foo", ts.nextSegment() );
assertTrue( !ts.hasMoreSegments() );
ts = new TextSegmenter( "foo<[bar]>baz<[bee]>bob", "<[", "]>" );
assertTrue( ts.hasMoreSegments() );
assertEquals( "bar", ts.nextSegment() );
assertTrue( ts.hasMoreSegments() );
assertEquals( "bee", ts.nextSegment() );
assertTrue( !ts.hasMoreSegments() );
ts = new TextSegmenter( "foo[bar]baz[bee]bob", "[", "]" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "X" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "Y" );
assertTrue( !ts.hasMoreSegments() );
assertEquals( "fooXbazYbob", ts.getReplacedContent() );
ts = new TextSegmenter( "foo[bar]baz[bee]bob", "[", "]" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "X" );
ts.replaceSegment( "A" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "Y" );
assertTrue( !ts.hasMoreSegments() );
assertEquals( "fooAbazYbob", ts.getReplacedContent() );
ts = new TextSegmenter( "[bar]baz[bee]bob[foo]", "[", "]" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "X" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "Y" );
assertTrue( ts.hasMoreSegments() );
ts.nextSegment();
ts.replaceSegment( "Z" );
assertTrue( !ts.hasMoreSegments() );
assertEquals( "XbazYbobZ", ts.getReplacedContent() );
assertEquals( "XbazYbobZ", ts.getReplacedContent() );
}