local N=require("\064\102\114\107\116\101\115\116\047")local f=N.test local u=N.assert.check local p=require("\046\046\047\115\114\099\047\108\105\098")local b=p.fs return function()local N="\116\101\115\116\115\047\116\101\115\116\049\046\116\120\116"local E="\116\101\115\116\115\047\116\101\115\116\050\046\116\120\116"local A="\116\101\115\116\115\047\116\101\115\116\051\046\116\120\116"local K="\072\101\108\108\111\044 \119\111\114\108\100\033"f.suite("\119\114\105\116\105\110\103 \102\105\108\101\115",function()f.case("\102\114\111\109 \115\116\114\105\110\103 \112\097\116\104\115",function()b.writeFile(N,K)b.move(N,E)b.copy(E,A)b.writeFile(E,"")b.removeFile(E)b.removeFile(A)end)f.case("\102\114\111\109 \099\111\109\112\111\110\101\110\116\115",function()local f=(p.Path.from(N)):components()local u=(p.Path.from(E)):components()local Q=(p.Path.from(A)):components()b.writeFile(f,K)b.move(f,u)b.copy(u,Q)b.writeFile(u,"")b.removeFile(u)b.removeFile(Q)end)f.case("\102\114\111\109 \112\097\116\104\115",function()local f=p.Path.from(N)local u=p.Path.from(E)local Q=p.Path.from(A)b.writeFile(f,K)b.move(f,u)b.copy(u,Q)b.writeFile(u,"")b.removeFile(u)b.removeFile(Q)end)end)f.suite("\114\101\097\100\105\110\103 \102\105\108\101\115",function()f.case("\102\114\111\109 \115\116\114\105\110\103 \112\097\116\104\115",function()b.writeFile(N,K)u.equal(b.readFile(N),K)b.move(N,E)u.equal(b.readFile(E),K)b.copy(E,A)u.equal(b.readFile(A),K)b.removeFile(E)b.removeFile(A)end)f.case("\102\114\111\109 \099\111\109\112\111\110\101\110\116\115",function()local f=(p.Path.from(N)):components()local Q=(p.Path.from(E)):components()local t=(p.Path.from(A)):components()b.writeFile(f,K)u.equal(b.readFile(f),K)b.move(f,Q)u.equal(b.readFile(Q),K)b.copy(Q,t)u.equal(b.readFile(t),K)b.removeFile(Q)b.removeFile(t)end)f.case("\102\114\111\109 \112\097\116\104\115",function()local f=p.Path.from(N)local Q=p.Path.from(E)local t=p.Path.from(A)b.writeFile(f,K)u.equal(b.readFile(f),K)b.move(f,Q)u.equal(b.readFile(Q),K)b.copy(Q,t)u.equal(b.readFile(t),K)b.removeFile(Q)b.removeFile(t)end)end)local Q="\116\101\115\116\115\047\116\101\115\116\100\105\114"f.suite("\119\114\105\116\105\110\103 \100\105\114\101\099\116\111\114\105\101\115",function()f.case("\102\114\111\109 \115\116\114\105\110\103 \112\097\116\104\115",function()b.writeDir(Q)b.removeDir(Q)end)f.case("\102\114\111\109 \099\111\109\112\111\110\101\110\116\115",function()local N=(p.Path.from(Q)):components()b.writeDir(N)b.removeDir(N)end)f.case("\102\114\111\109 \112\097\116\104\115",function()local N=p.Path.from(Q)b.writeDir(N)b.removeDir(N)end)end)f.suite("\114\101\097\100\105\110\103 \100\105\114\101\099\116\111\114\105\101\115",function()f.case("\102\114\111\109 \115\116\114\105\110\103 \112\097\116\104\115",function()b.writeDir(Q)u.truthy(b.readDir(Q))b.removeDir(Q)end)f.case("\102\114\111\109 \099\111\109\112\111\110\101\110\116\115",function()local N=(p.Path.from(Q)):components()b.writeDir(N)u.truthy(b.readDir(N))b.removeDir(N)end)f.case("\102\114\111\109 \112\097\116\104\115",function()local N=p.Path.from(Q)b.writeDir(N)u.truthy(b.readDir(N))b.removeDir(N)end)end)end
local frktest = require("@frktest/")
local test = frktest.test
local check = frktest.assert.check
local pathfs = require("../src/lib")
local fs = pathfs.fs

