/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.ios; import gplx.*;
import org.junit.*;
public class IoUrl_wnt_tst {
	IoUrlFxt fx = IoUrlFxt.new_();
	@Test  public void Raw() {
		fx.tst_Xto_gplx(Io_url_.wnt_fil_("C:\\dir\\fil.txt"), "C:\\dir\\fil.txt");
		fx.tst_Xto_gplx(Io_url_.wnt_dir_("C:\\dir\\"), "C:\\dir\\");
		fx.tst_Xto_gplx(Io_url_.wnt_dir_("C:\\dir")	, "C:\\dir\\"); // add \
	}
	@Test  public void Xto_api() {
		fx.tst_Xto_api(Io_url_.wnt_fil_("C:\\fil.txt"), "C:\\fil.txt");
		fx.tst_Xto_api(Io_url_.wnt_dir_("C:\\dir\\"), "C:\\dir");	// del \
		fx.tst_Xto_api(Io_url_.wnt_dir_("C:"), "C:");
	}
	@Test  public void OwnerRoot() {
		fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:\\dir")		, "C:\\");
		fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:\\fil.png")	, "C:\\");
		fx.tst_OwnerRoot(Io_url_.wnt_dir_("C:")			, "C:\\");
	}
	@Test  public void IsDir() {
		fx.tst_IsDir(Io_url_.wnt_dir_("C:\\dir\\"), true);
		fx.tst_IsDir(Io_url_.wnt_fil_("C:\\dir"), false);
		fx.tst_IsDir(Io_url_.wnt_fil_("C:\\fil.txt"), false);
	}
	@Test  public void OwnerDir() {
		fx.tst_OwnerDir(Io_url_.wnt_dir_("C:\\dir\\sub1"), Io_url_.wnt_dir_("C:\\dir"));
		fx.tst_OwnerDir(Io_url_.wnt_fil_("C:\\fil.txt"), Io_url_.wnt_dir_("C:"));
		fx.tst_OwnerDir(Io_url_.wnt_dir_("C:"), Io_url_.Null);
//			fx.tst_OwnerDir(Io_url_.wnt_fil_("press enter to select this folder"), Io_url_.Null);
	}
	@Test  public void NameAndExt() {
		fx.tst_NameAndExt(Io_url_.wnt_fil_("C:\\fil.txt"), "fil.txt");
		fx.tst_NameAndExt(Io_url_.wnt_dir_("C:\\dir"), "dir\\");
	}
	@Test  public void NameOnly() {
		fx.tst_NameOnly(Io_url_.wnt_fil_("C:\\fil.txt"), "fil");
		fx.tst_NameOnly(Io_url_.wnt_dir_("C:\\dir"), "dir");
		fx.tst_NameOnly(Io_url_.wnt_dir_("C:"), "C");
	}
	@Test  public void Ext() {
		fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil.txt"), ".txt"); // fil
		fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil.multiple.txt"), ".txt"); // multiple ext
		fx.tst_Ext(Io_url_.wnt_fil_("C:\\fil"), ""); // no ext
		fx.tst_Ext(Io_url_.wnt_dir_("C:\\dir"), "\\"); // dir
	}
	@Test  public void GenSubDir_nest() {
		fx.tst_GenSubDir_nest(Io_url_.wnt_dir_("C:"), fx.ary_("dir1", "sub1"), Io_url_.wnt_dir_("C:\\dir1\\sub1"));
	}
	@Test  public void GenNewExt() {
		fx.tst_GenNewExt(Io_url_.wnt_fil_("C:\\fil.gif"), ".png", Io_url_.wnt_fil_("C:\\fil.png")); // basic
		fx.tst_GenNewExt(Io_url_.wnt_fil_("C:\\fil.tst.gif"), ".png", Io_url_.wnt_fil_("C:\\fil.tst.png")); // last in multiple dotted
	}
	@Test  public void GenRelUrl_orEmpty() {
		fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\fil.txt")		, Io_url_.wnt_dir_("C:\\root")	, "fil.txt"); // fil
		fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_dir_("C:\\root\\dir")			, Io_url_.wnt_dir_("C:\\root")	, "dir\\"); // dir
		fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\dir\\fil.txt")	, Io_url_.wnt_dir_("C:\\root")	, "dir\\fil.txt"); // fil: nested1			
		fx.tst_GenRelUrl_orEmpty(Io_url_.wnt_fil_("C:\\root\\dir\\fil.txt")	, Io_url_.wnt_dir_("C:")			, "root\\dir\\fil.txt"); // fil: nested2
	}
	@Test  public void GenParallel() {
		fx.tst_GenParallel(Io_url_.wnt_fil_("C:\\root1\\fil.txt"), Io_url_.wnt_dir_("C:\\root1"), Io_url_.wnt_dir_("D:\\root2"), Io_url_.wnt_fil_("D:\\root2\\fil.txt"));
		fx.tst_GenParallel(Io_url_.wnt_dir_("C:\\root1\\dir")	, Io_url_.wnt_dir_("C:\\root1"), Io_url_.wnt_dir_("D:\\root2"), Io_url_.wnt_dir_("D:\\root2\\dir"));
	}
}
class IoUrlFxt {
	public void tst_Xto_api(Io_url url, String expd) {Tfds.Eq(expd, url.Xto_api());}
	public void tst_OwnerRoot(Io_url url, String expd) {Tfds.Eq(expd, url.OwnerRoot().Raw());}
	public void tst_XtoNames(Io_url url, String... expdAry) {Tfds.Eq_ary(expdAry, url.XtoNames().XtoStrAry());}
	public void tst_NameAndExt(Io_url url, String expd) {Tfds.Eq(expd, url.NameAndExt());}
	public void tst_Xto_gplx(Io_url url, String expd) {Tfds.Eq(expd, url.Raw());}
	public void tst_IsDir(Io_url url, boolean expd) {Tfds.Eq(expd, url.Type_dir());}
	public void tst_OwnerDir(Io_url url, Io_url expd) {Tfds.Eq_url(expd, url.OwnerDir());}
	public void tst_NameOnly(Io_url url, String expd) {Tfds.Eq(expd, url.NameOnly());}
	public void tst_Ext(Io_url url, String expd) {Tfds.Eq(expd, url.Ext());}
	public void tst_GenSubDir_nest(Io_url rootDir, String[] parts, Io_url expd) {Tfds.Eq(expd, rootDir.GenSubDir_nest(parts));}
	public void tst_GenNewExt(Io_url url, String ext, Io_url expd) {Tfds.Eq_url(expd, url.GenNewExt(ext));}
	public void tst_GenRelUrl_orEmpty(Io_url url, Io_url rootDir, String expd) {Tfds.Eq(expd, url.GenRelUrl_orEmpty(rootDir));}
	public void tst_GenParallel(Io_url url, Io_url oldRoot, Io_url newRoot, Io_url expd) {Tfds.Eq_url(expd, url.GenParallel(oldRoot, newRoot));}

	public String[] ary_(String... ary) {return String_.Ary(ary);}
	public static IoUrlFxt new_() {return new IoUrlFxt();}	IoUrlFxt() {}
}
