package net.openhft.chronicle.bytes.readme;

import net.openhft.chronicle.bytes.BytesTestCommon;
import net.openhft.chronicle.bytes.HexDumpBytes;
import net.openhft.chronicle.bytes.NativeBytes;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

public class CASTest extends BytesTestCommon {
    @Test
    public void testCAS() {
        assumeFalse(NativeBytes.areNewGuarded());

        HexDumpBytes bytes = new HexDumpBytes()
                .offsetFormat((o, b) -> b.appendBase16(o, 4));

        bytes.comment("s32").writeUtf8("s32");
        bytes.alignBy(4);
        long s32 = bytes.writePosition();
        bytes.writeInt(0);

        bytes.comment("s64").writeUtf8("s64");
        bytes.alignBy(8);
        long s64 = bytes.writePosition();
        bytes.writeLong(0);

        System.out.println(bytes.toHexString());

        assertTrue(bytes.compareAndSwapInt(s32, 0, Integer.MAX_VALUE));
        assertTrue(bytes.compareAndSwapLong(s64, 0, Long.MAX_VALUE));

        System.out.println(bytes.toHexString());

        assertEquals("0000 03 73 33 32 ff ff ff 7f                         # s32\n" +
                        "0008 03 73 36 34 00 00 00 00 ff ff ff ff ff ff ff 7f # s64\n",
                bytes.toHexString());
        bytes.releaseLast();
    }
}

@@ -488,16 +488,22 @@
         
+final 
 HexDumpB
@@ -597,25 +597,41 @@
 o, 4));%0A
-%0A
+        try %7B%0A%0A  
         
 bytes.co
@@ -614,32 +614,34 @@
 ry %7B%0A%0A          
+  
 bytes.comment(%22s
@@ -663,32 +663,36 @@
 %22s32%22);%0A        
+    
 bytes.alignBy(4)
@@ -697,24 +697,28 @@
 4);%0A        
+  
+  
 long s32 = b
@@ -739,32 +739,36 @@
 tion();%0A        
+    
 bytes.writeInt(0
@@ -771,32 +771,36 @@
 nt(0);%0A%0A        
+  
+  
 bytes.comment(%22s
@@ -822,32 +822,36 @@
 %22s64%22);%0A        
+    
 bytes.alignBy(8)
@@ -856,24 +856,28 @@
 8);%0A        
+  
+  
 long s64 = b
@@ -898,32 +898,36 @@
 tion();%0A        
+    
 bytes.writeLong(
@@ -931,32 +931,329 @@
 ng(0);%0A%0A        
+  
+  final String expected1 = %220000 03 73 33 32 00 00 00 00                         # s32%5Cn%22 +%0A                    %220008 03 73 36 34 00 00 00 00 00 00 00 00 00 00 00 00 # s64%5Cn%22;%0A%0A            final String actual1 = bytes.toHexString();%0A%0A            assertEquals(expected1, actual1);%0A%0A            //
 System.out.print
@@ -1278,32 +1278,36 @@
 ng());%0A%0A        
+ 
+   
 assertTrue(bytes
@@ -1354,32 +1354,36 @@
 ALUE));%0A        
+    
 assertTrue(bytes
@@ -1437,16 +1437,23 @@
         
+ 
+   // 
 System.o
@@ -1494,29 +1494,45 @@
         
+  
-assertEquals(
+  final String expected2 = 
 %220000 03
@@ -1600,36 +1600,32 @@
                 
-    
 %220008 03 73 36 3
@@ -1670,17 +1670,17 @@
 # s64%5Cn%22
-,
+;
 %0A       
@@ -1688,34 +1688,123 @@
     
-    bytes.toHexString()
+final String actual2 = bytes.toHexString();%0A%0A            assertEquals(expected2,actual2
 );%0A
+%0A
+        %7D finally %7B%0A    
     
@@ -1824,20 +1824,31 @@
 easeLast();%0A
+        %7D%0A%0A
     %7D%0A%7D%0A

Improve test and reduce clutter