示例#1
0
        public void MakeDataType_LimitedInteger(string tokenValue, string expectedValue, string sign, string bitwidth)
        {
            var dataType = MakeDataType <LimitedIntegerType>(DataType.LimitedInteger, tokenValue);

            dataType.Value.Should().Be(BigInteger.Parse(expectedValue));
            dataType.IsSigned.Should().Be(sign == "i");
            dataType.BitWidth.Should().Be(LimitedIntegerToken.ParseBitWidth(bitwidth));
        }
示例#2
0
        public void MakeLiteralToken_LimitedInteger(string tokenValue, string expectedValue, string sign, string bitwidth)
        {
            var token = MakeToken <LimitedIntegerToken>(LiteralTokenType.LimitedInteger, tokenValue);

            token.TypedValue.Should().Be(BigInteger.Parse(expectedValue));
            token.IsSigned.Should().Be(sign == "i");
            token.BitWidth.Should().Be(LimitedIntegerToken.ParseBitWidth(bitwidth));
        }
示例#3
0
 public void LimitedIntegerIsCreatedWithinRange(string value, string sign, string bitwidth)
 => TestLimitedIntegerRange(BigInteger.Parse(value), new BitWidthAndSignPair(LimitedIntegerToken.ParseBitWidth(bitwidth), sign.ToLower() == "i"));
示例#4
0
        public static ILiteralToken MakeLiteralToken(this string tokenString, IConfiguration configuration = null)
        {
            if (string.IsNullOrWhiteSpace(tokenString))
            {
                return(null);
            }

            var firstSpace = tokenString.IndexOf(' ');
            var tokenType  = firstSpace <= 0
                ? tokenString
                : tokenString.Substring(0, firstSpace).Trim();
            var tokenArg = firstSpace <= 0
                ? ""
                : tokenString.Substring(firstSpace).Trim();

            switch (tokenType.ToLower())
            {
            case "date":
            case "datetoken":
                return(DateToken.Parse(tokenArg, false, SourcePosition.None, configuration));

            case "float":
            case "floattoken":
                return(FloatToken.Parse(tokenArg, configuration));

            case "limitedinteger":
            case "limitedintegertoken":
            {
                var portions = _limitedIntegerRegex.Match(tokenArg);
                var isNeg    = portions.Groups[1].Value == "-";
                var numBase  = IntegerBase.Decimal;
                switch (portions.Groups[2].Value.ToLower())
                {
                case "0x": numBase = IntegerBase.Hexadecimal; break;

                case "b": numBase = IntegerBase.Decimal; break;

                case "o": numBase = IntegerBase.Decimal; break;

                case "": numBase = IntegerBase.Decimal; break;

                default: throw new ArgumentOutOfRangeException($"Unhandled numeric base indicator '{portions.Groups[2].Value}'");
                }
                var num      = portions.Groups[3].Value;
                var isSigned = portions.Groups[4].Value.ToLower() != "u";
                var bitWidth = LimitedIntegerToken.ParseBitWidth(portions.Groups[5].Value);
                return(LimitedIntegerToken.Parse(num, numBase, bitWidth, isSigned, isNeg, tokenArg, SourcePosition.None, configuration ?? new Configuration()
                    {
                        IgnoreLimitedIntegerMaxMinRange = true
                    }));
            }

            case "unlimitedinteger":
            case "unlimitedintegertoken":
            {
                var portions = _unlimitedIntegerRegex.Match(tokenArg);
                var isNeg    = portions.Groups[1].Value == "-";
                var numBase  = IntegerBase.Decimal;
                switch (portions.Groups[2].Value.ToLower())
                {
                case "0x": numBase = IntegerBase.Hexadecimal; break;

                case "b": numBase = IntegerBase.Decimal; break;

                case "o": numBase = IntegerBase.Decimal; break;

                case "": numBase = IntegerBase.Decimal; break;

                default: throw new ArgumentOutOfRangeException($"Unhandled numeric base indicator '{portions.Groups[2].Value}'");
                }
                var num = portions.Groups[3].Value;
                return(UnlimitedIntegerToken.Parse(num, numBase, isNeg, SourcePosition.None, configuration));
            }

            case "timespan":
            case "timespantoken":
                return(TimespanToken.Parse(TimeToken.Parse(tokenArg, SourcePosition.None, configuration).TypedValue, tokenArg, SourcePosition.None, configuration));

            case "time":
            case "timetoken":
                return(TimeToken.Parse(tokenArg, SourcePosition.None, configuration));

            default:
                throw new TestOperationException($"Unrecognised token type {tokenType}");
            }
        }
 public static LimitedIntegerTokenAssertions Should(this LimitedIntegerToken token) => new LimitedIntegerTokenAssertions(token);