/*
 * Copyright 2016-2020 chronicle.software
 *
 * https://chronicle.software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.openhft.chronicle.wire;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;

import static net.openhft.chronicle.bytes.NativeBytes.nativeBytes;
import static org.junit.Assert.assertEquals;

@RunWith(value = Parameterized.class)
public class EscapeCharsTest extends WireTestCommon {
    @NotNull
    final Character ch;
    final Future future;

    public EscapeCharsTest(@NotNull Character ch, Future future) {
        this.ch = ch;
        this.future = future;
    }

    @NotNull
    @Parameterized.Parameters(name = "char = {0}")
    public static Collection<Object[]> combinations() {
        @NotNull List<Object[]> list = new ArrayList<>();
        for (char i = 36; i < 260; i++) {
            char finalI = i;
            list.add(new Object[]{i, ForkJoinPool.commonPool().submit(() -> testEscaped(finalI))});
        }
        return list;
    }

    @Test
    public void testEscaped() throws ExecutionException, InterruptedException {
        future.get();
    }

    static void testEscaped(char ch) {
        @NotNull Wire wire = createWire();
        wire.write("" + ch).text("" + ch);
        wire.write("" + ch + ch).text("" + ch + ch);

        @NotNull StringBuilder sb = new StringBuilder();
        @Nullable String s = wire.read(sb).text();
        assertEquals("key " + ch, "" + ch, sb.toString());
        assertEquals("value " + ch, "" + ch, s);
        @Nullable String ss = wire.read(sb).text();
        assertEquals("key " + ch + ch, "" + ch + ch, sb.toString());
        assertEquals("value " + ch + ch, "" + ch + ch, ss);

        wire.bytes().releaseLast();
    }

    @NotNull
    static TextWire createWire() {
        return new TextWire(nativeBytes());
    }
}

@@ -1303,24 +1303,32 @@
 ter ch;%0A    
+private 
 final Future
@@ -1336,16 +1336,16 @@
 future;%0A
-
 %0A    pub
@@ -1518,15 +1518,8 @@
  = %22
-char = 
 %7B0%7D%22
@@ -1660,18 +1660,17 @@
 i = 
-36
+0
 ; i %3C 
-26
+30
 0; i
@@ -1814,16 +1814,16 @@
       %7D%0A
+
         
@@ -1846,127 +1846,8 @@
  %7D%0A%0A
-    @Test%0A    public void testEscaped() throws ExecutionException, InterruptedException %7B%0A        future.get();%0A    %7D%0A%0A
     
@@ -2559,11 +2559,130 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testEscaped() throws ExecutionException, InterruptedException %7B%0A        future.get();%0A    %7D
 %0A%7D%0A

Make concurrent