-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·196 lines (163 loc) · 4.48 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·196 lines (163 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# Build the program first
echo "Building dateline..."
go build -o dateline ./cmd/dateline || exit 1
echo "Running comprehensive date format tests..."
echo "========================================="
# Test data - each line is a test case
test_cases=(
# ISO 8601 formats
"2024-03-15"
"20240315"
"2024-W11"
"2024-W11-5"
"2024-074"
"2024-03-15T14:30:45"
"2024-03-15T14:30:45Z"
"2024-03-15T14:30:45+00:00"
"2024-03-15T14:30:45-05:00"
"2024-03-15T14:30:45.123"
"2024-03-15T14:30:45.123456"
"2024-03-15T14:30:45.123456789"
"20240315T143045"
"20240315T143045Z"
"2024-03-15 14:30:45"
# RFC formats
"Fri, 15 Mar 2024 14:30:45 +0000"
"Fri, 15 Mar 2024 14:30:45 GMT"
"15 Mar 2024 14:30:45 +0000"
"Friday, 15-Mar-24 14:30:45 GMT"
# American formats
"03/15/2024"
"3/15/2024"
"03/15/24"
"3/5/24"
"03-15-2024"
"03.15.2024"
"March 15, 2024"
"Mar 15, 2024"
"March 15th, 2024"
"15 March 2024"
# European formats
"15/03/2024"
"15/3/2024"
"15/03/24"
"15.03.2024"
"15-03-2024"
"15 March 2024"
"15 mars 2024"
"15 marzo 2024"
"15. März 2024"
# Time formats
"Meeting at 2:30 PM"
"Meeting at 14:30"
"Meeting at 14:30:45"
"Meeting at 2:30:45 PM"
# Unix timestamps
"1710510645"
"@1710510645"
"Timestamp: 1710510645123"
# Log formats
"Mar 15 14:30:45"
"[15/Mar/2024:14:30:45 +0000]"
# Relative dates
"today"
"yesterday"
"tomorrow"
"2 days ago"
"in 3 hours"
"last Monday"
"next Friday"
# Complex embedded dates
"The meeting is scheduled for 2024-03-15 at 2:30 PM in room 101"
"File backup_20240315_143045.tar.gz was created"
"Error occurred on Fri, 15 Mar 2024 14:30:45 GMT - please investigate"
"Due date: March 15, 2024 (urgent)"
# Multiple dates
"From 2024-01-01 to 2024-12-31"
"Meeting changed from 03/15/2024 to 03/20/2024"
# Ambiguous formats
"01/02/03"
"10/11/12"
# With ordinals
"1st January 2024"
"March 1st, 2024"
"21st April 2024"
# Asian formats
"2024年3月15日"
"2024년 3월 15일"
# Quarter formats
"Q1 2024"
"2024 Q1"
# Short formats
"Mar 15"
"15 Mar"
"2024-03"
"March 2024"
)
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
success_count=0
fail_count=0
echo ""
echo "Testing individual date parsing:"
echo "---------------------------------"
for test in "${test_cases[@]}"; do
echo -n "Testing: \"$test\" ... "
# Run the test and capture output
result=$(echo "$test" | ./dateline 2>/dev/null | grep -E "Time:|Error:" | head -1)
if [[ $result == *"Time:"* ]]; then
echo -e "${GREEN}✓${NC} Parsed: ${result#*Time: }"
((success_count++))
else
echo -e "${RED}✗${NC} Failed to parse"
((fail_count++))
fi
done
echo ""
echo "========================================="
echo "Testing date removal feature:"
echo "---------------------------------"
removal_tests=(
"Meeting on 2024-03-15 at conference room"
"File created on March 15, 2024 needs review"
"Backup_20240315.tar.gz is ready"
)
for test in "${removal_tests[@]}"; do
echo "Original: \"$test\""
result=$(echo "$test" | ./dateline -remove 2>/dev/null | grep "Without date:" | sed 's/.*Without date: //')
echo "Removed: $result"
echo ""
done
echo "========================================="
echo "Testing multiple date detection:"
echo "---------------------------------"
multi_tests=(
"From 2024-01-01 to 2024-12-31"
"Meeting changed from March 15, 2024 to March 20, 2024"
"Dates: 01/01/2024, 06/30/2024, and 12/31/2024"
)
for test in "${multi_tests[@]}"; do
echo "Input: \"$test\""
count=$(echo "$test" | ./dateline -all 2>/dev/null | grep -c "Time:")
echo "Found $count date(s)"
echo ""
done
echo "========================================="
echo "Testing JSON output:"
echo "---------------------------------"
echo "Testing: \"2024-03-15T14:30:45Z\""
echo "$test" | ./dateline -json 2>/dev/null | head -20
echo ""
echo "========================================="
echo "Summary:"
echo "--------"
echo -e "${GREEN}Successful parses:${NC} $success_count"
echo -e "${RED}Failed parses:${NC} $fail_count"
echo -e "${YELLOW}Total tests:${NC} $((success_count + fail_count))"
echo ""
# Make script executable
chmod +x test.sh