package boxpusher.tests;

import static org.junit.Assert.assertEquals;

import java.io.File;

import org.junit.Test;

import boxpusher.game.Filename;

public class FilenameTest {
	@Test
	public void testNormalLevel() {
		Filename fn = new Filename(new File("data" + File.separator + "levels"
				+ File.separator + "boxpusher.txt"));
		assertEquals("data" + File.separator + "levels", fn.getPath());
		assertEquals("boxpusher", fn.getName());
		assertEquals(".txt", fn.getExtension());
		assertEquals(-1, fn.getNumber());
	}

	@Test
	public void testNormalLevelsetFirstLevel() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdI Lab" + File.separator
				+ "level_01.txt"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("level", fn.getName());
		assertEquals(".txt", fn.getExtension());
		assertEquals(1, fn.getNumber());
	}
	
	@Test
	public void testNormalSavegame() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdII Lab" + File.separator
				+ "boxpusher.sok"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdII Lab", fn.getPath());
		assertEquals("boxpusher", fn.getName());
		assertEquals(".sok", fn.getExtension());
		assertEquals(-1, fn.getNumber());
	}
	
	@Test
	public void testNormalLevelsetThirdLevel() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdI Lab" + File.separator
				+ "level_03.txt"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("level", fn.getName());
		assertEquals(".txt", fn.getExtension());
		assertEquals(3, fn.getNumber());
	}
	
	@Test
	public void testLevelsetWithLvlExt() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdI Lab" + File.separator
				+ "level_05.lvl"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("level", fn.getName());
		assertEquals(".lvl", fn.getExtension());
		assertEquals(5, fn.getNumber());
	}

	@Test
	public void testLevelsetWithLvlTxtExt() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdI Lab" + File.separator
				+ "level_09.lvl.txt"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("level", fn.getName());
		assertEquals(".lvl.txt", fn.getExtension());
		assertEquals(9, fn.getNumber());
	}
	
	@Test
	public void testSavegameWithTxtSokExt() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdI Lab" + File.separator
				+ "boxpusher.txt.sok"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("boxpusher.txt", fn.getName());
		assertEquals(".sok", fn.getExtension());
		assertEquals(-1, fn.getNumber());
	}
	
	@Test
	public void testLevelWithSokTxtExt() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset" + File.separator + "GdI Lab" + File.separator
				+ "level_02.sok.txt"));
		assertEquals("data" + File.separator + "levelset" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("level", fn.getName());
		assertEquals(".sok.txt", fn.getExtension());
		assertEquals(2, fn.getNumber());
	}
	
	@Test
	public void testLevelsetWithDifferentName() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset2" + File.separator + "GdI Lab" + File.separator
				+ "boxpusher_02.txt"));
		assertEquals("data" + File.separator + "levelset2" + File.separator
				+ "GdI Lab", fn.getPath());
		assertEquals("boxpusher", fn.getName());
		assertEquals(".txt", fn.getExtension());
		assertEquals(2, fn.getNumber());
	}
	
	@Test
	public void testLevelWithAnUnderscoreInTheName() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset2" + File.separator + "GdILab" + File.separator
				+ "boxpusher_testlevel.txt"));
		assertEquals("data" + File.separator + "levelset2" + File.separator
				+ "GdILab", fn.getPath());
		assertEquals("boxpusher_testlevel", fn.getName());
		assertEquals(".txt", fn.getExtension());
		assertEquals(-1, fn.getNumber());
	}
	
	@Test
	public void testLevelsetWithAnUnderscoreInTheName() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset2" + File.separator + "GdILab" + File.separator
				+ "boxpusher_testlevel_02.txt"));
		assertEquals("data" + File.separator + "levelset2" + File.separator
				+ "GdILab", fn.getPath());
		assertEquals("boxpusher_testlevel", fn.getName());
		assertEquals(".txt", fn.getExtension());
		assertEquals(2, fn.getNumber());
	}
	
	@Test
	public void testLevelWithoutAnExtension() {
		Filename fn = new Filename(new File("data" + File.separator
				+ "levelset2" + File.separator + "GdILab" + File.separator
				+ "testlevel_first"));
		assertEquals("data" + File.separator + "levelset2" + File.separator
				+ "GdILab", fn.getPath());
		assertEquals("testlevel_first", fn.getName());
		assertEquals(null, fn.getExtension());
		assertEquals(-1, fn.getNumber());
	}
}
