예제 #1
0
        public void TestGetRepeatCount_ExceedsMax()
        {
            var cursor = new PatternCursor("aaa");

            Assert.IsTrue(cursor.MoveNext());
            Assert.Throws <InvalidPatternException>(() => cursor.GetRepeatCount(2));
        }
예제 #2
0
        public void TestGetRepeatCount_Three()
        {
            var cursor = new PatternCursor("aaa");

            Assert.IsTrue(cursor.MoveNext());
            int actual = cursor.GetRepeatCount(10);

            Assert.AreEqual(3, actual);
            ValidateCurrentCharacter(cursor, 2, 'a');
        }
예제 #3
0
        public void GetRepeatCount_Valid(string text, int expectedCount)
        {
            var cursor = new PatternCursor(text);

            Assert.IsTrue(cursor.MoveNext());
            int actual = cursor.GetRepeatCount(10);

            Assert.AreEqual(expectedCount, actual);
            ValidateCurrentCharacter(cursor, expectedCount - 1, 'a');
        }
예제 #4
0
        private static void HandleDayOfMonth(PatternCursor pattern, SteppedPatternBuilder <AnnualDate, AnnualDateParseBucket> builder)
        {
            int           count = pattern.GetRepeatCount(2);
            PatternFields field;

            switch (count)
            {
            case 1:
            case 2:
                field = PatternFields.DayOfMonth;
                // Handle real maximum value in the bucket
                builder.AddParseValueAction(count, 2, pattern.Current, 1, 99, (bucket, value) => bucket.DayOfMonth = value);
                builder.AddFormatLeftPad(count, value => value.Day, assumeNonNegative: true, assumeFitsInCount: count == 2);
                break;

            default:
                throw new InvalidOperationException("Invalid count!");
            }
            builder.AddField(field, pattern.Current);
        }