package cn.edu.seu.ise.dca.util.test;

import static org.junit.Assert.*;

import org.junit.Test;

import cn.edu.seu.ise.dca.util.StringUtil;

public class StringUtilTest {

	@Test
	public void testIndexOf() {
		String[] list = {"hello", "world", "dong"};
		assertEquals(StringUtil.indexOf(list, "world"), 1);
		assertEquals(StringUtil.indexOf(list, "wrld"), -1);
	}
	
	@Test
	public void testFindAll() {
		assertEquals(StringUtil.findAllNotInQuote("hello{ ", '{'), 1);
		assertEquals(StringUtil.findAllNotInQuote("if ( ! unlink( \"{$dest}/{$image}\" ) ) {", '{'), 1);
		assertEquals(StringUtil.findAllNotInQuote("if ( preg_match( '/^(:*)\\{\\|(.*)$/', $x, $matches ) ) {", '{'), 1);	
		assertEquals(StringUtil.findAllNotInQuote("if ( preg_match( '/^(:*)\\{\\|(.*)$/{', $x, $matches ) ) {", '{'), 1);
		assertEquals(StringUtil.findAllNotInQuote("if ( preg_match( '/^(:*)\\{\\|(.*)$/{', $x{, $matches ) ) {", '{'), 2);
		assertEquals(StringUtil.findAllNotInQuote("if ($linestart !== '\n' && preg_match('/^({\\\\||:|;|#|\\*)/', $text)) {", '{'), 1);
		assertEquals(StringUtil.findAllNotInQuote("if ( $linestart === '{' ) {", '{'), 1);
		
		assertEquals(StringUtil.findAllNotInQuote("if ( \"$linestart === '{' )\" {", '{'), 1);
		assertEquals(StringUtil.findAllNotInQuote("if ( $linestart === '{' ) {", '{'), 1);
		
	}
	
	@Test
	public void testIsActLine() {
		
		assertFalse(StringUtil.isActualLine(""));
		assertFalse(StringUtil.isActualLine("/*dadjasdsadkas"));
		assertFalse(StringUtil.isActualLine("* dadjasdsadkas"));
		assertFalse(StringUtil.isActualLine("# dadjasdsadkas"));
		assertFalse(StringUtil.isActualLine("/* dadjasdsadkas */"));
		assertTrue(StringUtil.isActualLine("/* dadjasdsadkas */ classes"));
		assertTrue(StringUtil.isActualLine(" adjasdsadkas */ classes"));
		assertTrue(StringUtil.isActualLine(" adjasdsadkas */ classes //dada"));
		assertTrue(StringUtil.isActualLine(" adjasdsadkas */ classes #dada"));
		assertFalse(StringUtil.isActualLine(" adjasdsadkas */  #dada"));
		assertTrue(StringUtil.isActualLine(" adjasdsadkas */ d #dada"));
	}

}
