public void Parse_TooBigNumber_Null()
        {
            long   num    = 9999999999999;
            string result = _numberParser.Parse(num);

            Assert.IsNull(result);
        }
Beispiel #2
0
        public override void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Text))
            {
                Say("Please provide a valid HRESULT value.");
            }
            else
            {
                NumberParser np      = new NumberParser();
                long         hresult = np.Parse(Text);
                if (np.Error)
                {
                    Say("{0} is not a valid HRESULT value.", Text);
                    return;
                }

                string description = GetHresultDescription(hresult);
                if (description != null)
                {
                    Say("{0} is {1}.",
                        Text,
                        description);
                }
                else
                {
                    Say("I don't know about HRESULT {0}.", Text);
                }
            }
        }
Beispiel #3
0
        public override void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(WMText))
            {
                Say("Please provide a valid window message value or name.");
            }
            else
            {
                NumberParser np = new NumberParser();
                long         wm = np.Parse(WMText);
                string       output;
                if (np.Error)
                {
                    // Assume "!wm <name>" form.
                    output = GetWmNumber(WMText);
                }
                else
                {
                    output = GetWmDescription(wm);
                }

                if (output != null)
                {
                    Say("{0} is {1}.",
                        WMText,
                        output);
                }
                else
                {
                    Say("I don't know about window message {0}.", WMText);
                }
            }
        }
Beispiel #4
0
        public static JSNumberValue ParseNumber(string value)
        {
            Contract.Requires(value != null);
            var parser = new NumberParser(value);

            return(parser.Parse());
        }
Beispiel #5
0
        public override void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Text))
            {
                Say("Please provide a valid NTSTATUS value.");
            }
            else
            {
                NumberParser np       = new NumberParser();
                long         ntstatus = np.Parse(Text);
                if (np.Error)
                {
                    Say("{0} is not a valid NTSTATUS value.", Text);
                    return;
                }

                string description = GetNtstatusDescription(ntstatus);
                if (description != null)
                {
                    Say("{0} is {1}.",
                        Text,
                        description);
                }
                else
                {
                    Say("I don't know about NTSTATUS {0}.", Text);
                }
            }
        }
Beispiel #6
0
        public override void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Text))
            {
                Say("Please provide a valid System Error Code value.");
            }
            else
            {
                NumberParser np       = new NumberParser();
                long         winerror = np.Parse(Text);
                if (np.Error)
                {
                    Say("{0} is not a valid System Error Code value.", Text);
                    return;
                }

                string description = GetWinerrorDescription(winerror);
                if (description != null)
                {
                    Say("{0} is {1}.",
                        Text,
                        description);
                }
                else
                {
                    Say("I don't know about System Error Code {0}.", Text);
                }
            }
        }
Beispiel #7
0
        public void Normalize_ReturnsCorrectValue_EvenWhenThereAreSpacesBesidesSign(string toBeNormalized)
        {
            var numberParser = new NumberParser();
            var numberToken  = numberParser.Parse(toBeNormalized);

            Assert.Equal("n365", numberToken.Normalize());
        }
        public void Parse_GivenNumberToParse_CorrectlyParsed(string toParse, double expectedResult)
        {
            //Arrange
            var parser = new NumberParser();

            //Act
            var result = parser.Parse(toParse);

            //Assert
            result.Should().Be(expectedResult);
        }
        public void Parse_withStringWithNoHashNumber_ShouldReurnEmptyList()
        {
            //setup
            var parser = new NumberParser();
            string input = "This is my comment.";

            //execute
            List<int> actual = parser.Parse(input);

            //asert
            Assert.IsTrue(actual.Count == 0);
        }
        public void Parse_withNullString_ShouldReurnEmptyList()
        {
            //setup
            var parser = new NumberParser();
            string input = null;

            //execute
            List<int> actual = parser.Parse(input);

            //asert
            Assert.IsTrue(actual.Count == 0);
        }
        public void Parse_withStringWithHash3NumberSpace_ShouldReurnNumberInList()
        {
            //setup
            var parser = new NumberParser();
            List<int> expected = new List<int>() { 453 };
            string input = "Work on item #453 and updated version number.";

            //execute
            List<int> actual = parser.Parse(input);

            //asert
            CollectionAssert.AreEquivalent(expected, actual);
        }
Beispiel #12
0
        public void UpperCaseIsParsed(string input, int expected)
        {
            // Arrange

            var parser = new NumberParser();

            // Act

            var result = parser.Parse(input);

            // Assert

            Assert.That(result, Is.EqualTo(expected));
        }
