| 1 |
package regexp2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/ |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 5 |
"testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 6 |
"timescip-go gomod github.com/golang/go/src go1.13 time/" |
| 7 |
) |
| 8 |
|
| 9 |
func initscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/init().() { |
| 10 |
//speed up testing by making the timeout clock 1ms instead of 100ms... |
| 11 |
//bad for benchmark tests though |
| •12 |
// Debian: Prevent failure on busy/slower machines by setting to 10ms instead |
| 13 |
SetTimeoutCheckPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/SetTimeoutCheckPeriod().(timescip-go gomod github.com/golang/go/src go1.13 time/.Millisecondscip-go gomod github.com/golang/go/src go1.13 time/Millisecond. * 10) |
| 14 |
} |
| 15 |
func TestDeadlinescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestDeadline().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 16 |
for _, delay := range []timescip-go gomod github.com/golang/go/src go1.13 time/.Durationscip-go gomod github.com/golang/go/src go1.13 time/Duration#{ |
| 17 |
clockPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/clockPeriod. / 10, |
| 18 |
clockPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/clockPeriod., |
| 19 |
clockPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/clockPeriod. * 5, |
| 20 |
clockPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/clockPeriod. * 10, |
| 21 |
} { |
| 22 |
delay := delay // Make copy for parallel sub-test. |
| 23 |
t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.13 fmt/Sprint().(delay), func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 24 |
t.Parallelscip-go gomod github.com/golang/go/src go1.13 testing/T#Parallel().() |
| 25 |
start := timescip-go gomod github.com/golang/go/src go1.13 time/.Nowscip-go gomod github.com/golang/go/src go1.13 time/Now().() |
| 26 |
d := makeDeadlinescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/makeDeadline().(delay) |
| 27 |
if d.reachedscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/fasttime#reached().() { |
| 28 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("deadline (%v) unexpectedly expired immediately", delay) |
| 29 |
} |
| 30 |
timescip-go gomod github.com/golang/go/src go1.13 time/.Sleepscip-go gomod github.com/golang/go/src go1.13 time/Sleep().(delay / 2) |
| 31 |
if d.reachedscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/fasttime#reached().() { |
| 32 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("deadline (%v) expired too soon (after %v)", delay, timescip-go gomod github.com/golang/go/src go1.13 time/.Sincescip-go gomod github.com/golang/go/src go1.13 time/Since().(start)) |
| 33 |
} |
| 34 |
timescip-go gomod github.com/golang/go/src go1.13 time/.Sleepscip-go gomod github.com/golang/go/src go1.13 time/Sleep().(delay/2 + 2*clockPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/clockPeriod.) // Give clock time to tick |
| 35 |
if !d.reachedscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/fasttime#reached().() { |
| 36 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("deadline (%v) did not expire within %v", delay, timescip-go gomod github.com/golang/go/src go1.13 time/.Sincescip-go gomod github.com/golang/go/src go1.13 time/Since().(start)) |
| 37 |
} |
| 38 |
}) |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
func TestStopTimeoutClockscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestStopTimeoutClock().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 43 |
// run a quick regex with a long timeout |
| 44 |
// make sure the stop clock returns quickly |
| 45 |
r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(".", 0) |
| 46 |
r.MatchTimeoutscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchTimeout. = timescip-go gomod github.com/golang/go/src go1.13 time/.Secondscip-go gomod github.com/golang/go/src go1.13 time/Second. * 10 |
| 47 |
|
| 48 |
r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("a") |
| 49 |
start := timescip-go gomod github.com/golang/go/src go1.13 time/.Nowscip-go gomod github.com/golang/go/src go1.13 time/Now().() |
| 50 |
StopTimeoutClockscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/StopTimeoutClock().() |
| 51 |
stop := timescip-go gomod github.com/golang/go/src go1.13 time/.Nowscip-go gomod github.com/golang/go/src go1.13 time/Now().() |
| 52 |
|
| 53 |
if want, got := clockPeriodscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/clockPeriod.*2, stop.Subscip-go gomod github.com/golang/go/src go1.13 time/Time#Sub().(start); want < got { |
| 54 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("Expected duration less than %v, got %v", want, got) |
| 55 |
} |
| 56 |
if want, got := false, fastscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/fast..runningscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/fastclock#running.; want != got { |
| 57 |
t.Errorfscip-go gomod github.com/golang/go/src go1.13 testing/common#Errorf().("Expected isRunning to be %v, got %v", want, got) |
| 58 |
} |
| 59 |
} |