/// <summary> /// Parse a year match expression. /// <example> /// Valid expression are: /// * => Every year /// 2020 => Exactly that year /// ..2030 => Every year until 2030 comprised /// 2020.. => Every year starting from 2020 /// 2020..2030 => Every year between 2020 and 2030 /// */Leap => Every leap year /// 2020..2030/Leap => Every leap year between 2020 and 2030 /// */NotLeap => Every non leap year /// 2020..2030/2 => Starting from 2020 every 2 years until 2030 /// 2020../2 => Starting from 2020 every 2 years /// 2020../NotLeap => Starting from 2020 every NonLeap year /// 2020..2030%2 => Every year which reminder modulo 2 is zero between 2020 and 2030 /// 2020..%3 => Starting from 2020 every year which reminder modulo 3 is zero /// </example> /// </summary> public override bool TryParse(string value, out IYearMatcher yearMatcher) { if (RangeYearMatcher.TryParse(value, out var rangeYearMatcher)) { yearMatcher = rangeYearMatcher; return(true); } if (PeriodicYearMatcher.TryParse(value, out var periodYearMatcher)) { yearMatcher = periodYearMatcher; return(true); } if (ModuloYearMatcher.TryParse(value, out var moduloYearMatcher)) { yearMatcher = moduloYearMatcher; return(true); } if (LeapYearMatcher.TryParse(value, out var leapYearMatcher)) { yearMatcher = leapYearMatcher; return(true); } if (NotLeapYearMatcher.TryParse(value, out var notLeapYearMatcher)) { yearMatcher = notLeapYearMatcher; return(true); } yearMatcher = default; return(false); }
public void TryParseTests() { // Testing object factory (valid) Assert.IsTrue(LeapYearMatcher.TryParse("*/Leap", out var lym)); Assert.IsNotNull(lym); Assert.IsNull(lym.Left); Assert.IsNull(lym.Right); Assert.IsTrue(LeapYearMatcher.TryParse("1..100/Leap", out lym)); Assert.IsNotNull(lym); Assert.AreEqual(1, lym.Left); Assert.AreEqual(100, lym.Right); // Testing object factory (invalid) Assert.IsFalse(LeapYearMatcher.TryParse("/Leap", out lym)); Assert.IsNull(lym); Assert.IsFalse(LeapYearMatcher.TryParse("12/Leap", out lym)); Assert.IsNull(lym); Assert.IsFalse(LeapYearMatcher.TryParse("12..12/Leap", out lym)); Assert.IsNull(lym); }