<commit_before>/*
 * This file is part of the DITA Open Toolkit project hosted on
 * Sourceforge.net. See the accompanying license.txt file for 
 * applicable licenses.
 */

/*
 * (c) Copyright IBM Corp. 2010 All Rights Reserved.
 */
package org.dita.dost.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.dita.dost.util.StringUtils;
import org.junit.Test;

public class TestStringUtils {

	@Test
	public void testAssembleString() {
		String result = null;
		Collection<Object> input = new ArrayList<Object>();
		result = StringUtils.assembleString((Collection<Object>) null, ";");
		assertEquals("", result);
		result = StringUtils.assembleString(Collections.emptyList(), ";");
		assertEquals("", result);
		input.add("first");
		input.add("second");
		input.add("third");
		result = StringUtils.assembleString(input, ";");
		assertEquals("first;second;third", result);
	}

	@Test
	public void testEscapeXMLString() {
		String result = null;
		String input = "<this is test of char update for xml href=\" see link: http://www.ibm.com/download.php?abc=123&def=456\">'test' </test>";
		String expected = "&lt;this is test of char update for xml href=&quot; see link: http://www.ibm.com/download.php?abc=123&amp;def=456&quot;&gt;&apos;test&apos; &lt;/test&gt;";
		result = StringUtils.escapeXML(input);
		assertEquals(expected, result);
	}

	@Test
	public void testEscapeXMLCharArrayIntInt() {
		String result = null;
		char[] input = "<this is test of char update for xml href=\" see link: http://www.ibm.com/download.php?abc=123&def=456\">'test' </test>".toCharArray();
		String expected = "&lt;this is test of char update for xml href=&quot; see link: http://www.ibm.com/download.php?abc=123&amp;def=456&quot;&gt;&apos;test&apos; &lt;/test&gt;";
		result = StringUtils.escapeXML(input,0,input.length);
		assertEquals(expected, result);
	}

	@Test
	public void testGetEntity() {
		String result = null;
		result = StringUtils.getEntity("abc");
		assertEquals("&abc;", result);
		result = StringUtils.getEntity("%xyz");
		assertEquals("%xyz;", result);
	}

	@Test
	public void testCheckEntity() {
		assertFalse(StringUtils.checkEntity("lt"));
		assertFalse(StringUtils.checkEntity("gt"));
		assertFalse(StringUtils.checkEntity("quot"));
		assertFalse(StringUtils.checkEntity("amp"));
		assertTrue(StringUtils.checkEntity("abc"));
	}

	@Test
	public void testReplaceAll() {
		String result = null;
		result = StringUtils.replaceAll("abababa", "aba", "c");
		assertEquals("cbc", result);
	}

	@Test
	public void testRestoreMap() {
		Map<String, String> expected = new HashMap<String, String>();
		expected.put("abc", "def");
		expected.put("ghi", "jkl");
		expected.put("mno", "pqr");
		Map<String, String> result = StringUtils.restoreMap("abc=def,ghi=jkl,mno=pqr");
		assertEquals(expected, result);
	}

	@Test
	public void testIsEmptyString() {
		assertTrue(StringUtils.isEmptyString(null));
		assertTrue(StringUtils.isEmptyString(""));
		assertTrue(StringUtils.isEmptyString("      "));
		assertFalse(StringUtils.isEmptyString("abc"));
	}

	@Test
	public void testSetOrAppend() {
		String input1 = "input1";
		String input2 = "input2";
		String result = null;
		result = StringUtils.setOrAppend(null, input2, true);
		assertEquals("input2", result);
		result = StringUtils.setOrAppend(input1, null, true);
		assertEquals("input1", result);
		result = StringUtils.setOrAppend(input1, input2, false);
		assertEquals("input1input2", result);
		result = StringUtils.setOrAppend(input1, input2, true);
		assertEquals("input1 input2", result);
		
	}

	@Test
	public void testGetLocale() {
		Locale expected1 = new Locale("zh","cn");
		Locale result1 = StringUtils.getLocale("zh-cn");
		assertEquals(expected1, result1);
		Locale expected2 = new Locale("zh");
		Locale result2 = StringUtils.getLocale("zh_cn");
		assertEquals(expected2, result2);
		Locale expected3 = new Locale("zh","cn","gb2312");
		Locale result3 = StringUtils.getLocale("zh-cn-gb2312");
		assertEquals(expected3, result3);
	}

}<commit_msg>Add missing StringUtils unit tests - ID: 3160801<commit_after>/*
 * This file is part of the DITA Open Toolkit project hosted on
 * Sourceforge.net. See the accompanying license.txt file for 
 * applicable licenses.
 */

/*
 * (c) Copyright IBM Corp. 2010 All Rights Reserved.
 */
package org.dita.dost.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.dita.dost.util.StringUtils;
import org.junit.Test;

public class TestStringUtils {

	@Test
	public void testAssembleString() {
		String result = null;
		Collection<Object> input = new ArrayList<Object>();
		result = StringUtils.assembleString((Collection<Object>) null, ";");
		assertEquals("", result);
		result = StringUtils.assembleString(Collections.emptyList(), ";");
		assertEquals("", result);
		input.add("first");
		input.add("second");
		input.add("third");
		result = StringUtils.assembleString(input, ";");
		assertEquals("first;second;third", result);
	}

	@Test
	public void testEscapeXMLString() {
		String result = null;
		String input = "<this is test of char update for xml href=\" see link: http://www.ibm.com/download.php?abc=123&def=456\">'test' </test>";
		String expected = "&lt;this is test of char update for xml href=&quot; see link: http://www.ibm.com/download.php?abc=123&amp;def=456&quot;&gt;&apos;test&apos; &lt;/test&gt;";
		result = StringUtils.escapeXML(input);
		assertEquals(expected, result);
	}

