<commit_before>package brooklyn.util.text;

import org.testng.Assert;
import org.testng.annotations.Test;

import brooklyn.util.collections.MutableList;
import brooklyn.util.text.StringEscapes.BashStringEscapes;
import brooklyn.util.text.StringEscapes.JavaStringEscapes;

public class StringEscapesTest {

    @Test
    public void testEscapeSql() {
        Assert.assertEquals(StringEscapes.escapeSql("I've never been to Brooklyn"), "I''ve never been to Brooklyn");
    }

    
	@Test
	public void testBashEscaping() {
		Assert.assertEquals(
	        BashStringEscapes.doubleQuoteLiteralsForBash("-Dname=<NAME>", "-Dnet.worth=$100"),
			"\"-Dname=<NAME>\" \"-Dnet.worth=\\$100\"");
	}

	@Test
	public void testBashEscapable() {
		Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("<NAME>"));
		Assert.assertFalse(BashStringEscapes.isValidForDoubleQuotingInBash("\""));
		Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("\\\""));
	}	
    
    @Test
    public void testBashEscapableAmpersand() {
        Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("\\&"));
        Assert.assertFalse(BashStringEscapes.isValidForDoubleQuotingInBash("Marks & Spencer"));
        Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("Marks \\& Spencer"));
        Assert.assertFalse(BashStringEscapes.isValidForDoubleQuotingInBash("Marks \\\\& Spencer"));
    }

    @Test
    public void testJavaUnwrap() {
        Assert.assertEquals(JavaStringEscapes.unwrapJavaString("\"Hello World\""), "Hello World");
        Assert.assertEquals(JavaStringEscapes.unwrapJavaString("\"Hello \\\"Bob\\\"\""), "Hello \"Bob\"");
        try {
            JavaStringEscapes.unwrapJavaString("Hello World");
            Assert.fail("Should have thrown");
        } catch (Exception e) { /* expected */ }
        try {
            // missing final quote
            JavaStringEscapes.unwrapJavaString("\"Hello \\\"Bob\\\"");
            Assert.fail("Should have thrown");
        } catch (Exception e) { /* expected */ }
        
        Assert.assertEquals(JavaStringEscapes.unwrapJavaStringIfWrapped("\"Hello World\""), "Hello World");
        Assert.assertEquals(JavaStringEscapes.unwrapJavaStringIfWrapped("\"Hello \\\"Bob\\\"\""), "Hello \"Bob\"");
        Assert.assertEquals(JavaStringEscapes.unwrapJavaStringIfWrapped("Hello World"), "Hello World");
        try {
            // missing final quote
            JavaStringEscapes.unwrapJavaStringIfWrapped("\"Hello \\\"Bob\\\"");
            Assert.fail("Should have thrown");
        } catch (Exception e) { /* expected */ }
    }
    
    @Test
    public void testJavaEscape() {<commit_msg>Fix unit test for ampersand (non) escaping<commit_after>package brooklyn.util.text;

import org.testng.Assert;
import org.testng.annotations.Test;

import brooklyn.util.collections.MutableList;
import brooklyn.util.text.StringEscapes.BashStringEscapes;
import brooklyn.util.text.StringEscapes.JavaStringEscapes;

public class StringEscapesTest {

    @Test
    public void testEscapeSql() {
        Assert.assertEquals(StringEscapes.escapeSql("I've never been to Brooklyn"), "I''ve never been to Brooklyn");
    }

    
	@Test
	public void testBashEscaping() {
		Assert.assertEquals(
	        BashStringEscapes.doubleQuoteLiteralsForBash("-Dname=<NAME>", "-Dnet.worth=$100"),
			"\"-Dname=<NAME>\" \"-Dnet.worth=\\$100\"");
	}

	@Test
	public void testBashEscapable() {
		Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("<NAME>"));
		Assert.assertFalse(BashStringEscapes.isValidForDoubleQuotingInBash("\""));
		Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("\\\""));
	}	
    
    /** Bash handles ampersand in double quoted strings without escaping. */
    @Test
    public void testBashEscapableAmpersand() {
        Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("&"));
        Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("Marks & Spencer"));
    }

    @Test
    public void testJavaUnwrap() {
        Assert.assertEquals(JavaStringEscapes.unwrapJavaString("\"Hello World\""), "Hello World");
        Assert.assertEquals(JavaStringEscapes.unwrapJavaString("\"Hello \\\"Bob\\\"\""), "Hello \"Bob\"");
        try {
            JavaStringEscapes.unwrapJavaString("Hello World");
            Assert.fail("Should have thrown");
        } catch (Exception e) { /* expected */ }
        try {
            // missing final quote
            JavaStringEscapes.unwrapJavaString("\"Hello \\\"Bob\\\"");
            Assert.fail("Should have thrown");
        } catch (Exception e) { /* expected */ }
        
        Assert.assertEquals(JavaStringEscapes.unwrapJavaStringIfWrapped("\"Hello World\""), "Hello World");
        Assert.assertEquals(JavaStringEscapes.unwrapJavaStringIfWrapped("\"Hello \\\"Bob\\\"\""), "Hello \"Bob\"");
        Assert.assertEquals(JavaStringEscapes.unwrapJavaStringIfWrapped("Hello World"), "Hello World");
        try {
            // missing final quote
            JavaStringEscapes.unwrapJavaStringIfWrapped("\"Hello \\\"Bob\\\"");
            Assert.fail("Should have thrown");
        } catch (Exception e) { /* expected */ }
    }
    
    @Test
    public void testJavaEscape() {
{'fraction_non_alphanumeric': 0.1426944971537002, 'fraction_numerical': 0.0022770398481973433, 'mean_word_length': 3.396163469557965, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7590763', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1550, 'n_words': 251}