Skip to content

Commit 955d5ff

Browse files
LarsEckartJayBazuziisidore
committed
- F added even more dates that ChatGPT gave us examples for
Co-authored-by: Jay Bazuzi <[email protected]> Co-authored-by: Llewellyn Falco <[email protected]>
1 parent ccf3c9d commit 955d5ff

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.approvaltests.Approvals;
44
import org.approvaltests.core.Options;
55
import org.approvaltests.velocity.VelocityApprovals;
6+
import org.junit.jupiter.api.Disabled;
67
import org.junit.jupiter.api.Test;
78

89
import java.util.List;
@@ -53,4 +54,15 @@ void supportedFormats()
5354
VelocityApprovals.verify(c -> c.put("formats", DateScrubber.getSupportedFormats()),
5455
new Options().forFile().withExtension(".md"));
5556
}
57+
58+
@Disabled("use when new examples are shared at https://github.com/approvals/ApprovalTests.Java/issues/112")
59+
@Test
60+
void textExamples() {
61+
String[] examples = """
62+
05/13/2014 11:50:49 PM
63+
2024-12-18T14:04:46-0500
64+
2025-07-17 14:58:02,123456
65+
""".split("\n");
66+
Approvals.verifyAll("Date scrubbing", examples, this::verifyScrubbing);
67+
}
5668
}

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.supportedFormats.approved.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
| Oct 13 15:29 | [A-Za-z]{3} \d{2} \d{2}:\d{2} |
1010
| May 13, 2014 11:30:00 PM PST | [a-zA-Z]{3} \d{2}, \d{4} \d{2}:\d{2}:\d{2} [a-zA-Z]{2} [a-zA-Z]{3} |
1111
| 23:30:00 | \d{2}:\d{2}:\d{2} |
12-
| 2014/05/13 16:30:59.786 | \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}.\d{2}\d |
12+
| 2014/05/13 16:30:59.786 | \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})? |
1313
| 2020-9-10T08:07Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}Z |
1414
| 2020-09-10T08:07:89Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}Z |
1515
| 2020-09-10T01:23:45.678Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}\:\d{2}\.\d{3}Z |
1616
| 20210505T091112Z | \d{8}T\d{6}Z |
1717
| 2024-12-17 | \d{4}-\d{2}-\d{2} |
1818
| 2024-12-18T14:04:46.746130Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}(\.\d{1,9})?Z |
19+
| 13/05/2014 23:50:49 | \d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))? |

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.testGetDateScrubber.approved.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ Example: {'date':"[Date1]"}
4747

4848

4949
Scrubbing for 2014/05/13 16:30:59.786:
50-
RegExScrubber[\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}.\d{2}\d]
50+
RegExScrubber[\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})?]
51+
Example: {'date':"[Date1]"}
52+
53+
54+
Scrubbing for 2014/05/13 16:30:59:
55+
RegExScrubber[\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})?]
5156
Example: {'date':"[Date1]"}
5257

5358

@@ -106,3 +111,28 @@ RegExScrubber[\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}(\.\d{1,9})?Z]
106111
Example: {'date':"[Date1]"}
107112

108113

114+
Scrubbing for 13/05/2014 23:50:49:
115+
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
116+
Example: {'date':"[Date1]"}
117+
118+
119+
Scrubbing for 13.05.2014 23:50:49:
120+
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
121+
Example: {'date':"[Date1]"}
122+
123+
124+
Scrubbing for 13-05-2014 23:50:49:
125+
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
126+
Example: {'date':"[Date1]"}
127+
128+
129+
Scrubbing for 13.05.2014 23:50:
130+
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
131+
Example: {'date':"[Date1]"}
132+
133+
134+
Scrubbing for 05/13/2014 11:50:49 PM:
135+
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
136+
Example: {'date':"[Date1]"}
137+
138+

approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public DateScrubber(String pattern, Function1<Integer, String> replacement)
1717
}
1818
public static SupportedFormat[] getSupportedFormats()
1919
{
20-
return new SupportedFormat[]{__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2}", "Tue May 13 16:30:00"),
20+
return new SupportedFormat[]{__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2}",
21+
"Tue May 13 16:30:00"),
2122
__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2} [a-zA-Z]{3,4} \\d{4}",
2223
"Wed Nov 17 22:28:33 EET 2021"),
2324
__("(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{2}:\\d{2}:\\d{2} GMT",
@@ -32,8 +33,8 @@ public static SupportedFormat[] getSupportedFormats()
3233
__("[a-zA-Z]{3} \\d{2}, \\d{4} \\d{2}:\\d{2}:\\d{2} [a-zA-Z]{2} [a-zA-Z]{3}",
3334
"May 13, 2014 11:30:00 PM PST"),
3435
__("\\d{2}:\\d{2}:\\d{2}", "23:30:00"),
35-
__("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{2}\\d",
36-
"2014/05/13 16:30:59.786"),
36+
__("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?",
37+
"2014/05/13 16:30:59.786", "2014/05/13 16:30:59"),
3738
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}Z", "2020-9-10T08:07Z",
3839
"2020-09-9T08:07Z", "2020-09-10T8:07Z", "2020-09-10T08:07Z"),
3940
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}Z", "2020-09-10T08:07:89Z"),
@@ -42,7 +43,16 @@ public static SupportedFormat[] getSupportedFormats()
4243
__("\\d{8}T\\d{6}Z", "20210505T091112Z"),
4344
__("\\d{4}-\\d{2}-\\d{2}", "2024-12-17"),
4445
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z",
45-
"2024-12-18T14:04:46.746130Z", "2024-12-18T14:04:46Z", "2024-12-18T14:04:46.746130834Z")};
46+
"2024-12-18T14:04:46.746130Z", "2024-12-18T14:04:46Z",
47+
"2024-12-18T14:04:46.746130834Z"),
48+
__("\\d{2}[-/.]\\d{2}[-/.]\\d{4}\\s\\d{2}:\\d{2}(:\\d{2})?( (?:pm|am|PM|AM))?" ,
49+
"13/05/2014 23:50:49",
50+
"13.05.2014 23:50:49",
51+
"13-05-2014 23:50:49",
52+
"13.05.2014 23:50",
53+
"05/13/2014 11:50:49 PM"
54+
),
55+
};
4656
}
4757
private static SupportedFormat __(String regex, String... examples)
4858
{

0 commit comments

Comments
 (0)