Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

PRX-64: Fix `~Hash.CreateFromArgs`

Fixes PRX-64.

Christian Klauser (Apr 4, 2022, 6:49 PM +0200) 6e0fc51b 36843e12

+83 -4
+2 -4
Prexonite/Types/HashPType.cs
··· 323 323 result = new PValue(pvht, this); 324 324 break; 325 325 326 - case "createFromArgs": 327 - if (args.Length%2 != 0) 328 - break; 326 + case "createfromargs": 329 327 pvht = new PValueHashtable(args.Length/2); 330 - for (var i = 0; i < args.Length; i += 2) 328 + for (var i = 0; i + 1 < args.Length; i += 2) 331 329 pvht.AddOverride(args[i], args[i + 1]); 332 330 result = new PValue(pvht, this); 333 331 break;
+81
PrexoniteTests/Tests/BuiltInTypesTest.cs
··· 1 + // Prexonite 2 + // 3 + // Copyright (c) 2014, Christian Klauser 4 + // All rights reserved. 5 + // 6 + // Redistribution and use in source and binary forms, with or without modification, 7 + // are permitted provided that the following conditions are met: 8 + // 9 + // Redistributions of source code must retain the above copyright notice, 10 + // this list of conditions and the following disclaimer. 11 + // Redistributions in binary form must reproduce the above copyright notice, 12 + // this list of conditions and the following disclaimer in the 13 + // documentation and/or other materials provided with the distribution. 14 + // The names of the contributors may be used to endorse or 15 + // promote products derived from this software without specific prior written permission. 16 + // 17 + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 + // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 + // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 + // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 + // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 + // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 + // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 + 27 + using System.Collections.Generic; 28 + using System.IO; 29 + using System.Linq; 30 + using JetBrains.Annotations; 31 + using Moq; 32 + using NUnit.Framework; 33 + using Prexonite; 34 + using Prexonite.Commands; 35 + using Prexonite.Compiler; 36 + using Prexonite.Compiler.Ast; 37 + using Prexonite.Compiler.Build; 38 + using Prexonite.Compiler.Symbolic; 39 + using Prexonite.Modular; 40 + using Prexonite.Types; 41 + 42 + namespace PrexoniteTests.Tests; 43 + 44 + public class BuiltInTypeTests : VMTestsBase 45 + { 46 + [Test] 47 + public void HashStaticMethodCreate() 48 + { 49 + Compile(@" 50 + function main(x,y) { 51 + var h = ~Hash.Create(""x"": x, ""y"": y); 52 + return ""x=$(h[""x""]), y=$(h[""y""]), c=$(h.Count)""; 53 + } 54 + "); 55 + Expect("x=5, y=7, c=2", 5, 7); 56 + } 57 + 58 + [Test] 59 + public void HashStaticMethodCreateFromArgs() 60 + { 61 + Compile(@" 62 + function main(x,y) { 63 + var h = ~Hash.CreateFromArgs(""x"", x, ""y"", y); 64 + return ""x=$(h[""x""]), y=$(h[""y""]), c=$(h.Count)""; 65 + } 66 + "); 67 + Expect("x=3, y=8, c=2", 3, 8); 68 + } 69 + 70 + [Test] 71 + public void HashStaticMethodCreateFromArgsIgnoresExcessArg() 72 + { 73 + Compile(@" 74 + function main(x,y) { 75 + var h = ~Hash.CreateFromArgs(""x"", x, ""y"", y, ""z""); 76 + return ""x=$(h[""x""]), y=$(h[""y""]), c=$(h.Count)""; 77 + } 78 + "); 79 + Expect("x=6, y=9, c=2", 6,9); 80 + } 81 + }