diff --git a/.editorconfig b/.editorconfig index db9ab4c..5bbb817 100644 --- a/.editorconfig +++ b/.editorconfig @@ -145,7 +145,7 @@ dotnet_naming_symbols.all_members.applicable_kinds = * dotnet_naming_style.pascal_case_style.capitalization = pascal_case -file_header_template = Copyright (c) $CURRENT_YEAR$ Koji Hasegawa.\nThis software is released under the MIT License. +file_header_template = Copyright (c) 2021-$CURRENT_YEAR$ Koji Hasegawa.\nThis software is released under the MIT License. # RS0016: Only enable if API files are present dotnet_public_api_analyzer.require_api_files = true diff --git a/Editor/AssemblyInfo.cs b/Editor/AssemblyInfo.cs new file mode 100644 index 0000000..90b6e40 --- /dev/null +++ b/Editor/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) 2021-2023 Koji Hasegawa. +// This software is released under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("CreateScriptFoldersWithTests.Editor.Tests")] diff --git a/Editor/AssemblyInfo.cs.meta b/Editor/AssemblyInfo.cs.meta new file mode 100644 index 0000000..886a9e2 --- /dev/null +++ b/Editor/AssemblyInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d2cc8d0d0da8463b9000ef3c720f9a6a +timeCreated: 1676239843 \ No newline at end of file diff --git a/Editor/DoCreateScriptFoldersWithTests.cs b/Editor/DoCreateScriptFoldersWithTests.cs index 3aafcbe..a82c82f 100644 --- a/Editor/DoCreateScriptFoldersWithTests.cs +++ b/Editor/DoCreateScriptFoldersWithTests.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using System.Text; +using CreateScriptFoldersWithTests.Editor.Internals; using UnityEditor; using UnityEditor.ProjectWindowCallback; using UnityEngine; @@ -44,6 +45,7 @@ private static void CreateSecondLayer(string pathName, string firstLayerName, st { AssetDatabase.CreateFolder(PathCombineAllowNull(pathName, firstLayerName), secondLayerName); CreateAssemblyDefinitionFile(pathName, firstLayerName, secondLayerName); + CreateDotSettingsFile(pathName, firstLayerName, secondLayerName); } private static void CreateAssemblyDefinitionFile(string pathName, string firstLayerName, string secondLayerName) @@ -65,13 +67,39 @@ private static void CreateAssemblyDefinitionFile(string pathName, string firstLa asmdef.AddReferences(moduleName); } - asmdef.rootNamespace = assemblyName.Replace($".{Tests}", ""); + if (IsUnderPackages(pathName)) + { + asmdef.rootNamespace = moduleName; + } var path = Path.Combine( PathCombineAllowNull(pathName, firstLayerName), secondLayerName, $"{assemblyName}.asmdef"); CreateScriptAssetWithContent(path, EditorJsonUtility.ToJson(asmdef)); } + private static void CreateDotSettingsFile(string pathName, string firstLayerName, string secondLayerName) + { + var moduleName = Path.GetFileName(pathName); + var assemblyName = AssemblyName(moduleName, firstLayerName, secondLayerName); + var dotSettingsCreator = new DotSettingsCreator(assemblyName); + + if (firstLayerName is Scripts || firstLayerName is Tests) + { + dotSettingsCreator.AddNamespaceFoldersToSkip(Path.Combine(pathName, firstLayerName)); + } + + if (secondLayerName == Runtime) + { + dotSettingsCreator.AddNamespaceFoldersToSkip( + Path.Combine(PathCombineAllowNull(pathName, firstLayerName), secondLayerName)); + } + + if (dotSettingsCreator.WasAddNamespaceFoldersToSkip()) + { + dotSettingsCreator.Flush(); + } + } + private static string AssemblyName(string moduleName, string firstLayerName, string secondLayerName) { var assemblyName = new StringBuilder(moduleName); @@ -107,6 +135,11 @@ private static bool IsUnderAssets(string pathName) return pathName.StartsWith("Assets/"); } + private static bool IsUnderPackages(string pathName) + { + return !IsUnderAssets(pathName); + } + private static string PathCombineAllowNull(string pathName, string firstLayerName) { return firstLayerName != null ? Path.Combine(pathName, firstLayerName) : pathName; diff --git a/Editor/Internals.meta b/Editor/Internals.meta new file mode 100644 index 0000000..4434d6a --- /dev/null +++ b/Editor/Internals.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 593a7c310cb6469484b0fd87ae87ad29 +timeCreated: 1676298117 \ No newline at end of file diff --git a/Editor/Internals/DotSettingsCreator.cs b/Editor/Internals/DotSettingsCreator.cs new file mode 100644 index 0000000..027ad4e --- /dev/null +++ b/Editor/Internals/DotSettingsCreator.cs @@ -0,0 +1,56 @@ +// Copyright (c) 2021-2023 Koji Hasegawa. +// This software is released under the MIT License. + +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace CreateScriptFoldersWithTests.Editor.Internals +{ + internal class DotSettingsCreator + { + private readonly string _assemblyName; + private readonly List _namespaceFoldersToSkip; + + public DotSettingsCreator(string assemblyName) + { + _assemblyName = assemblyName; + _namespaceFoldersToSkip = new List(); + } + + public void AddNamespaceFoldersToSkip(string path) + { + var key = path + .ToLower() + .Replace("/", "_005C") + .Replace(".", "_002E") + .Replace("-", "_002D") + .Replace(" ", "_0020") + .Replace("(", "_0028") + .Replace(")", "_0029"); + + _namespaceFoldersToSkip.Add( + $"True"); + } + + public bool WasAddNamespaceFoldersToSkip() + { + return _namespaceFoldersToSkip.Any(); + } + + public void Flush() + { + using (var writer = new StreamWriter($"{_assemblyName}.csproj.DotSettings")) + { + writer.WriteLine( + ""); + foreach (var s in _namespaceFoldersToSkip) + { + writer.WriteLine(s); + } + + writer.WriteLine(""); + } + } + } +} diff --git a/Editor/Internals/DotSettingsCreator.cs.meta b/Editor/Internals/DotSettingsCreator.cs.meta new file mode 100644 index 0000000..3a85673 --- /dev/null +++ b/Editor/Internals/DotSettingsCreator.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f5348cad1e434e1fa6b0bff7e31349bd +timeCreated: 1676231661 \ No newline at end of file diff --git a/README.md b/README.md index 095e14a..d8767ac 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,18 @@ [![Test](https://github.com/nowsprinting/create-script-folders-with-tests/actions/workflows/test.yml/badge.svg)](https://github.com/nowsprinting/create-script-folders-with-tests/actions/workflows/test.yml) [![openupm](https://img.shields.io/npm/v/com.nowsprinting.create-script-folders-with-tests?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.nowsprinting.create-script-folders-with-tests/) -This Unity Editor Extensions create script folders (Editor, Runtime, and each Tests) containing assembly definition file (.asmdef). +This Unity editor extensions create script folders (Editor, Runtime, and each Tests) containing assembly definition file (.asmdef). -### Using under Assets folder: +## Features When opening the context menu and select **Create | C# Script Folders and Assemblies with Tests**, The root folder (e.g., named "YourFeature") and below will be created as follows. +### Creating folders and asmdefs + +#### Using under Assets folder + ``` Assets └── YourFeature @@ -27,21 +31,7 @@ Assets    └── YourFeature.Tests.asmdef ``` -And the references of each asmdef are set as follows. - -- `YourFeature` has not references -- `YourFeature.Editor` has references to `YourFeature` -- `YourFeature.Tests` has references to `YourFeature` -- `YourFeature.Editor.Tests` has references to `YourFeature` and `YourFeature.Editor` - - -### Using under Packages folder: - -First, your package folder (e.g., named "your.package.name") must be created in advance. -Because can not open the context menu directly under the Packages folder. - -Next, opening the context menu and select **Create | C# Script Folders and Assemblies with Tests**, -The root folder (e.g., named "YourFeature") and below will be created as follows. +#### Using under Packages folder ``` Packages @@ -58,10 +48,62 @@ Packages       └── YourFeature.Tests.asmdef ``` +Package folder (e.g., named "your.package.name") must be created in before. +Because can not open the context menu directly under the Packages folder. + After creating folders, move the Editor, Runtime and Tests folders directly under the "your.package.name" folder. And remove the "YourFeature" folder. +Then it will be the same as the official [package layout](https://docs.unity3d.com/Manual/cus-layout.html). + +``` +Packages +└── your.package.name +   ├── Editor +   │   └── YourFeature.Editor.asmdef +   ├── Runtime +   │   └── YourFeature.asmdef +   └── Tests +   ├── Editor +   │   └── YourFeature.Editor.Tests.asmdef +   └── Runtime +   └── YourFeature.Tests.asmdef +``` + + +### Assembly Definition References in asmdefs + +"Assembly Definition References" in each asmdef are set as follows. + +- `YourFeature.Editor` has references to `YourFeature` +- `YourFeature` has not references +- `YourFeature.Tests` has references to `YourFeature` +- `YourFeature.Editor.Tests` has references to `YourFeature` and `YourFeature.Editor` + + +### Creating DotSettings files + +And creating .csproj.DotSettings file for each assembly. +This file is set up to make the "Namespace does not correspond to file location" inspection work as expected in JetBrains Rider. +Do not forget to commit .DotSettings files for that project. + +Specifically, disabled the [Namespace provider](https://www.jetbrains.com/help/rider/Refactorings__Adjust_Namespaces.html) for the following folders. + +- Scripts +- Scripts/Runtime +- Tests +- Tests/Runtime + +This will result in the expected namespace per folder as follows. + +- Scripts/Editor: YourFeature.Editor +- Scripts/Runtime: YourFeature +- Tests/Editor: YourFeature.Editor +- Tests/Runtime: YourFeature + +See more information: -Then it will be the same as the official [Package layout](https://docs.unity3d.com/Manual/cus-layout.html). +- [Code Inspections in C# | JetBrains Rider Documentation](https://www.jetbrains.com/help/rider/Reference__Code_Inspections_CSHARP.html) +- [Code Inspection: Namespace does not correspond to file location | JetBrains Rider Documentation](https://www.jetbrains.com/help/rider/CheckNamespace.html) ## Installation diff --git a/Tests/Editor/DoCreateScriptFoldersWithTestsTest.cs b/Tests/Editor/DoCreateScriptFoldersWithTestsTest.cs index 96928a9..803f506 100644 --- a/Tests/Editor/DoCreateScriptFoldersWithTestsTest.cs +++ b/Tests/Editor/DoCreateScriptFoldersWithTestsTest.cs @@ -12,15 +12,25 @@ namespace CreateScriptFoldersWithTests.Editor public class DoCreateScriptFoldersWithTestsTest { private const string ModuleName = "CreateScriptFoldersWithTestsTarget"; + private const string DotSettingsSuffix = ".csproj.DotSettings"; private readonly string _rootFolderPath = Path.Combine("Assets", ModuleName); + private static readonly string s_rootEncoded = "assets_005C" + ModuleName.ToLower(); + private static readonly string s_foldersToSkipScripts = $"{s_rootEncoded}_005Cscripts/"; + private static readonly string s_foldersToSkipScriptsRuntime = $"{s_rootEncoded}_005Cscripts_005Cruntime/"; + private static readonly string s_foldersToSkipTests = $"{s_rootEncoded}_005Ctests/"; + private static readonly string s_foldersToSkipTestsRuntime = $"{s_rootEncoded}_005Ctests_005Cruntime/"; [OneTimeSetUp] public void OneTimeSetUp() { AssetDatabase.DisallowAutoRefresh(); - var exist = AssetDatabase.IsValidFolder(_rootFolderPath); - Assume.That(exist, Is.False, "Generated folder does not exist before test"); + // Generated folder and files does not exist before test + Assume.That(AssetDatabase.IsValidFolder(_rootFolderPath), Is.False); + Assume.That(new FileInfo(ModuleName + DotSettingsSuffix), Does.Not.Exist); + Assume.That(new FileInfo(ModuleName + ".Editor" + DotSettingsSuffix), Does.Not.Exist); + Assume.That(new FileInfo(ModuleName + ".Tests" + DotSettingsSuffix), Does.Not.Exist); + Assume.That(new FileInfo(ModuleName + ".Editor.Tests" + DotSettingsSuffix), Does.Not.Exist); var sut = ScriptableObject.CreateInstance(); sut.Action(0, _rootFolderPath, null); @@ -49,7 +59,14 @@ public void Action_CreatedRuntimeFolderContainingAsmdef() Assert.That(asmdef.defineConstraints, Is.Empty); Assert.That(asmdef.includePlatforms, Is.Empty); Assert.That(asmdef.references, Is.Empty); - Assert.That(asmdef.rootNamespace, Is.EqualTo(AssemblyName)); + Assert.That(asmdef.rootNamespace, Is.Empty); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipScripts)); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipScriptsRuntime)); + + File.Delete(DotSettingsPath); } [Test] @@ -67,7 +84,13 @@ public void Action_CreatedEditorFolderContainingAsmdef() Assert.That(asmdef.defineConstraints, Is.Empty); Assert.That(asmdef.includePlatforms, Does.Contain("Editor")); Assert.That(asmdef.references, Does.Contain(ModuleName)); - Assert.That(asmdef.rootNamespace, Is.EqualTo(AssemblyName)); + Assert.That(asmdef.rootNamespace, Is.Empty); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipScripts)); + + File.Delete(DotSettingsPath); } [Test] @@ -94,7 +117,14 @@ public void Action_CreatedRuntimeTestsFolderContainingAsmdef() #else Assert.That(asmdef.optionalUnityReferences, Does.Contain("TestAssemblies")); #endif - Assert.That(asmdef.rootNamespace, Is.EqualTo(ModuleName)); + Assert.That(asmdef.rootNamespace, Is.Empty); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipTests)); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipTestsRuntime)); + + File.Delete(DotSettingsPath); } [Test] @@ -123,7 +153,13 @@ public void Action_CreatedEditorTestsFolderContainingAsmdef() #else Assert.That(asmdef.optionalUnityReferences, Does.Contain("TestAssemblies")); #endif - Assert.That(asmdef.rootNamespace, Is.EqualTo(EditorAssemblyName)); + Assert.That(asmdef.rootNamespace, Is.Empty); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipTests)); + + File.Delete(DotSettingsPath); } } } diff --git a/Tests/Editor/DoCreateScriptFoldersWithTestsTestUnderPackages.cs b/Tests/Editor/DoCreateScriptFoldersWithTestsTestUnderPackages.cs index fec300c..ac3aab1 100644 --- a/Tests/Editor/DoCreateScriptFoldersWithTestsTestUnderPackages.cs +++ b/Tests/Editor/DoCreateScriptFoldersWithTestsTestUnderPackages.cs @@ -12,17 +12,30 @@ namespace CreateScriptFoldersWithTests.Editor public class DoCreateScriptFoldersWithTestsTestUnderPackages { private const string ModuleName = "CreateScriptFoldersWithTestsTarget"; + private const string DotSettingsSuffix = ".csproj.DotSettings"; private readonly string _rootFolderPath = Path.Combine("Packages", "com.nowsprinting.create-script-folders-with-tests", ModuleName); + private static readonly string s_rootEncoded = + "packages_005Ccom_002Enowsprinting_002Ecreate_002Dscript_002Dfolders_002Dwith_002Dtests_005C" + + ModuleName.ToLower(); + + private static readonly string s_foldersToSkipRuntime = $"{s_rootEncoded}_005Cruntime/"; + private static readonly string s_foldersToSkipTests = $"{s_rootEncoded}_005Ctests/"; + private static readonly string s_foldersToSkipTestsRuntime = $"{s_rootEncoded}_005Ctests_005Cruntime/"; + [OneTimeSetUp] public void OneTimeSetUp() { AssetDatabase.DisallowAutoRefresh(); - var exist = AssetDatabase.IsValidFolder(_rootFolderPath); - Assume.That(exist, Is.False, "Generated folder does not exist before test"); + // Generated folder and files does not exist before test + Assume.That(AssetDatabase.IsValidFolder(_rootFolderPath), Is.False); + Assume.That(new FileInfo(ModuleName + DotSettingsSuffix), Does.Not.Exist); + Assume.That(new FileInfo(ModuleName + ".Editor" + DotSettingsSuffix), Does.Not.Exist); + Assume.That(new FileInfo(ModuleName + ".Tests" + DotSettingsSuffix), Does.Not.Exist); + Assume.That(new FileInfo(ModuleName + ".Editor.Tests" + DotSettingsSuffix), Does.Not.Exist); var sut = ScriptableObject.CreateInstance(); sut.Action(0, _rootFolderPath, null); @@ -52,7 +65,13 @@ public void Action_CreatedRuntimeFolderContainingAsmdef() Assert.That(asmdef.defineConstraints, Is.Empty); Assert.That(asmdef.includePlatforms, Is.Empty); Assert.That(asmdef.references, Is.Empty); - Assert.That(asmdef.rootNamespace, Is.EqualTo(AssemblyName)); + Assert.That(asmdef.rootNamespace, Is.EqualTo(ModuleName)); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipRuntime)); + + File.Delete(DotSettingsPath); } [Test] @@ -71,7 +90,11 @@ public void Action_CreatedEditorFolderContainingAsmdef() Assert.That(asmdef.defineConstraints, Is.Empty); Assert.That(asmdef.includePlatforms, Does.Contain("Editor")); Assert.That(asmdef.references, Does.Contain(ModuleName)); - Assert.That(asmdef.rootNamespace, Is.EqualTo(AssemblyName)); + Assert.That(asmdef.rootNamespace, Is.EqualTo(ModuleName)); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Not.Exist); + // Does not create DotSettings only Packages/Editor case } [Test] @@ -99,6 +122,13 @@ public void Action_CreatedRuntimeTestsFolderContainingAsmdef() Assert.That(asmdef.optionalUnityReferences, Does.Contain("TestAssemblies")); #endif Assert.That(asmdef.rootNamespace, Is.EqualTo(ModuleName)); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipTests)); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipTestsRuntime)); + + File.Delete(DotSettingsPath); } [Test] @@ -127,7 +157,13 @@ public void Action_CreatedEditorTestsFolderContainingAsmdef() #else Assert.That(asmdef.optionalUnityReferences, Does.Contain("TestAssemblies")); #endif - Assert.That(asmdef.rootNamespace, Is.EqualTo(EditorAssemblyName)); + Assert.That(asmdef.rootNamespace, Is.EqualTo(ModuleName)); + + const string DotSettingsPath = AssemblyName + DotSettingsSuffix; + Assume.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Does.Contain(s_foldersToSkipTests)); + + File.Delete(DotSettingsPath); } } } diff --git a/Tests/Editor/Helpers.meta b/Tests/Editor/Helpers.meta new file mode 100644 index 0000000..61ca0cd --- /dev/null +++ b/Tests/Editor/Helpers.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4c2a8d4d4f77468c8e1730ddfe457fd5 +timeCreated: 1676325968 \ No newline at end of file diff --git a/Tests/Editor/Helpers/ShrinkSpaceComparer.cs b/Tests/Editor/Helpers/ShrinkSpaceComparer.cs new file mode 100644 index 0000000..5c516b0 --- /dev/null +++ b/Tests/Editor/Helpers/ShrinkSpaceComparer.cs @@ -0,0 +1,39 @@ +// Copyright (c) 2021-2023 Koji Hasegawa. +// This software is released under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace CreateScriptFoldersWithTests.Editor.Helpers +{ + /// + /// Consecutive spaces and tabs shrink to a single space + /// Ignore line breaks + /// + public class ShrinkSpaceComparer : IComparer + { + /// + public int Compare(string x, string y) + { + var compere = string.Compare(Shrink(x), Shrink(y), StringComparison.Ordinal); + if (compere == 0) + { + return 0; + } + + Debug.Log($"Expected: \"{Shrink(x)}\""); + Debug.Log($"But was: \"{Shrink(y)}\""); + + return compere; + } + + private static string Shrink(string s) + { + return Regex.Replace( + s.Replace(Environment.NewLine, string.Empty), + "\\s+", " "); + } + } +} diff --git a/Tests/Editor/Helpers/ShrinkSpaceComparer.cs.meta b/Tests/Editor/Helpers/ShrinkSpaceComparer.cs.meta new file mode 100644 index 0000000..a6ce1fe --- /dev/null +++ b/Tests/Editor/Helpers/ShrinkSpaceComparer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: db2ed8d1eea0478a8708f30f8cdfeaef +timeCreated: 1676324954 \ No newline at end of file diff --git a/Tests/Editor/Internals.meta b/Tests/Editor/Internals.meta new file mode 100644 index 0000000..7cd1de7 --- /dev/null +++ b/Tests/Editor/Internals.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2df55e26bbce4550b2d70d6d34cff77c +timeCreated: 1676298138 \ No newline at end of file diff --git a/Tests/Editor/Internals/DotSettingsCreatorTests.cs b/Tests/Editor/Internals/DotSettingsCreatorTests.cs new file mode 100644 index 0000000..af79f40 --- /dev/null +++ b/Tests/Editor/Internals/DotSettingsCreatorTests.cs @@ -0,0 +1,66 @@ +// Copyright (c) 2021-2023 Koji Hasegawa. +// This software is released under the MIT License. + +using System.IO; +using CreateScriptFoldersWithTests.Editor.Helpers; +using NUnit.Framework; + +namespace CreateScriptFoldersWithTests.Editor.Internals +{ + public class DotSettingsCreatorTests + { + private const string ModuleName = "CreateScriptFoldersWithTestsTarget"; + private const string DotSettingsSuffix = ".csproj.DotSettings"; + private const string DotSettingsPath = ModuleName + DotSettingsSuffix; + + [SetUp] + public void SetUp() + { + Assume.That(new FileInfo(DotSettingsPath), Does.Not.Exist); + } + + [Test] + public void DotSettingsCreator_CreatedDotSettingsFile() + { + var sut = new DotSettingsCreator(ModuleName); + sut.Flush(); + + Assert.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Is.EqualTo(@" +") + .Using(new ShrinkSpaceComparer())); + + File.Delete(DotSettingsPath); + } + + [Test] + public void AddNamespaceFoldersToSkip_DotSettingsContainNamespaceFoldersToSkipElement() + { + var sut = new DotSettingsCreator(ModuleName); + sut.AddNamespaceFoldersToSkip("Packages/com.nowsprinting.create-script-folders-with-tests/Foo"); + sut.AddNamespaceFoldersToSkip("Packages/com.nowsprinting.create-script-folders-with-tests/Foo/Bar"); + sut.AddNamespaceFoldersToSkip("Packages/com.nowsprinting.create-script-folders-with-tests/New Feature (1)"); + sut.Flush(); + + Assert.That(new FileInfo(DotSettingsPath), Does.Exist); + Assert.That(File.ReadAllText(DotSettingsPath), Is.EqualTo(@" +True +True +True +") + .Using(new ShrinkSpaceComparer())); + + File.Delete(DotSettingsPath); + } + } +} diff --git a/Tests/Editor/Internals/DotSettingsCreatorTests.cs.meta b/Tests/Editor/Internals/DotSettingsCreatorTests.cs.meta new file mode 100644 index 0000000..2c2e465 --- /dev/null +++ b/Tests/Editor/Internals/DotSettingsCreatorTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a507901621de428bbda0ffb3b63b1b11 +timeCreated: 1676231982 \ No newline at end of file