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

import java.io.IOException;
import java.nio.charset.UnsupportedCharsetException;
import net.ranides.assira.text.Charsets;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class StringOutputTest {
    
    private static final String TEXT = "Pchnąć w tę łódź jeża lub ośm skrzyń fig";
    
    @Test
    public void testUTF8() throws IOException {
        StringOutput so = new StringOutput();
        so.write(TEXT.getBytes(Charsets.UTF8));
        
        assertEquals(TEXT, so.toString());
        assertEquals(TEXT, so.toString(Charsets.UTF8));
        assertEquals(TEXT, so.toString(Charsets.UTF8.name()));
        
        assertNotEquals(TEXT, so.toString(Charsets.PL_WINDOWS));
        
        assertThrows(UnsupportedCharsetException.class, ()->{
            so.toString("unknown-cs");
        });
        
        assertEquals(Charsets.UTF8, so.charset());
    }
    
    @Test
    public void testPL() throws IOException {
        StringOutput so = new StringOutput(Charsets.PL_WINDOWS);
        so.write(TEXT.getBytes(Charsets.PL_WINDOWS));
        
        assertEquals(TEXT, so.toString());
        assertEquals(TEXT, so.toString(Charsets.PL_WINDOWS));
        assertEquals(TEXT, so.toString(Charsets.PL_WINDOWS.name()));
        
        assertNotEquals(TEXT, so.toString(Charsets.UTF8));
        
        assertEquals(Charsets.PL_WINDOWS, so.charset());
        
    }
    
    
}
