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

import java.io.IOException;
import net.ranides.assira.generic.Serializer;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
@SuppressWarnings("PMD")
public class AnsiStringsTest {
    
    public AnsiStringsTest() {
    }
    
    @Test
    public void testString() {
        AnsiAttr a1 = AnsiStrings.attr(4,5,19, AnsiAttr.BOLD);
        assertEquals("AnsiAttr{4 5 19 +b}", a1.toString());
        
        AnsiAttr a2 = AnsiStrings.attr(4,5,19, AnsiAttr.MASK_FLAGS_SET);
        AnsiAttr a3 = AnsiStrings.attr("AnsiAttr{4 5 19 +b +u +i +m +n +s +f +c}");
        assertEquals(a2.toString(), a3.toString());
    }

    @Test
    public void testValueOf() {
        AnsiAttr a1 = AnsiStrings.attr(4,5,19, AnsiAttr.BOLD | AnsiAttr.NO_NARROW);
        assertEquals(a1, AnsiStrings.attr("4 5 19 +b-n"));
        assertEquals(a1, AnsiStrings.attr("4 5 19 +b -n"));
        
        AnsiAttr a2 = AnsiStrings.attr(4,5,19);
        assertEquals(a2, AnsiStrings.attr("4 5 19"));
        
        AnsiAttr a3 = AnsiStrings.attr(4,5);
        assertEquals(a3, AnsiStrings.attr("4 5"));
        
        AnsiAttr a4 = AnsiStrings.attr(4,5,19, AnsiAttr.MASK_FLAGS_SET);
        AnsiAttr a5 = AnsiStrings.attr("AnsiAttr{4 5 19 +b +u +i +m +n +s +f +c}");
        assertEquals(a4, a5);
    }
    
    @Test
    public void testSerialize() throws IOException {
        AnsiAttr a1 = AnsiStrings.attr("4 5 19 +b-n");
        AnsiAttr a2 = Serializer.copy(a1);
        assertEquals(a1, a2);
    }
    
    @Test
    public void testEquals() {
        AnsiAttr a1 = AnsiStrings.attr("4 5 19 +b +s -n");
        AnsiAttr a2 = AnsiStrings.attr("4 5 19 +b +s -n");
        AnsiAttr a3 = AnsiStrings.attr("7 6 20");
        
        assertTrue(a1.equals(a1));
        assertTrue(a1.equals(a2));
        
        assertFalse(a1.equals(a3, AnsiAttr.CMP_BACK));
        assertFalse(a1.equals(a3, AnsiAttr.CMP_FORE));
        assertFalse(a1.equals(a3, AnsiAttr.CMP_FONT));
    }
    
}