Beispiel #13
0
        private Expr Primary()
        {
            if (Match(FALSE))
            {
                return(new Expr.Literal(false));
            }
            if (Match(TRUE))
            {
                return(new Expr.Literal(true));
            }
            if (Match(NULL))
            {
                return(new Expr.Literal(null));
            }

            if (Match(NUMBER))
            {
                // Numbers are retained as strings in the scanning phase, to properly be able to parse negative numbers
                // in the parsing stage (where we can more easily join the MINUS and NUMBER token together). See #302
                // for details.
                INumericLiteral numericLiteral = NumberParser.Parse((NumericToken)Previous());
                return(new Expr.Literal(numericLiteral));
            }

            if (Match(STRING))
            {
                return(new Expr.Literal(Previous().Literal));
            }

            if (Match(IDENTIFIER))
            {
                return(new Expr.Identifier(Previous()));
            }

            if (Match(LEFT_PAREN))
            {
                Expr expr = Expression();
                Consume(RIGHT_PAREN, "Expect ')' after expression.");
                return(new Expr.Grouping(expr));
            }

            if (Check(SEMICOLON))
            {
                // Bare semicolon, no expression inside. To avoid having to handle pesky null exceptions all over
                // the code base, we have a dedicated expression for this.
                return(new Expr.Empty());
            }

            throw Error(Peek(), "Expect expression.");
        }
Beispiel #14
0
        public void ReturnsTrue_WhenOnlyThousandSeparatorsAreRecognized()
        {
            // arrange
            var separators = new List <NumberSeparator>
            {
                new NumberSeparator {
                    Type = NumberSeparator.SeparatorType.GroupSeparator, Value = "."
                }
            };
            var numberParser = new NumberParser(separators);

            // act
            var value = numberParser.Parse("3.021.343.432");

            // assert
            Assert.True(value.Valid && value.HasGroupSeparator && !value.HasDecimalSeparator);
        }
Beispiel #15
0
        public void ReturnsTrue_WhenGroupValueIsOutOfRange()
        {
            // arrange
            var separators = new List <NumberSeparator>
            {
                new NumberSeparator {
                    Type = NumberSeparator.SeparatorType.GroupSeparator, Value = ","
                }
            };

            var numberParser = new NumberParser(separators);

            // act
            var value = numberParser.Parse("234,34");

            // assert
            Assert.False(value.Valid);
        }
Beispiel #16
0
        private static IEnumerable <NumberToken> GetNumbersTokens(string text, IEnumerable <string> decimalSeparators, IEnumerable <string> groupSeparators)
        {
            var numberTokens = new List <NumberToken>();

            var numberSeparators = GetNumberSeparators(
                NormalizeStrings(decimalSeparators),
                NormalizeStrings(groupSeparators));
            var numberParser = new NumberParser(numberSeparators.Count > 0 ? numberSeparators : null);

            var regexNumber   = new Regex(@"[\+\-]?\s*[0-9\.\,]*[Ee]?[\+\-]?\d+", RegexOptions.Singleline);
            var numberMatches = regexNumber.Matches(text);

            foreach (Match numberMatch in numberMatches)
            {
                var numberToken = numberParser.Parse(numberMatch.Value);
                numberTokens.Add(numberToken);
            }

            return(numberTokens);
        }
Beispiel #17
0
        private int ParseNumber(Group numerator)
        {
            var isParsed = int.TryParse(numerator.Value, out int num);

            if (!isParsed)
            {
                var er = new ExtractResult
                {
                    Start  = numerator.Index,
                    Length = numerator.Length,
                    Text   = numerator.Value,
                    Type   = "Integer",
                    Data   = null,
                };
                var pr = NumberParser.Parse(er);
                int.TryParse(pr.ResolutionStr, out num);
            }

            return(num);
        }
Beispiel #18
0
        public void ReturnsTrue_WhenCustomMultiCharSeparatorIsRecognized()
        {
            // arrange
            var separators = new List <NumberSeparator>
            {
                new NumberSeparator {
                    Type = NumberSeparator.SeparatorType.DecimalSeparator, Value = "MySeparator"
                },
                new NumberSeparator {
                    Type = NumberSeparator.SeparatorType.GroupSeparator, Value = "--"
                }
            };

            var numberParser = new NumberParser(separators);

            // act
            var value = numberParser.Parse("343--456MySeparator3");

            // assert
            Assert.True(value.Valid);
        }
Beispiel #19
0
        public void ReturnsNull_WhenInputIsNull()
        {
            // arrange
            // act
            var value = _numberParser.Parse(null);

            // assert
            Assert.Null(value);
        }
