<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.IO;
using NUnit.Framework;
using osu.Framework.Testing;

namespace osu.Framework.Tests.IO
{
    [TestFixture]
    public class TestDesktopStorage
    {
        [Test]
        public void TestRelativePaths()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                string basePath = storage.GetFullPath(string.Empty);

                Assert.IsTrue(basePath.EndsWith(guid, StringComparison.Ordinal));

                Assert.Throws<ArgumentException>(() => storage.GetFullPath("../"));
                Assert.Throws<ArgumentException>(() => storage.GetFullPath(".."));
                Assert.Throws<ArgumentException>(() => storage.GetFullPath("./../"));

                Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")) + Path.DirectorySeparatorChar, storage.GetFullPath("sub/test/"));
                Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")), storage.GetFullPath("sub/test"));
            }
        }

        [Test]
        public void TestAttemptEscapeRoot()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.Throws<ArgumentException>(() =>
                {
                    using var x = storage.GetStream("../test");
                });

                Assert.Throws<ArgumentException>(() => storage.GetStorageForDirectory("../"));
            }
        }

        [Test]
        public void TestGetSubDirectoryStorage()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.That(storage.GetStorageForDirectory("subdir").GetFullPath(string.Empty), Is.EqualTo(Path.Combine(storage.GetFullPath(string.Empty), "subdir")));
            }
        }

        [Test]
        public void TestGetEmptySubDirectoryStorage()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.That(storage.GetStorageForDirectory(string.Empty).GetFullPath(string.Empty), Is.EqualTo(storage.GetFullPath(string.Empty)));
            }
        }
    }<commit_msg>Add failing test coverage of case insensitive file system lookups working correctly<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.IO;
using NUnit.Framework;
using osu.Framework.Testing;

namespace osu.Framework.Tests.IO
{
    [TestFixture]
    public class TestDesktopStorage
    {
        [Test]
        public void TestRelativePaths()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                string basePath = storage.GetFullPath(string.Empty);

                Assert.IsTrue(basePath.EndsWith(guid, StringComparison.Ordinal));

                Assert.Throws<ArgumentException>(() => storage.GetFullPath("../"));
                Assert.Throws<ArgumentException>(() => storage.GetFullPath(".."));
                Assert.Throws<ArgumentException>(() => storage.GetFullPath("./../"));

                Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")) + Path.DirectorySeparatorChar, storage.GetFullPath("sub/test/"));
                Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")), storage.GetFullPath("sub/test"));
            }
        }

        [Test]
        public void TestAttemptEscapeRoot()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.Throws<ArgumentException>(() =>
                {
                    using var x = storage.GetStream("../test");
                });

                Assert.Throws<ArgumentException>(() => storage.GetStorageForDirectory("../"));
            }
        }

        [Test]
        public void TestGetSubDirectoryStorage()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.That(storage.GetStorageForDirectory("subdir").GetFullPath(string.Empty), Is.EqualTo(Path.Combine(storage.GetFullPath(string.Empty), "subdir")));
            }
        }

        [Test]
        public void TestGetEmptySubDirectoryStorage()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.That(storage.GetStorageForDirectory(string.Empty).GetFullPath(string.Empty), Is.EqualTo(storage.GetFullPath(string.Empty)));
            }
        }

        [Test]
        public void TestCaseSensitivity()
        {
            // First test if this unit test is running on a filesystem which is case sensitive.
            File.WriteAllText(Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, "case-sensitivity-test"), "test");
            bool isCaseSensitive = !File.Exists(Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, "CASE-SENSITIVITY-TEST"));
            File.Delete("case-sensitivity-test");

            // Then check our methods match this.
            using (var storage = new TemporaryNativeStorage("test"))
            {
                using (var stream = storage.CreateFileSafely("test-file"))
                    stream.WriteByte(0);

                Assert.That(storage.Exists("test-file"), Is.True);
                Assert.That(storage.Exists("TEST-FILE"), Is.EqualTo(!isCaseSensitive));

                using (var storage2 = new TemporaryNativeStorage("TEST"))
                {
                    Assert.That(storage2.Exists("test-file"), Is.EqualTo(!isCaseSensitive));
                    Assert.That(storage2.Exists("TEST-FILE"), Is.EqualTo(!isCaseSensitive));

                    // Test that base path lookup checks don't incorrectly fail.
                    // This should pass regardless of case sensitivity of the underlying partition.
                    var nested = storage2.GetStorageForDirectory("subdir");

                    using (var stream = nested.CreateFileSafely("test-file"))
                        stream.WriteByte(0);

                    Assert.That(nested.GetDirectories(string.Empty), Is.Empty);
                    Assert.That(nested.GetFiles(string.Empty), Has.One.Items);
                }
            }
        }
    }
{'fraction_non_alphanumeric': 0.12039312039312039, 'fraction_numerical': 0.000867177337765573, 'mean_word_length': 2.0892857142857144, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649807', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1723, 'n_words': 339}