Follow upstream changes -- Bytestring updates
[git-darcs-import.git] / tests / match-date.sh
blobb61ca531ba54b33bdd1dd4794b6a9e6e1d3d163b
1 #!/usr/bin/env bash
2 set -ev
4 not () { "$@" && exit 1 || :; }
6 rm -rf temp1
7 # Some tests for the '--match' flag, specifically the date-matching
9 reset_repo () {
10 cd ..
11 rm -rf temp1
12 mkdir temp1
13 cd temp1
14 darcs init
15 touch bar
16 darcs add bar
19 create_entry () {
20 echo $1 >> bar
21 echo "$1/tester/a///" | tr / \\012 | darcs record -m "" --pipe bar
24 create_entry_now () {
25 echo today >> bar
26 darcs record -m "" bar -a -A tester
29 # parse_date just checks for parsing, while match_date checks for an actual match.
30 # It's better if we can use "match_date", but we have to be able to construct such a date
31 # based on a date dynamically generated by this test script.
33 # alternately, it might be more useful to build a random date string generator
34 # using QuickCheck... for any n random CalendarTimes, have it generate some
35 # possible variants and roundtrip them to see if they match
37 parse_date () {
38 darcs changes --match "date \"$1\"" > log
39 not grep fancy log
42 match_date () {
43 darcs changes --match "date \"$1\"" > log
44 grep tester log
45 not grep fancy log
48 nomatch_date () {
49 darcs changes --match "date \"$1\"" > log
50 not grep tester log
51 not grep fancy log
54 mkdir temp1
55 cd temp1
56 reset_repo
58 # this block of dates should all refer to the same thing
59 year=1973
60 mm=02
61 dd=04
62 hhmmss="15:08"
63 create_entry "$year-$mm-$dd $hhmmss"
64 echo "/tester/a///" | tr / \\012 | darcs record -m "" --pipe bar
65 match_date "$year-$mm-$dd"
66 match_date "$year$mm$dd"
67 match_date "$year-$mm"
68 match_date "$year$mm"
69 match_date "$year"
71 # week dates. note that 2007 was selected as it starts on Monday
72 reset_repo
73 create_entry "2007-01-04 15:00"
74 match_date '2007-W01-4'
75 nomatch_date '2007-W01-1'
76 match_date '2007W014'
77 match_date '2007-W01'
78 nomatch_date '2007-W02-1'
79 create_entry "2007-01-08 15:00"
80 match_date '2007-W02'
81 match_date '2007-W02-1'
82 create_entry "2007-05-20 15:00"
83 match_date '2007-W20'
84 nomatch_date '2007-W21'
85 nomatch_date '2007-W19'
86 # ordinal dates. eh... why not?
87 match_date '2007-004'; # fourth day of 2007
88 match_date '2007004'
89 nomatch_date '2007-005'
91 # midnight and zero
92 reset_repo
93 create_entry "1992-10-15 00:00"
94 match_date '1992-10-14 24:00'
95 match_date '1992-10-15 00:00'
97 # all the same date/time
98 reset_repo
99 create_entry "1992-02-12T22:32:11"
100 match_date '1992-02-12T22:32:11'
101 match_date '1992-02-12 22:32:11'
102 match_date '1992-02-12T223211.0000'
104 # english dates - the old hard coded from < darcs 1.0.6
105 reset_repo
106 year=`date +%Y`
107 mm=`date +%m`
108 dd=`date +%d`
109 hhmmss=`date +%k:%M:%S`
110 tz=`date +%z`
111 create_entry "$(($year-1))-$mm-$dd"
112 nomatch_date 'today'
113 nomatch_date 'yesterday'
114 nomatch_date 'day before yesterday'
115 nomatch_date 'last week'
116 nomatch_date 'last month'
117 # note: this test might fail if you run it just before midnight
118 reset_repo
119 create_entry_now
120 match_date 'today'
121 nomatch_date 'yesterday'
122 nomatch_date 'day before yesterday'
123 match_date 'last week'
124 match_date 'last month'
126 reset_repo
127 create_entry "$(($year-1))-$mm-$dd"
128 # english dates - new possibilities
129 nomatch_date 'yesterday at 14:00:00'
130 match_date 'last 3 years'
131 match_date 'last year'
132 nomatch_date '2 days ago'
133 nomatch_date 'last month 13:00'
134 nomatch_date '3 days before last week'
135 reset_repo
136 create_entry_now
137 match_date 'day after yesterday'
138 match_date 'week after last week'
139 create_entry "1992-10-02 00:15"
140 match_date '15 minutes after 1992-10-02'
141 reset_repo
142 create_entry "1992-10-02 00:15+05"
143 # note that earlier dates will always match
144 match_date '15 minutes after 1992-10-02 00:00+05'; # same time
145 match_date '15 minutes after 1992-10-01 23:00+04'; # same time
146 nomatch_date '15 minutes after 1992-10-02 01:00+05'; # 1 hour later
147 nomatch_date '15 minutes after 1992-10-02 00:00+04'; # 1 hour later
148 nomatch_date '1 hour, 15 minutes after 1992-10-02 00:00+05'; # 1 hour later
149 match_date '1 hour, 15 minutes after 1992-10-02 00:00+06'; # same time
150 match_date '1 hour, 15 minutes after 1992-10-01 23:00+05'; # same time
152 reset_repo
153 create_entry_now
154 create_entry 1992-10-02 00:15
155 # english intervals
156 nomatch_date 'between last fortnight and day before yesterday'
157 match_date 'between last fortnight and today'
158 match_date 'in the last 45 seconds'
159 match_date 'after 1992'
161 # iso 8601 intervals
162 parse_date '1992-10-02 00:00Z/1992-10-02 00:16Z'
163 match_date '1992-10-02 00:00/1992-10-02 00:16'
164 match_date 'between 1992-10-02 00:00 and 1992-10-12 00:16'
165 parse_date 'P3YT3M/1992'
166 parse_date '1992/P3Y3M4DT5H3M2S'
167 parse_date '1992/P3Y3M'
169 # stuff from the manual
170 reset_repo
171 create_entry_now
172 nomatch_date 'between 2004-03-12 and last week'
173 match_date 'last week'
174 parse_date 'yesterday'
175 parse_date 'today 14:00'
176 nomatch_date '3 days before last year at 17:00'
177 # We can't in general parse the raw date output by darcs. If we change the
178 # format to not include timezone information, this would be possible. But
179 # maybe that's not desireable. For now, we just won't test the raw date.
180 #match_date "$raw_date"
181 parse_date 'after 2005'
182 parse_date 'in the last 3 weeks'
183 parse_date 'P3M/2006-03-17'
184 parse_date '2004-01-02/2006-03-17'
185 parse_date 'P2M6D'
187 # cvs dates
188 parse_date '2006/01/19 21:14:20 UTC'
189 # We can't handle all timezones in the old style dates
190 # so this test will not work everywhere
191 # match_date "$year/$mm/$dd $hhmmss $tz"
193 rm -rf temp1 temp2