// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public bool check_stamp_parsing(ParseResult pr, string expected_remainder, string expected_year, string expected_month, string expected_day) { UT.Assert.IsNotNull(pr); UT.Assert.IsNotNull(pr); UT.Assert.IsNotNull(pr.Stamp); UT.Assert.AreEqual(expected_remainder, pr.Remainder); UT.Assert.AreEqual(expected_year, pr.Stamp.Year); UT.Assert.AreEqual(expected_month, pr.Stamp.Month); UT.Assert.AreEqual(expected_day, pr.Stamp.Day); return true; }
public ParseResult parse(string input_filename) { ParseResult result = new ParseResult(); if (input_filename == null) { throw new NullReferenceException(); } if (input_filename.Length == 0) { result.Remainder = input_filename; result.Stamp = null; return result; } Stamp stamp_struct = new Stamp(); string redigit = "([0-9]|[xX])"; string redash = @"\-"; string releft = @"(([\[|\(])*)"; string reright = @"(([\]|\)])*)"; string reyyyymmdd = (releft) + (redigit + "{4}") + redash + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + (reright); string remmddyyyy = (releft) + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + redash + (redigit + "{4}") + (reright); System.Text.RegularExpressions.Regex regex_pattern; System.Text.RegularExpressions.Match regex_match; System.Text.RegularExpressions.Capture regex_capture = null; regex_pattern = new System.Text.RegularExpressions.Regex(reyyyymmdd); regex_match = regex_pattern.Match(input_filename); if (regex_match.Success) { regex_capture = regex_match.Captures[0]; string[] tokens = this.tokenize(regex_capture.ToString()); stamp_struct.Year=tokens[0]; stamp_struct.Month = tokens[1]; stamp_struct.Day=tokens[2]; stamp_struct.calc(); result.Stamp=stamp_struct; } else { regex_pattern = new System.Text.RegularExpressions.Regex(remmddyyyy); regex_match = regex_pattern.Match(input_filename); if (regex_match.Success) { regex_capture = regex_match.Captures[0]; string[] tokens = this.tokenize(regex_capture.ToString()); stamp_struct.Year = tokens[2]; stamp_struct.Month = tokens[0]; stamp_struct.Day = tokens[1]; stamp_struct.calc(); result.Stamp = stamp_struct; } else { result.Remainder = input_filename; result.Stamp =null; return result; } } if (regex_match == null) { throw new Exception(); } string before = ""; string after = ""; if (regex_capture.Length > 0) { if (regex_capture.Index < 1) { before = ""; after = input_filename.Substring(regex_capture.Index + regex_capture.Length); } else { before = input_filename.Substring(0, regex_capture.Index); after = input_filename.Substring(regex_capture.Index + regex_capture.Length); } } result.Remainder = before + after; return result; }