Beispiel #20
0
        public override void  ExecuteCommand()
        {
            if (Parameters.Equals(String.Empty))
            {
                Say("Please provide an Error Code.");
                return;
            }

            string errorText = Parameters;

retry:
            NumberParser np = new NumberParser();
            long error = np.Parse(errorText);

            if (Parameters.ToLower().Contains("deadbeef"))
            {
                Say("Unimplemented. You haven't seen enough Wine code.");
                return;
            }
            if (error == 3735928559)
            {
                Say("Unimplemented. Most likely a Wine stub is in your way."); return;
            }

            if (Parameters.ToLower().Contains("neo"))
            {
                Say("Never heard of him."); return;
            }

            if (np.Error)
            {
                Say("{0} is not a valid Error Code.", Parameters);
                return;
            }

            ArrayList descriptions = new ArrayList();

            // Error is out of bounds
            if ((ulong)error > uint.MaxValue)
            {
                // Do nothing
            }
            // Error is outside of the range [0, 65535]: it cannot be a plain Win32 error code
            else if ((ulong)error > ushort.MaxValue)
            {
                // Customer bit is set: custom error code
                if (IsCustomer(error))
                {
                    string description = String.Format("[custom, severity {0}, facility {1}, code {2}]",
                                                       FormatSeverity(error),
                                                       FormatFacility(error),
                                                       FormatCode(error));
                    descriptions.Add(description);
                }
                // Reserved bit is set: HRESULT_FROM_NT(ntstatus)
                else if (IsReserved(error))
                {
                    int    status      = (int)(error & 0xCFFFFFFF);
                    string description = ntStatus.GetNtstatusDescription(status);

                    if (description == null)
                    {
                        description = status.ToString("X");
                    }

                    description = String.Format("HRESULT_FROM_NT({0})", description);
                    descriptions.Add(description);
                }
                // Win32 facility: HRESULT_FROM_WIN32(winerror)
                else if (GetFacility(error) == 7)
                {
                    // Must be an error code
                    if (GetSeverity(error) == 2)
                    {
                        short  err         = GetCode(error);
                        string description = winerror.GetWinerrorDescription(err);

                        if (description == null)
                        {
                            description = err.ToString("D");
                        }

                        description = String.Format("HRESULT_FROM_WIN32({0})", description);
                        descriptions.Add(description);
                    }
                }
            }

            string winerrorDescription = winerror.GetWinerrorDescription(error);
            string ntstatusDescription = ntStatus.GetNtstatusDescription(error);
            string hresultDescription  = hresult.GetHresultDescription(error);

            if (winerrorDescription != null)
            {
                descriptions.Add(winerrorDescription);
            }
            if (ntstatusDescription != null)
            {
                descriptions.Add(ntstatusDescription);
            }
            if (hresultDescription != null)
            {
                descriptions.Add(hresultDescription);
            }

            if (descriptions.Count == 0)
            {
                // Last chance heuristics: attempt to parse a 8-digit decimal as hexadecimal
                if (errorText.Length == 8)
                {
                    errorText = "0x" + errorText;
                    goto retry;
                }

                Say("I don't know about Error Code {0}.",
                    Parameters);
            }
            else if (descriptions.Count == 1)
            {
                string description = (string)descriptions[0];
                Say("{0} is {1}.",
                    Parameters,
                    description.Trim());
            }
            else
            {
                Say("{0} could be:", Parameters);

                foreach (string description in descriptions)
                {
                    Say("\t{0}", description.Trim());
                }
            }
        }
 private List<int> ConvertToNumbers(IEnumerable<string> tokens)
 {
     NumberParser parser = new NumberParser();
     return parser.Parse(tokens);
 }
        public void Parse_withStringWithMultipleHashNumbers_ShouldReurnNumbersInList()
        {
            //setup
            var parser = new NumberParser();
            List<int> expected = new List<int>() { 12, 453 };
            string input = "Work on item #453 and #12.";

            //execute
            List<int> actual = parser.Parse(input);

            //asert
            CollectionAssert.AreEquivalent(expected, actual);
        }
Beispiel #23
0
        public void Parse_ReturnsNumberAsString()
        {
            var numberParser = new NumberParser();

            Assert.AreEqual("10", numberParser.Parse(10));
        }
Beispiel #24
0
        public void ReturnsFalse_WhenFoundMixedThousandSeparators()
        {
            // arrange
            // act
            var value = _numberParser.Parse("3,021.343.43");

            // assert
            Assert.False(value.Valid);
        }