/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.text;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public class FormatHexTest {

    @Test
    public void appendChar() {
        StringBuilder target = new StringBuilder();

        target.append("x");
        FormatHex.appendChar(target, (char)0x32A7);
        target.append(" x");
        FormatHex.appendChar(target, (char)0x93ce);
        target.append(" x");
        FormatHex.appendChar(target, (char)0xaaa);
        target.append(" x");
        FormatHex.appendChar(target, (char)0x7e);

        assertEquals("x32A7 x93CE x0AAA x007E", target.toString());
    }

    @Test
    public void parseChar() {
        String input = "x32A7 x93CE x0AAA x007E";

        assertEquals((char)0x32A7, FormatHex.parseChar(input, 1) );
        assertEquals((char)0x93CE, FormatHex.parseChar(input, 7) );
        assertEquals((char)0x0AAA, FormatHex.parseChar(input, 13) );
        assertEquals((char)0x007E, FormatHex.parseChar(input, 19) );
    }

    @Test
    public void testFormatBuilder() {
        assertEquals("H:34 97 32 71", FormatHex.format(new StringBuilder("H:"), new byte[]{(byte)0x34, (byte)0x97, (byte)0x32, (byte)0x71}).toString());
    }
    
    @Test
    public void testFormat() {
        assertEquals("34 97 32 71", FormatHex.format(new byte[]{(byte)0x34, (byte)0x97, (byte)0x32, (byte)0x71}));
    }

    @Test
    public void testParse() {
        assertArrayEquals(new byte[]{(byte)0x34, (byte)0x97, (byte)0x32, (byte)0x71, (byte)0x9a, (byte)0xa9}, FormatHex.parse("34 97 32 71 9A a9"));
    }
}
