Exemplo n.º 1
0
        private AType ConvertNumberToChar(AType argument)
        {
            AType result = AArray.Create(ATypes.AChar);

            if (argument.IsArray)
            {
                foreach (AType item in argument)
                {
                    AType convertedItem = ConvertNumberToChar(item);

                    if (item.IsArray)
                    {
                        result.Add(convertedItem);
                    }
                    else
                    {
                        result.AddRange(convertedItem);
                    }
                }
            }
            else
            {
                byte[] bytes = (argument.Type == ATypes.AFloat)
                    ? BitConverter.GetBytes(argument.asFloat)
                    : BitConverter.GetBytes(argument.asInteger);

                result.AddRange(bytes.Select <byte, AType>(item => AChar.Create((char)item)));
            }

            return(result);
        }
Exemplo n.º 2
0
        public void UnpackSymbolConstantMatrix()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AArray.Create(
                    ATypes.AChar,
                    AArray.Create(ATypes.AChar, AChar.Create('a'), AChar.Create(' '), AChar.Create(' '), AChar.Create(' ')),
                    AArray.Create(ATypes.AChar, AChar.Create('a'), AChar.Create('b'), AChar.Create('c'), AChar.Create('d')),
                    AArray.Create(ATypes.AChar, AChar.Create('t'), AChar.Create(' '), AChar.Create(' '), AChar.Create(' '))
                    ),
                AArray.Create(
                    ATypes.AChar,
                    AArray.Create(ATypes.AChar, AChar.Create('d'), AChar.Create('f'), AChar.Create('g'), AChar.Create(' ')),
                    AArray.Create(ATypes.AChar, AChar.Create('a'), AChar.Create(' '), AChar.Create(' '), AChar.Create(' ')),
                    AArray.Create(ATypes.AChar, AChar.Create('a'), AChar.Create('b'), AChar.Create('c'), AChar.Create('d'))
                    ),
                AArray.Create(
                    ATypes.AChar,
                    AArray.Create(ATypes.AChar, AChar.Create('t'), AChar.Create(' '), AChar.Create(' '), AChar.Create(' ')),
                    AArray.Create(ATypes.AChar, AChar.Create('d'), AChar.Create('f'), AChar.Create('g'), AChar.Create(' ')),
                    AArray.Create(ATypes.AChar, AChar.Create('a'), AChar.Create(' '), AChar.Create(' '), AChar.Create(' '))
                    )
                );

            AType result = this.engine.Execute <AType>("unpack 3 3 rho `a `abcd `t `dfg");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tester method which returns different typed results.
        /// </summary>
        /// <param name="env"><see cref="Aplus"/> environemnt.</param>
        /// <param name="number">Input number.</param>
        /// <remarks>
        /// The resulting type of the value is determined by the input number's value.
        /// If the value is:
        /// <list type="bullet">
        ///  <item><description>0: returns 1.1 as a AFloat.</description></item>
        ///  <item><description>1: returns 0 as a AInteger.</description></item>
        ///  <item><description>2: returns `a as a ASymbol.</description></item>
        ///  <item><description>3: returns 'a' as a AFChar.</description></item>
        ///  <item><description>otherwise: returns empty array.</description></item>
        /// </list>
        /// </remarks>
        /// <returns>Different typed ATypes.</returns>
        public static AType MonadicTypeAlternate(Aplus env, AType number)
        {
            AType result;

            switch (number.asInteger)
            {
            case 0:
                result = AFloat.Create(1.1);
                break;

            case 1:
                result = AInteger.Create(0);
                break;

            case 2:
                result = ASymbol.Create("a");
                break;

            case 3:
                result = AChar.Create('a');
                break;

            default:
                result = Utils.ANull();
                break;
            }

            return(result);
        }
Exemplo n.º 4
0
        public void EqualToTest()
        {
            AssertPasses('x', AChar.EqualTo('x'));
            AssertPasses(null, AChar.EqualTo(null));

            AssertFails('x', AChar.EqualTo('y'));
            AssertFails(null, AChar.NotEqualTo(null));
        }
