<commit_before>﻿using System;
using System.IO;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Zongsoft.IO
{
	[TestClass]
	public class FileSystemTest
	{
		public FileSystemTest()
		{
			FileSystem.Providers.Register(LocalFileSystem.Instance, typeof(IFileSystem));
		}

		[TestMethod]
		public void DirectoryCreate()
		{
			var text = @"zfs.local:/c/temp/year/month-day/[1]123.jpg";
			var path = Path.Parse(text);

			var directoryPath = path.Schema + ":" + path.DirectoryName;

			FileSystem.Directory.Create(directoryPath);

			Assert.IsTrue(FileSystem.Directory.Exists(directoryPath));
			Assert.IsTrue(FileSystem.Directory.Delete(directoryPath));
		}
	}<commit_msg>增加了一个目录和文件搜索的单元测试。 :radio_button:<commit_after>﻿using System;
using System.IO;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Zongsoft.IO
{
	[TestClass]
	public class FileSystemTest
	{
		public FileSystemTest()
		{
			FileSystem.Providers.Register(LocalFileSystem.Instance, typeof(IFileSystem));
		}

		[TestMethod]
		public void DirectoryCreate()
		{
			var text = @"zfs.local:/d/temp/sub-dir/[1]123.jpg";
			var path = Path.Parse(text);

			var directoryUrl = path.Schema + ":" + path.DirectoryName;

			//创建目录
			FileSystem.Directory.Create(directoryUrl);

			Assert.IsTrue(FileSystem.Directory.Exists(directoryUrl));
			Assert.IsTrue(FileSystem.Directory.Delete(directoryUrl));
		}

		[TestMethod]
		public void DirectoryGetFilesTest()
		{
			const int FILE_COUNT = 10;

			if(!FileSystem.Directory.Exists("zfs.local:/d/temp/"))
				FileSystem.Directory.Create("zfs.local:/d/temp/");

			//生成一个随机的文件前缀名
			var prefix = string.Format("[{0:yyyyMMdd}]{1:N}", DateTime.Today, Guid.NewGuid());

			for(int i = 1; i <= FILE_COUNT; i++)
			{
				//创建临时文件
				using(var stream = FileSystem.File.Open(string.Format("zfs.local:/d/temp/{1}({0}).{2}", i, prefix, (i % 2 == 0 ? "log" : "txt")), FileMode.Create, FileAccess.Write))
				{
					Zongsoft.Runtime.Serialization.Serializer.Text.Serialize(stream, i.ToString());
				}
			}

			var count = 0;
			//使用正则匹配的方式查找文件
			var infos = LocalFileSystem.Instance.Directory.GetFiles(@"D:\temp", prefix + @"(/\d+/).log");

			foreach(var info in infos)
			{
				Assert.IsTrue(info.Name.StartsWith(prefix + "("));
				Assert.IsTrue(info.Name.EndsWith(").log"));

				count++;
			}

			Assert.IsTrue(count >= FILE_COUNT / 2);
			count = 0;

			//使用文件系统匹配的方式查找文件
			infos = LocalFileSystem.Instance.Directory.GetFiles(@"D:\temp", prefix + "*");

			foreach(var info in infos)
			{
				Assert.IsTrue(info.Name.StartsWith(prefix + "("));
				Assert.IsTrue(info.Name.EndsWith(").log") || info.Name.EndsWith(").txt"));

				//删除临时文件
				LocalFileSystem.Instance.File.Delete(info.Path.Url);

				count++;
			}

			Assert.IsTrue(count == FILE_COUNT);
		}
	}
{'fraction_non_alphanumeric': 0.16140602582496413, 'fraction_numerical': 0.007532281205164993, 'mean_word_length': 3.910211267605634, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2198430', 'n_tokens_mistral': 1167, 'n_tokens_neox': 997, 'n_words': 142}