	@Test
	public void testEscapeXMLCharArrayIntInt() {
		String result = null;
		char[] input = "<this is test of char update for xml href=\" see link: http://www.ibm.com/download.php?abc=123&def=456\">'test' </test>".toCharArray();
		String expected = "&lt;this is test of char update for xml href=&quot; see link: http://www.ibm.com/download.php?abc=123&amp;def=456&quot;&gt;&apos;test&apos; &lt;/test&gt;";
		result = StringUtils.escapeXML(input,0,input.length);
		assertEquals(expected, result);
	}

	@Test
	public void testGetEntity() {
		String result = null;
		result = StringUtils.getEntity("abc");
		assertEquals("&abc;", result);
		result = StringUtils.getEntity("%xyz");
		assertEquals("%xyz;", result);
	}

	@Test
	public void testCheckEntity() {
		assertFalse(StringUtils.checkEntity("lt"));
		assertFalse(StringUtils.checkEntity("gt"));
		assertFalse(StringUtils.checkEntity("quot"));
		assertFalse(StringUtils.checkEntity("amp"));
		assertTrue(StringUtils.checkEntity("abc"));
	}

	@Test
	public void testReplaceAll() {
		String result = null;
		result = StringUtils.replaceAll("abababa", "aba", "c");
		assertEquals("cbc", result);
	}
	
	@Test
	public void testGetAscii() {
	    assertEquals("\\'66\\'6f\\'6f", StringUtils.getAscii("foo"));
	    byte[] nonAscii = "äöå".getBytes(Charset.defaultCharset());
	    final StringBuilder buf = new StringBuilder();
	    for (final byte b: nonAscii) {
	        final String s = Integer.toHexString((int) b);
	        buf.append('\\').append('\'').append(s.substring(s.length() - 2));
	    }
	    assertEquals(buf.toString(), StringUtils.getAscii("äöå"));
	}
	
	@Test
	public void testGetExtProps() {
	    assertEquals("props foo,props bar", StringUtils.getExtProps("a(props foo) a(props bar)"));
	    assertEquals("props bar,props qux", StringUtils.getExtProps("(topic foo) a(props bar) (topic baz) a(props qux)"));
	    assertEquals("props   foo", StringUtils.getExtProps("  a(props   foo  )   "));
	}

	@Test
	public void testRestoreMap() {
		Map<String, String> expected = new HashMap<String, String>();
		expected.put("abc", "def");
		expected.put("ghi", "jkl");
		expected.put("mno", "pqr");
		Map<String, String> result = StringUtils.restoreMap("abc=def,ghi=jkl,mno=pqr");
		assertEquals(expected, result);
	}

	@Test
	public void testIsEmptyString() {
		assertTrue(StringUtils.isEmptyString(null));
		assertTrue(StringUtils.isEmptyString(""));
		assertTrue(StringUtils.isEmptyString("      "));
		assertFalse(StringUtils.isEmptyString("abc"));
	}

	@Test
	public void testSetOrAppend() {
		String input1 = "input1";
		String input2 = "input2";
		String result = null;
		result = StringUtils.setOrAppend(null, input2, true);
		assertEquals("input2", result);
		result = StringUtils.setOrAppend(input1, null, true);
		assertEquals("input1", result);
		result = StringUtils.setOrAppend(input1, input2, false);
		assertEquals("input1input2", result);
		result = StringUtils.setOrAppend(input1, input2, true);
		assertEquals("input1 input2", result);
		
	}

	@Test
	public void testGetLocale() {
		Locale expected1 = new Locale("zh","cn");
		Locale result1 = StringUtils.getLocale("zh-cn");
		assertEquals(expected1, result1);
		Locale expected2 = new Locale("zh");
		Locale result2 = StringUtils.getLocale("zh_cn");
		assertEquals(expected2, result2);
		Locale expected3 = new Locale("zh","cn","gb2312");
		Locale result3 = StringUtils.getLocale("zh-cn-gb2312");
		assertEquals(expected3, result3);
	}
	
	@Test
	public void testGetFileName() {
	    assertEquals("foo.bar", StringUtils.getFileName("foo.bar.baz", "."));
	    assertEquals("foo", StringUtils.getFileName("foo.bar", "."));
	    assertEquals("foo", StringUtils.getFileName("foo", "."));
	}
	
	@Test
	public void testGetMaxFive() {
	    assertEquals(Integer.valueOf(5), StringUtils.getMax("1", "2", "3", "4", "5"));
	    assertEquals(Integer.valueOf(5), StringUtils.getMax("5", "4", "3", "2", "1"));
	    assertEquals(Integer.valueOf(5), StringUtils.getMax("5", "5", "5", "5", "5"));
	}
	
	@Test
    public void testGetMaxSix() {
        assertEquals(Integer.valueOf(6), StringUtils.getMax("1", "2", "3", "4", "5", "6"));
        assertEquals(Integer.valueOf(6), StringUtils.getMax("6", "5", "4", "3", "2", "1"));
        assertEquals(Integer.valueOf(6), StringUtils.getMax("6", "6", "6", "6", "6", "6"));
    }
	
}
{'fraction_non_alphanumeric': 0.1640731375218829, 'fraction_numerical': 0.0176035790702198, 'mean_word_length': 5.099051008303677, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2006742', 'n_tokens_mistral': 3521, 'n_tokens_neox': 3275, 'n_words': 730}