Exemplo n.º 5
0
        public void ChooseRestrictedWholeNumber2CharaterConstantList()
        {
            AType expected = AChar.Create('t');

            AType result = this.engine.Execute <AType>("3.000000000000006 # 'test'");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 6
0
        public void RotatePositiveInteger2Char()
        {
            AType expected = AChar.Create('a');

            AType result = this.engine.Execute <AType>("3 rot 'a'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 7
0
        public void PickStrand2NestedStrand()
        {
            AType expected = AChar.Create('d');

            AType result = this.engine.Execute <AType>("(1;0;0 1) pick ('ab';(2 2 rho('c';'d';'e';'f');10 20))");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 8
0
        public void PickInteger2SimpleCharacter()
        {
            AType expected = AChar.Create('a');

            AType result = this.engine.Execute <AType>("(1 1 rho 0) pick 'a'");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 9
0
        public void PickNestedElement2NestedCharacterMatrix()
        {
            AType expected = AChar.Create('b');

            AType result = this.engine.Execute <AType>("(< 0 1) pick 2 2 rho ('a';'b';'c';'d')");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 10
0
        public void PickOneElementMatrix2SimpleSymbolConstantVector()
        {
            AType expected = AChar.Create('t');

            AType result = this.engine.Execute <AType>("(1 1 rho 3) pick 'test'");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 11
0
        public void ExpandOne2CharacterConstant()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('a')
                );
            AType result = this.engine.Execute <AType>("1 \\ 'a'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Convert string argument to AType character array.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        private static AType[] ConvertToCharArray(string argument)
        {
            AType[] result = new AType[argument.Length];

            for (int i = 0; i < argument.Length; i++)
            {
                result[i] = AChar.Create(argument[i]);
            }

            return(result);
        }
Exemplo n.º 13
0
        public void DropNull2CharacterConstant2()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('a')
                );
            AType result = this.engine.Execute <AType>("(iota 1) drop 'a'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 14
0
        public void StringCycleReshape()
        {
            AType expected = AArray.Create(ATypes.AChar,
                                           AArray.Create(ATypes.AChar, AChar.Create('h'), AChar.Create('e'), AChar.Create('l')),
                                           AArray.Create(ATypes.AChar, AChar.Create('l'), AChar.Create('o'), AChar.Create('h')),
                                           AArray.Create(ATypes.AChar, AChar.Create('e'), AChar.Create('l'), AChar.Create('l'))
                                           );

            AType result = this.engine.Execute <AType>(" 3 3 rho 'hello'");

            Assert.AreEqual <AType>(expected, result, "Incorrect integer matrix generated");
        }
Exemplo n.º 15
0
        public void UnpackSymbolConstant1()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('a')
                );

            AType result = this.engine.Execute <AType>("unpack `a");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 16
0
        public void MultiPickPathNumber2NestedVector()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AArray.Create(ATypes.AChar, AChar.Create('c'), AChar.Create('d')),
                AArray.Create(ATypes.AChar, AChar.Create('e'), AChar.Create('f'))
                );

            AType result = this.engine.Execute <AType>("0 pick 1 pick ('ab';(2 2 rho 'cdef'; 10 20))");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 17
0
        public void UnpackSymbolConstantVector1Uni()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AArray.Create(ATypes.AChar, AChar.Create('a'), AChar.Create('b'), AChar.Create(' ')),
                AArray.Create(ATypes.AChar, AChar.Create('e'), AChar.Create(' '), AChar.Create(' ')),
                AArray.Create(ATypes.AChar, AChar.Create('g'), AChar.Create('f'), AChar.Create('h'))
                );

            AType result = this.engineUni.Execute <AType>("M.> `ab `e `gfh");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 18
0
        public static AType Export(Aplus environment, AType argument)
        {
            byte[] exportedMessage = SysExp.Instance.Format(argument);
            AType  result          = AArray.Create(ATypes.AChar);

            foreach (byte charcter in exportedMessage)
            {
                result.AddWithNoUpdate(AChar.Create((char)charcter));
            }

            result.UpdateInfo();

            return(result);
        }
Exemplo n.º 19
0
        public void TakeInteger2CharacterConstant()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('a'),
                AChar.Create('b'),
                AChar.Create(' '),
                AChar.Create(' ')
                );
            AType result = this.engine.Execute <AType>("4 take 'ab'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 20
0
        public void ReverseCharacterConstant()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('t'),
                AChar.Create('s'),
                AChar.Create('e'),
                AChar.Create('t')
                );
            AType result = this.engine.Execute <AType>("rot 'test'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 21
0
        public void ReplaceAllMappedCharacter()
        {
            AType expected = AChar.Create('B');

            ScriptScope scope = this.engine.CreateScope();
            string executable = string.Format("a := 1 beam `{0}", MappedFiles.CharScalar.GetFileName());

            this.engine.Execute<AType>(executable, scope);
            this.engine.Execute<AType>("a[] := 'B'", scope);

            AType result = this.engine.Execute<AType>("1 beam `CharScalar", scope);

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 22
0
        public void PickIntegerNestedVector2()
        {
            AType expected = Helpers.BuildStrand(
                new AType[] {
                AArray.Create(ATypes.AInteger, AInteger.Create(10), AInteger.Create(20)),
                AArray.Create(
                    ATypes.AChar,
                    AArray.Create(ATypes.AChar, AChar.Create('c'), AChar.Create('d')),
                    AArray.Create(ATypes.AChar, AChar.Create('e'), AChar.Create('f')))
            });

            AType result = this.engine.Execute <AType>("1 pick ('ab';(2 2 rho 'cdef'; 10 20))");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Creates an AArray from the input string with AChar type or
        /// a simple AChar if the input is of length 1
        /// </summary>
        /// <param name="text">input string</param>
        /// <returns>AArray of AChars or a single AChar</returns>
        public static AType BuildString(string text)
        {
            if (text.Length == 1)
            {
                return(AChar.Create(text[0]));
            }

            AType characterArray = AArray.Create(ATypes.AChar);

            foreach (char ch in text)
            {
                characterArray.Add(AChar.Create(ch));
            }
            characterArray.UpdateInfo();

            return(characterArray);
        }
Exemplo n.º 24
0
        internal static AType Loadfile(Aplus environment, AType filename)
        {
            string fileName = filename.ToString();

            if (filename.Type != ATypes.AChar)
            {
                throw new Error.Type("_loadfile");
            }

            if (!File.Exists(fileName))
            {
                throw new Error.Invalid("_loadfile");
            }

            AType result = AArray.Create(ATypes.AChar);

            using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
            {
                int    blockReadSize      = 5 * 1024; // 5 KiB
                long   totalSize          = fileStream.Length;
                int    readLength         = blockReadSize < totalSize ? blockReadSize : (int)totalSize;
                byte[] filePartialContent = new byte[readLength];

                int sum = 0; // total number of bytes read
                int count;   // current number of bytes read

                // read until Read method returns 0 (end of the stream has been reached)
                while ((count = fileStream.Read(filePartialContent, 0, readLength)) > 0)
                {
                    sum += count;  // sum is a buffer offset for next reading

                    // build the array from the bytes that was read
                    for (int i = 0; i < count; i++)
                    {
                        result.Add(AChar.Create((char)filePartialContent[i]));
                    }

                    // calculate the next size of the read block
                    long leftover = totalSize - sum;
                    readLength = blockReadSize < leftover ? blockReadSize : (int)leftover;
                }

                return(result);
            }
        }
Exemplo n.º 25
0
        protected override AType ConvertToAObject(byte[] message)
        {
            AType result = Utils.ANull();

            for (int i = 0; i < message.Length; i++)
            {
                try
                {
                    result.Add(AChar.Create((char)message[i]));
                }
                catch (InvalidCastException)
                {
                    throw new ADAPException(ADAPExceptionType.Import);
                }
            }

            return(result);
        }
Exemplo n.º 26
0
        protected override AType ConvertToAObject(byte[] messageByte)
        {
            AType message = AArray.Create(ATypes.AChar);

            foreach (byte b in messageByte)
            {
                try
                {
                    message.Add(AChar.Create((char)b));
                }
                catch (InvalidCastException)
                {
                    throw new ADAPException(ADAPExceptionType.Import);
                }
            }

            return message;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Adds a hotkey trigger.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="modKeys">
        /// Modifier keys, like with the <see cref="AKeys.Key"/> function.
        /// Examples: "Ctrl", "Ctrl+Shift+Alt+Win".
        /// To ignore modifiers: "?". Then the trigger works with any combination of modifiers.
        /// To ignore a modifier: "Ctrl?". Then the trigger works with or without the modifier. More examples: "Ctrl?+Shift?", "Ctrl+Shift?".
        /// </param>
        /// <param name="flags"></param>
        /// <exception cref="ArgumentException">Invalid modKeys string or flags.</exception>
        /// <exception cref="InvalidOperationException">Cannot add triggers after <c>Triggers.Run</c> was called, until it returns.</exception>
        public Action <HotkeyTriggerArgs> this[KKey key, string modKeys, TKFlags flags = 0] {
            set {
                var ps = key.ToString(); if (AChar.IsAsciiDigit(ps[0]))
                {
                    ps = "VK" + ps;
                }
                if (!modKeys.NE())
                {
                    ps = modKeys + "+" + ps;
                }

                if (!AKeys.More.ParseHotkeyTriggerString_(modKeys, out var mod, out var modAny, out _, true))
                {
                    throw new ArgumentException("Invalid modKeys string.");
                }
                _Add(value, key, mod, modAny, flags, ps);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Convert Symbol to Character constant vector.
        /// </summary>
        /// <param name="symbol"></param>
        /// <returns></returns>
        private AType Convert(AType symbol, int lastDimension)
        {
            string item   = symbol.asString;
            AType  result = AArray.Create(ATypes.AChar);

            for (int i = 0; i < lastDimension; i++)
            {
                result.AddWithNoUpdate(AChar.Create(i >= item.Length ? ' ' : item[i]));
            }

            result.Length = lastDimension;
            result.Shape  = new List <int>()
            {
                lastDimension
            };
            result.Rank = 1;

            return(result);
        }
Exemplo n.º 29
0
        public void RavelCharacterMatrix()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('c'),
                AChar.Create('a'),
                AChar.Create('t'),
                AChar.Create('h'),
                AChar.Create('a'),
                AChar.Create('t'),
                AChar.Create('b'),
                AChar.Create('a'),
                AChar.Create('t')
                );
            AType result = this.engine.Execute <AType>(", 3 3 rho 'cathatbat'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
Exemplo n.º 30
0
        void _Insert(string s)
        {
            var sci  = InsertInControl;
            var pos8 = sci.Z.CurrentPos8;

            switch (s)
            {
            case "text": _AddParameter(sci, pos8, ", (KText)\"%\""); return;

            case "sleepMs": _AddParameter(sci, pos8, ", 100"); return;

            case "keyCode": _AddParameter(sci, pos8, ", KKey.Left"); return;

            case "scanCode": _AddParameter(sci, pos8, ", (1, false)"); return;

            case "action": _AddParameter(sci, pos8, ", new Action(() => { AMouse.RightClick(); })"); return;
            }

            if (s.Length == 2 && s[0] != '#' && !AChar.IsAsciiAlpha(s[0]))
            {
                s = s[0] == '\\' ? "|" : s[..1];                                                                       //eg 2@ or /? or \|