return function()
	local test1 = "tests/test1.txt"
	local test2 = "tests/test2.txt"
	local test3 = "tests/test3.txt"
	local test_content = "Hello, world!"

	test.suite("writing files", function()
		test.case("from string paths", function()
			fs.writeFile(test1, test_content)
			fs.move(test1, test2)
			fs.copy(test2, test3)
			fs.writeFile(test2, "")
			fs.removeFile(test2)
			fs.removeFile(test3)
		end)

		test.case("from components", function()
			local components_test1 = pathfs.Path.from(test1):components()
			local components_test2 = pathfs.Path.from(test2):components()
			local components_test3 = pathfs.Path.from(test3):components()

			fs.writeFile(components_test1, test_content)
			fs.move(components_test1, components_test2)
			fs.copy(components_test2, components_test3)
			fs.writeFile(components_test2, "")
			fs.removeFile(components_test2)
			fs.removeFile(components_test3)
		end)

		test.case("from paths", function()
			local path_test1 = pathfs.Path.from(test1)
			local path_test2 = pathfs.Path.from(test2)
			local path_test3 = pathfs.Path.from(test3)

			fs.writeFile(path_test1, test_content)
			fs.move(path_test1, path_test2)
			fs.copy(path_test2, path_test3)
			fs.writeFile(path_test2, "")
			fs.removeFile(path_test2)
			fs.removeFile(path_test3)
		end)
	end)

	test.suite("reading files", function()
		test.case("from string paths", function()
			fs.writeFile(test1, test_content)
			check.equal(fs.readFile(test1), test_content)
			fs.move(test1, test2)
			check.equal(fs.readFile(test2), test_content)
			fs.copy(test2, test3)
			check.equal(fs.readFile(test3), test_content)
			fs.removeFile(test2)
			fs.removeFile(test3)
		end)

		test.case("from components", function()
			local components_test1 = pathfs.Path.from(test1):components()
			local components_test2 = pathfs.Path.from(test2):components()
			local components_test3 = pathfs.Path.from(test3):components()

			fs.writeFile(components_test1, test_content)
			check.equal(fs.readFile(components_test1), test_content)
			fs.move(components_test1, components_test2)
			check.equal(fs.readFile(components_test2), test_content)
			fs.copy(components_test2, components_test3)
			check.equal(fs.readFile(components_test3), test_content)
			fs.removeFile(components_test2)
			fs.removeFile(components_test3)
		end)

		test.case("from paths", function()
			local path_test1 = pathfs.Path.from(test1)
			local path_test2 = pathfs.Path.from(test2)
			local path_test3 = pathfs.Path.from(test3)

			fs.writeFile(path_test1, test_content)
			check.equal(fs.readFile(path_test1), test_content)
			fs.move(path_test1, path_test2)
			check.equal(fs.readFile(path_test2), test_content)
			fs.copy(path_test2, path_test3)
			check.equal(fs.readFile(path_test3), test_content)
			fs.removeFile(path_test2)
			fs.removeFile(path_test3)
		end)
	end)

	local test_dir = "tests/testdir"

	test.suite("writing directories", function()
		test.case("from string paths", function()
			fs.writeDir(test_dir)
			fs.removeDir(test_dir)
		end)

		test.case("from components", function()
			local components = pathfs.Path.from(test_dir):components()
			fs.writeDir(components)
			fs.removeDir(components)
		end)

		test.case("from paths", function()
			local path = pathfs.Path.from(test_dir)
			fs.writeDir(path)
			fs.removeDir(path)
		end)
	end)

	test.suite("reading directories", function()
		test.case("from string paths", function()
			fs.writeDir(test_dir)
			check.truthy(fs.readDir(test_dir))
			fs.removeDir(test_dir)
		end)

		test.case("from components", function()
			local components = pathfs.Path.from(test_dir):components()
			fs.writeDir(components)
			check.truthy(fs.readDir(components))
			fs.removeDir(components)
		end)

		test.case("from paths", function()
			local path = pathfs.Path.from(test_dir)
			fs.writeDir(path)
			check.truthy(fs.readDir(path))
			fs.removeDir(path)
		end)
	end)
end
