public void TestIsSettingSet() { //setup BasePackNamespace pack = new NamespaceTestClass(new DatapackTestClass("a folder path", "pack"), "namespace"); //test Assert.IsTrue(pack.IsSettingSet(NamespaceSettings.GetSettings().FunctionGroupedCommands()), "Failed to detect that the setting is set"); Assert.IsFalse(pack.IsSettingSet(NamespaceSettings.GetSettings().GenerateNames()), "Failed to detect that the setting isn't set"); pack.Dispose(); }
public NamespaceTestClass(BaseDatapack datapack, string name) : base(datapack, name) { settings.Add(NamespaceSettings.GetSettings().FunctionGroupedCommands()); #pragma warning disable IDE0067 new BaseFileTestClass1(this, "file1", BaseFile.WriteSetting.OnDispose); new BaseFileTestClass1(this, "file2", BaseFile.WriteSetting.Auto); new BaseFileTestClass2(this, "file1", BaseFile.WriteSetting.Auto); new BaseFileTestClass2(this, "file2", BaseFile.WriteSetting.Auto); new BaseFileTestClass2(this, "file3", BaseFile.WriteSetting.LockedAuto); #pragma warning restore IDE0067 }
public static TypescriptGenerator ConfigureNamespace(this TypescriptGenerator generator, string namespaceName, Action <NamespaceSettings> options) { if (generator.NamespaceSettings.Exists(x => x.Namespace == namespaceName)) { throw new InvalidOperationException($"Namespace '{namespaceName}' is already configured"); } var namespaceSettings = new NamespaceSettings(namespaceName); options(namespaceSettings); generator.NamespaceSettings.Add(namespaceSettings); return(generator); }
public void TranslateOnlyReplacesLeadingPart() { var input = "MyNamespace.MyNamespace.Test"; var translation = "Models"; var settings = new NamespaceSettings("MyNamespace") { Translation = translation }; var actual = NamespaceTranslator.Translate(input, new List <NamespaceSettings> { settings }); Assert.That(actual, Is.EqualTo("Models.MyNamespace.Test")); }
public void TranslateReturnsTranslatedForExactMatch() { var input = "MyNamespace.Test"; var translation = "Models"; var settings = new NamespaceSettings(input) { Translation = translation }; var actual = NamespaceTranslator.Translate(input, new List <NamespaceSettings> { settings }); Assert.That(actual, Is.EqualTo(translation)); }
public NamespaceType( string aliasName, NamespaceSettings settings, IEnumerable <TypeProperty> properties, IEnumerable <FunctionOverload> functionOverloads, IEnumerable <BannedFunction> bannedFunctions, IEnumerable <Decorator> decorators, IResourceTypeProvider resourceTypeProvider) : base(aliasName, TypeSymbolValidationFlags.PreventAssignment, properties, null, TypePropertyFlags.None, obj => new FunctionResolver(obj, functionOverloads, bannedFunctions)) { Settings = settings; ResourceTypeProvider = resourceTypeProvider; DecoratorResolver = new DecoratorResolver(this, decorators); }
public void TestDIsposeFileSetting() { using Datapack pack = new Datapack("a path", "name", ".", 4, new NoneFileCreator()); PackNamespace space = pack.Namespace("space"); space.AddSetting(NamespaceSettings.GetSettings().ForceDisposeWriteFiles()); BaseFile file1 = space.Function("file1", BaseFile.WriteSetting.Auto); BaseFile file2 = space.Function("file2", BaseFile.WriteSetting.LockedAuto); BaseFile file3 = space.Function("file3", BaseFile.WriteSetting.LockedOnDispose); BaseFile file4 = space.Function("file4", BaseFile.WriteSetting.OnDispose); Assert.AreEqual(BaseFile.WriteSetting.OnDispose, file1.Setting, "Auto should have changed to OnDispose"); Assert.AreEqual(BaseFile.WriteSetting.LockedOnDispose, file2.Setting, "LockedAuto should have changed to LockedOnDispose"); Assert.AreEqual(BaseFile.WriteSetting.LockedOnDispose, file3.Setting, "LockedOnDispose shouldn't change"); Assert.AreEqual(BaseFile.WriteSetting.OnDispose, file4.Setting, "OnDispose shouldn't change"); }
public void TestBaseFile() { //setup BaseFileTestClass.WriterToUse = new StringWriter(); NamespaceTestClass packNamespace = new NamespaceTestClass(new DatapackTestClass("pack", "path"), "namespace"); BaseFile file = new BaseFileTestClass(packNamespace, "My/File", BaseFile.WriteSetting.Auto); //test Assert.AreEqual("my/file", file.FileId, "file name is not getting set by constructor"); Assert.AreEqual(packNamespace, file.PackNamespace, "Packnamespace is not getting set by the constructor"); Assert.AreEqual(file, packNamespace.GetFile("filetest", file.FileId), "Constructor is not adding the file to the namespace"); file.Dispose(); file = new BaseFileTestClass(packNamespace, null !, BaseFile.WriteSetting.Auto); Assert.AreEqual("1", file.FileId, "file name wasn't generated correctly"); file.Dispose(); packNamespace.AddSetting(NamespaceSettings.GetSettings().GenerateNames()); file = new BaseFileTestClass(packNamespace, "folder\\ignored-name", BaseFile.WriteSetting.Auto); Assert.AreEqual("2", file.WritePath, "writepath wasn't forced to be generated"); Assert.AreEqual("folder/ignored-name", file.FileId, "filename wasn't kept after forced path generation"); file.Dispose(); }
public void TestCustomGroupCommands() { //setup using Datapack pack = new Datapack("datapacks", "pack", "a pack", 0, new NoneFileCreator()); PackNamespace space = pack.Namespace("space"); Function function = space.Function("function", BaseFile.WriteSetting.OnDispose); BaseCommand command1 = new ExecuteAt(ID.Selector.s); BaseCommand command2 = new SayCommand("123"); BaseCommand command3 = new SayMeCommand("123"); BaseCommand command4 = new ExecuteAs(ID.Selector.s); //test //without execute at start function.Custom.GroupCommands((f) => { f.AddCommand(command1.ShallowClone()); f.AddCommand(command2); f.AddCommand(command3); }); Assert.AreEqual("execute at @s run say 123", function.Commands[0].GetCommandString(), "Get first grouped command string returned wrong string"); Assert.AreEqual("me 123", function.Commands[1].GetCommandString(), "Get second grouped command string returned wrong string"); //with execute at start function.Commands.Clear(); function.AddCommand(command1.ShallowClone()); function.Custom.GroupCommands((f) => { f.AddCommand(command2); f.AddCommand(command4.ShallowClone()); f.AddCommand(command3); }); Assert.AreEqual("execute at @s run say 123", function.Commands[0].GetCommandString(), "Get first executed grouped command string returned wrong string"); Assert.AreEqual("execute at @s as @s run me 123", function.Commands[1].GetCommandString(), "Get second executed grouped command string returned wrong string"); //using function function.Commands.Clear(); function.AddCommand(command1.ShallowClone()); function.Custom.GroupCommands((f) => { f.AddCommand(command2); f.AddCommand(command1.ShallowClone()); f.AddCommand(command3); }, true); Function addedFunction = (((function.Commands[0] as BaseExecuteCommand) !.ExecuteCommand as RunFunctionCommand) !.Function as Function) !; Assert.AreEqual("say 123", addedFunction.Commands[0].GetCommandString(), "Get first function grouped command string returned wrong string"); Assert.AreEqual("execute at @s run me 123", addedFunction.Commands[1].GetCommandString(), "Get second function grouped command string returned wrong string"); Assert.AreEqual(2, addedFunction.Commands.Count, "function grouped command doesn't contain the correct amount of commands"); space.AddSetting(NamespaceSettings.GetSettings().FunctionGroupedCommands()); function.Commands.Clear(); function.AddCommand(command1.ShallowClone()); function.Custom.GroupCommands((f) => { f.AddCommand(command2); f.AddCommand(command1.ShallowClone()); f.AddCommand(command3); }); addedFunction = (((function.Commands[0] as BaseExecuteCommand) !.ExecuteCommand as RunFunctionCommand) !.Function as Function) !; Assert.AreEqual(2, addedFunction.Commands.Count, "automatic function grouped command doesn't get the correct commands"); }