@@ -137,13 +137,17 @@ func init() {
137
137
}
138
138
139
139
type (
140
+ mapAsserter = map [int ]asserter
141
+
140
142
testersMap = map [int ]testing.TB
141
143
function = func ()
142
144
)
143
145
144
146
var (
145
147
// testers must be set if assertion package is used for the unit testing.
146
148
testers = x .NewRWMap [testersMap ]()
149
+
150
+ asserterMap = x .NewRWMap [mapAsserter ]()
147
151
)
148
152
149
153
const (
@@ -286,6 +290,38 @@ func ThatNot(term bool, a ...any) {
286
290
}
287
291
}
288
292
293
+ func ThatX (term bool , a ... any ) {
294
+ if ! term {
295
+ thatXDo (a )
296
+ }
297
+ }
298
+
299
+ func ZeroX [T Number ](val T , a ... any ) {
300
+ if val != 0 {
301
+ doZeroX (val , a )
302
+ }
303
+ }
304
+
305
+ func doZeroX [T Number ](val T , a []any ) {
306
+ defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want (== '0')" , val )
307
+ currentX ().reportAssertionFault (1 , defMsg , a )
308
+ }
309
+
310
+ func thatXDo (a []any ) {
311
+ defMsg := assertionMsg
312
+ currentX ().reportAssertionFault (1 , defMsg , a )
313
+ }
314
+
315
+ func currentX () asserter {
316
+ // we need thread local storage, maybe we'll implement that to x.package?
317
+ // study `tester` and copy ideas from it.
318
+ return asserterMap .Get (goid ())
319
+ }
320
+
321
+ func SetDefaultX (i defInd ) {
322
+ asserterMap .Set (goid (), defAsserter [i ])
323
+ }
324
+
289
325
// That asserts that the term is true. If not it panics with the given
290
326
// formatting string. Thanks to inlining, the performance penalty is equal to a
291
327
// single 'if-statement' that is almost nothing.
@@ -884,11 +920,26 @@ func NoError(err error, a ...any) {
884
920
// are used to override the auto-generated assert violation message.
885
921
func Error (err error , a ... any ) {
886
922
if err == nil {
887
- defMsg := "Error:" + assertionMsg + ": missing error"
888
- current ().reportAssertionFault (0 , defMsg , a )
923
+ doErrorX (a )
924
+ }
925
+ }
926
+
927
+ func ErrorX (err error , a ... any ) {
928
+ if err == nil {
929
+ doError (a )
889
930
}
890
931
}
891
932
933
+ func doErrorX (a []any ) {
934
+ defMsg := "Error:" + assertionMsg + ": missing error"
935
+ currentX ().reportAssertionFault (0 , defMsg , a )
936
+ }
937
+
938
+ func doError (a []any ) {
939
+ defMsg := "Error:" + assertionMsg + ": missing error"
940
+ current ().reportAssertionFault (0 , defMsg , a )
941
+ }
942
+
892
943
// Greater asserts that the value is greater than want. If it is not it panics
893
944
// and builds a violation message. Thanks to inlining, the performance penalty
894
945
// is equal to a single 'if-statement' that is almost nothing.
0 commit comments