package cn.hutool.poi.csv;

import cn.hutool.core.io.file.FileUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import org.junit.Ignore;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CsvWriterTest {

	@Test
	@Ignore
	public void writeWithAliasTest(){
		final CsvWriteConfig csvWriteConfig = CsvWriteConfig.defaultConfig()
				.addHeaderAlias("name", "姓名")
				.addHeaderAlias("gender", "性别");

		final CsvWriter writer = CsvUtil.getWriter(
				FileUtil.file("d:/test/csvAliasTest.csv"),
				CharsetUtil.GBK, false, csvWriteConfig);

		writer.writeHeaderLine("name", "gender", "address");
		writer.writeLine("张三", "男", "XX市XX区");
		writer.writeLine("李四", "男", "XX市XX区,01号");
		writer.close();
	}

	@Test
	@Ignore
	public void issue2255Test(){
		final String fileName = "D:/test/" + new Random().nextInt(100) + "-a.csv";
		final CsvWriter writer = CsvUtil.getWriter(fileName, CharsetUtil.UTF_8);
		final List<String> list = new ArrayList<>();
		for (int i = 0; i < 10000; i++) {
			list.add(i+"");
		}
		Console.log("{} : {}", fileName, list.size());
		for (final String s : list) {
			writer.writeLine(s);
		}
		writer.close();
	}
}
