package org.grobid.core.document;

import org.grobid.core.utilities.GrobidProperties;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;

/**
 *  @author Patrice Lopez
 */
public class TEIFormatterTest {

    @BeforeClass
    public static void setInitialContext() throws Exception {
        GrobidProperties.getInstance();
    }

	@Test
	public void testBracketReference_noBracket() throws Exception {
		String inputText = "I'm thinking of something.";
		String processedText = TEIFormatter.bracketReferenceSegment(inputText);

		assertThat(processedText, is(nullValue()));
	}

	@Test
	public void testBracketReference_openBracket() throws Exception {
		String inputText = "I'm thinking of (something.";
		String processedText = TEIFormatter.bracketReferenceSegment(inputText);

		assertThat(processedText, is(nullValue()));
	}

	@Test
	public void testBracketReference_closingBracket() throws Exception {
		String inputText = "I'm thinking of something).";
		String processedText = TEIFormatter.bracketReferenceSegment(inputText);

		assertThat(processedText, is(nullValue()));
	}

	@Test
	public void testBracketReference_openAndClosedBracket() throws Exception {
		String inputText = "I'm thinking of (something).";
		String processedText = TEIFormatter.bracketReferenceSegment(inputText);

		assertThat(processedText, is(notNullValue()));
	}

    @Test
    public void testRegex() {
		Pattern localNumberRefCompact =
		    		//Pattern.compile("(\\[|\\()((\\d+\\w?)(\\-(\\d+\\w?))?(,|;)?\\s?)+(\\)|\\])?");
			Pattern.compile("(\\[|\\()((\\d)+(\\w)?(\\-\\d+\\w?)?,\\s?)+(\\d+\\w?)(\\-\\d+\\w?)?(\\)|\\])");
		System.out.println(localNumberRefCompact.pattern());
		String text = "All selected (2000, 2100, 2900, 2902, 2908, 2909, 4300, 8200, 8900, 8902, 9720, 9730, 9780, 9790, 9900,17100,17202,17230,17231,17232, 17239,17290,17292,17293,17320,17330, 17360,17390,17901, 80000";
		text = TEIFormatter.bracketReferenceSegment(text);
		if (text != null) {
			Matcher m = localNumberRefCompact.matcher(text);
			m.find();
		}
		System.out.println("Done");
    }

}
@@ -586,1736 +586,5 @@
  %7D%0A%0A
-%09@Test%0A%09public void testBracketReference_noBracket() throws Exception %7B%0A%09%09String inputText = %22I'm thinking of something.%22;%0A%09%09String processedText = TEIFormatter.bracketReferenceSegment(inputText);%0A%0A%09%09assertThat(processedText, is(nullValue()));%0A%09%7D%0A%0A%09@Test%0A%09public void testBracketReference_openBracket() throws Exception %7B%0A%09%09String inputText = %22I'm thinking of (something.%22;%0A%09%09String processedText = TEIFormatter.bracketReferenceSegment(inputText);%0A%0A%09%09assertThat(processedText, is(nullValue()));%0A%09%7D%0A%0A%09@Test%0A%09public void testBracketReference_closingBracket() throws Exception %7B%0A%09%09String inputText = %22I'm thinking of something).%22;%0A%09%09String processedText = TEIFormatter.bracketReferenceSegment(inputText);%0A%0A%09%09assertThat(processedText, is(nullValue()));%0A%09%7D%0A%0A%09@Test%0A%09public void testBracketReference_openAndClosedBracket() throws Exception %7B%0A%09%09String inputText = %22I'm thinking of (something).%22;%0A%09%09String processedText = TEIFormatter.bracketReferenceSegment(inputText);%0A%0A%09%09assertThat(processedText, is(notNullValue()));%0A%09%7D%0A%0A    @Test%0A    public void testRegex() %7B%0A%09%09Pattern localNumberRefCompact =%0A%09%09    %09%09//Pattern.compile(%22(%5C%5C%5B%7C%5C%5C()((%5C%5Cd+%5C%5Cw?)(%5C%5C-(%5C%5Cd+%5C%5Cw?))?(,%7C;)?%5C%5Cs?)+(%5C%5C)%7C%5C%5C%5D)?%22);%0A%09%09%09Pattern.compile(%22(%5C%5C%5B%7C%5C%5C()((%5C%5Cd)+(%5C%5Cw)?(%5C%5C-%5C%5Cd+%5C%5Cw?)?,%5C%5Cs?)+(%5C%5Cd+%5C%5Cw?)(%5C%5C-%5C%5Cd+%5C%5Cw?)?(%5C%5C)%7C%5C%5C%5D)%22);%0A%09%09System.out.println(localNumberRefCompact.pattern());%0A%09%09String text = %22All selected (2000, 2100, 2900, 2902, 2908, 2909, 4300, 8200, 8900, 8902, 9720, 9730, 9780, 9790, 9900,17100,17202,17230,17231,17232, 17239,17290,17292,17293,17320,17330, 17360,17390,17901, 80000%22;%0A%09%09text = TEIFormatter.bracketReferenceSegment(text);%0A%09%09if (text != null) %7B%0A%09%09%09Matcher m = localNumberRefCompact.matcher(text);%0A%09%09%09m.find();%0A%09%09%7D%0A%09%09System.out.println(%22Done%22);%0A    %7D%0A%0A
 %7D

remove outdated tests