Best Go-testdeep code snippet using test.Fail
rules_test.go
Source:rules_test.go
...165 assertEventsMaxDepth(t, 1, BCT(1), ACL(10), ADT(NewString(5, 0)), ADT(NewString(3, 0)), ADT(NewString(2, 0)), ED())166}167func TestRulesInArrayBasic(t *testing.T) {168 rules := newRulesWithMaxDepth(9)169 assertEventsFail(t, rules, ACM(0))170 assertEventsSucceed(t, rules, BAU8())171 assertEventsSucceed(t, rules, ACM(0))172 assertEventsSucceed(t, rules, ACL(4))173 assertEventsFail(t, rules, ACM(0))174 assertEventsSucceed(t, rules, ADT(NewString(4, 0)))175 assertEventsFail(t, rules, ACM(0))176 assertEventsSucceed(t, rules, ED())177 assertEventsFail(t, rules, ACM(0))178}179func TestRulesInArray(t *testing.T) {180 rules := newRulesWithMaxDepth(9)181 assertEventsFail(t, rules, ACM(0))182 assertEventsSucceed(t, rules, L())183 assertEventsFail(t, rules, ACM(0))184 assertEventsSucceed(t, rules, BS())185 assertEventsSucceed(t, rules, ACM(0))186 assertEventsSucceed(t, rules, ACM(10))187 assertEventsFail(t, rules, ACM(0))188 assertEventsSucceed(t, rules, ADT(NewString(4, 0)))189 assertEventsFail(t, rules, ACM(0))190 assertEventsSucceed(t, rules, ADT(NewString(4, 0)))191 assertEventsFail(t, rules, ACM(0))192 assertEventsSucceed(t, rules, ADT(NewString(2, 0)))193 assertEventsSucceed(t, rules, ACM(0))194 assertEventsSucceed(t, rules, ACL(5))195 assertEventsSucceed(t, rules, ADT(NewString(5, 0)))196 assertEventsFail(t, rules, ACM(0))197 assertEventsSucceed(t, rules, BRID())198 assertEventsSucceed(t, rules, ACM(0))199 assertEventsSucceed(t, rules, ACL(5))200 assertEventsFail(t, rules, ACM(0))201 assertEventsSucceed(t, rules, ADT("a:123"))202 assertEventsFail(t, rules, ACM(0))203 assertEventsSucceed(t, rules, E())204 assertEventsFail(t, rules, ACM(0))205 assertEventsSucceed(t, rules, ED())206 assertEventsFail(t, rules, ACM(0))207}208func TestRulesInArrayEmpty(t *testing.T) {209 rules := newRulesWithMaxDepth(9)210 assertEventsFail(t, rules, ACM(0))211 assertEventsSucceed(t, rules, L())212 assertEventsFail(t, rules, ACM(0))213 assertEventsSucceed(t, rules, BS())214 assertEventsSucceed(t, rules, ACM(0))215 assertEventsSucceed(t, rules, ACL(0))216 assertEventsFail(t, rules, ACM(0))217 assertEventsSucceed(t, rules, BAU8())218 assertEventsSucceed(t, rules, ACM(0))219 assertEventsSucceed(t, rules, ACL(0))220 assertEventsFail(t, rules, ACM(0))221 assertEventsSucceed(t, rules, E())222 assertEventsFail(t, rules, ACM(0))223 assertEventsSucceed(t, rules, ED())224 assertEventsFail(t, rules, ACM(0))225}226// =================227// Containers: Empty228// =================229func TestRulesListEmpty(t *testing.T) {230 assertEventsMaxDepth(t, 1, L(), E(), ED())231}232func TestRulesMapEmpty(t *testing.T) {233 assertEventsMaxDepth(t, 1, M(), E(), ED())234}235func TestRulesNodeEmpty(t *testing.T) {236 assertEventsMaxDepth(t, 1, NODE(), NULL(), E(), ED())237}238// =======================239// Containers: Single item240// =======================241func TestRulesListSingleItem(t *testing.T) {242 assertEventsMaxDepth(t, 1, L(), B(true), E(), ED())243}244func TestRulesMapPair(t *testing.T) {245 assertEventsMaxDepth(t, 1, M(), B(true), NULL(), E(), ED())246}247func TestRulesNodeSingleItem(t *testing.T) {248 assertEventsMaxDepth(t, 1, NODE(), B(true), E(), ED())249 assertEventsMaxDepth(t, 1, NODE(), NULL(), B(true), E(), ED())250}251// ==================252// Containers: Filled253// ==================254func TestRulesListFilled(t *testing.T) {255 assertEventsMaxDepth(t, 2, L(), NULL(), NAN(), B(true), N(0.1), N(1), N(-1),256 T(compact_time.AsCompactTime(time.Now())), AU8(NewBytes(1, 0)), E(), ED())257}258func TestRulesMapFilled(t *testing.T) {259 assertEventsMaxDepth(t, 2, M(), B(true), NULL(), N(0.1), NAN(), N(1), N(-1),260 T(compact_time.AsCompactTime(time.Now())), AU8(NewBytes(1, 0)), E(), ED())261}262func TestRulesMapList(t *testing.T) {263 assertEventsMaxDepth(t, 2, M(), N(1), L(), E(), E(), ED())264}265func TestRulesMapMap(t *testing.T) {266 assertEventsMaxDepth(t, 2, M(), N(1), M(), E(), E(), ED())267}268func TestRulesDeepContainer(t *testing.T) {269 assertEventsMaxDepth(t, 6, L(), L(), M(), N(-1), M(), N(1), L(),270 S("0123456789"), E(), E(), E(), E(), E(), ED())271}272func TestRulesMarkerLocalReference(t *testing.T) {273 assertEventsMaxDepth(t, 9, M(),274 S("keys"),275 L(),276 MARK("1"), S("foo"),277 MARK("2"), S("bar"),278 E(),279 REFL("1"), N(1),280 REFL("2"), N(2),281 E())282}283func TestRulesNodeFilled(t *testing.T) {284 assertEventsMaxDepth(t, 2, NODE(), NULL(), NAN(), B(true), N(0.1), N(1), N(-1),285 T(compact_time.AsCompactTime(time.Now())), AU8(NewBytes(1, 0)), NODE(), NULL(), E(), E(), ED())286}287// ================288// Error conditions289// ================290func TestRulesErrorOnEndTooManyTimes(t *testing.T) {291 rules := newRulesWithMaxDepth(10)292 assertEventsSucceed(t, rules, L(), E())293 assertEventsFail(t, rules, E())294 rules = newRulesWithMaxDepth(10)295 assertEventsSucceed(t, rules, M(), E())296 assertEventsFail(t, rules, E())297 rules = newRulesWithMaxDepth(10)298 assertEventsSucceed(t, rules, NODE(), NULL(), E())299 assertEventsFail(t, rules, E())300}301func TestRulesErrorUnendedContainer(t *testing.T) {302 rules := newRulesWithMaxDepth(10)303 assertEventsSucceed(t, rules, L())304 assertEventsFail(t, rules, ED())305 rules = newRulesWithMaxDepth(10)306 assertEventsSucceed(t, rules, M())307 assertEventsFail(t, rules, ED())308 rules = newRulesWithMaxDepth(10)309 assertEventsSucceed(t, rules, NODE())310 assertEventsFail(t, rules, ED())311 rules = newRulesWithMaxDepth(10)312 assertEventsSucceed(t, rules, NODE(), NULL())313 assertEventsFail(t, rules, ED())314}315func TestRulesErrorArrayTooManyBytes(t *testing.T) {316 for _, arrayType := range test.ArrayBeginTypes {317 rules := newRulesWithMaxDepth(10)318 assertEventsSucceed(t, rules, arrayType, ACL(1))319 assertEventsFail(t, rules, ADU8([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))320 }321}322func TestRulesErrorArrayTooFewBytes(t *testing.T) {323 for _, arrayType := range test.ArrayBeginTypes {324 rules := newRulesWithMaxDepth(10)325 assertEventsSucceed(t, rules, arrayType, ACL(2000),326 ADU8([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2, 3, 4, 5, 6}))327 assertEventsFail(t, rules, ED())328 }329}330func TestRulesErrorMarkerIDLength0(t *testing.T) {331 rules := newRulesWithMaxDepth(2)332 assertEventsFail(t, rules, MARK(""))333}334func TestRulesErrorReferenceIDLength0(t *testing.T) {335 rules := newRulesWithMaxDepth(3)336 assertEventsFail(t, rules, L(), REFL(""))337}338func TestRulesErrorRefMissingMarker(t *testing.T) {339 rules := newRulesWithMaxDepth(5)340 assertEventsSucceed(t, rules, L(), REFL("test"), E())341 assertEventsFail(t, rules, ED())342}343func TestRulesResourceIDLength0_1(t *testing.T) {344 assertEventsMaxDepth(t, 2, RID(""))345 assertEventsMaxDepth(t, 2, RID("a"))346}347func TestRulesErrorDuplicateMarkerID(t *testing.T) {348 rules := newRulesWithMaxDepth(10)349 assertEventsSucceed(t, rules, L(), MARK("test"), B(true))350 // TODO: Can we check for duplicate markers before the marked object is read?351 assertEventsFail(t, rules, MARK("test"), B(false))352}353func TestRulesErrorInvalidMarkerID(t *testing.T) {354 prefix := func() events.DataEventReceiver {355 rules := newRulesWithMaxDepth(10)356 return rules357 }358 assertEachEventFails(t, prefix, MARK(""))359 for ch := 0; ch <= 0xff; ch++ {360 if ch >= 'a' && ch <= 'z' {361 continue362 }363 if ch >= 'A' && ch <= 'Z' {364 continue365 }366 if ch == '_' {367 continue368 }369 // TODO: Fix marker ID validation test370 // assertEachEventFails(t, prefix, S(string([]byte{byte(ch)})))371 }372}373// ======374// Limits375// ======376// TODO: Other array byte lengths377func TestRulesMaxBytesLength(t *testing.T) {378 opts := options.DefaultRuleOptions()379 opts.MaxArrayByteLength = 10380 rules := newRulesAfterVersion(&opts)381 assertEventsFail(t, rules, AU8(NewBytes(11, 0)))382 rules = newRulesAfterVersion(&opts)383 assertEventsSucceed(t, rules, BAU8(), ACM(8), ADU8(NewBytes(8, 0)))384 assertEventsFail(t, rules, ACL(4))385}386func TestRulesMaxStringLength(t *testing.T) {387 opts := options.DefaultRuleOptions()388 opts.MaxStringByteLength = 10389 rules := newRulesAfterVersion(&opts)390 assertEventsFail(t, rules, S("12345678901"))391 rules = newRulesAfterVersion(&opts)392 assertEventsSucceed(t, rules, BS(), ACM(8), ADU8(NewBytes(8, 40)))393 assertEventsFail(t, rules, ACL(4))394}395func TestRulesMaxResourceIDLength(t *testing.T) {396 opts := options.DefaultRuleOptions()397 opts.MaxResourceIDByteLength = 10398 rules := newRulesAfterVersion(&opts)399 assertEventsFail(t, rules, RID("12345678901"))400 rules = newRulesAfterVersion(&opts)401 assertEventsSucceed(t, rules, BRID(), ACM(8), ADU8(NewBytes(8, 64)))402 assertEventsFail(t, rules, ACL(4))403}404func TestRulesMaxIDLength(t *testing.T) {405 maxIDLength := 200406 opts := options.DefaultRuleOptions()407 opts.MaxIdentifierLength = uint64(maxIDLength)408 rules := newRulesAfterVersion(&opts)409 assertEventsFail(t, rules, MARK(string(NewString(maxIDLength+1, 0))))410 rules = newRulesAfterVersion(&opts)411 assertEventsSucceed(t, rules,412 L(),413 MARK(string(NewString(maxIDLength, 0))),414 N(1),415 REFL(string(NewString(maxIDLength, 0))),416 E(),417 )418}419func TestRulesMaxContainerDepth(t *testing.T) {420 rules := newRulesWithMaxDepth(1)421 assertEventsSucceed(t, rules, L())422 assertEventsFail(t, rules, L())423}424func TestRulesMaxObjectCount(t *testing.T) {425 opts := options.DefaultRuleOptions()426 opts.MaxObjectCount = 3427 rules := newRulesAfterVersion(&opts)428 assertEventsSucceed(t, rules, L(), S("test"), B(true))429 assertEventsFail(t, rules, B(false))430}431func TestRulesMaxReferenceCount(t *testing.T) {432 opts := options.DefaultRuleOptions()433 opts.MaxLocalReferenceCount = 2434 rules := newRulesAfterVersion(&opts)435 assertEventsSucceed(t, rules, L(), MARK("test"), B(true), MARK("10"), B(true))436 assertEventsFail(t, rules, MARK("xx"), B(true))437}438func TestRulesReset(t *testing.T) {439 opts := options.DefaultRuleOptions()440 opts.MaxContainerDepth = 2441 opts.MaxObjectCount = 5442 opts.MaxLocalReferenceCount = 2443 rules := newRulesAfterVersion(&opts)444 assertEventsSucceed(t, rules, L())445 rules.Reset()446 assertEventsFail(t, rules, E())447 assertEventsSucceed(t, rules, BD(), EvV, L(), L(), N(1), N(1), N(1), E())448 assertEventsFail(t, rules, N(1))449 rules.Reset()450 assertEventsSucceed(t, rules, BD(), EvV, L(), MARK("1"), S("test"), MARK("2"), S("more tests"))451 assertEventsFail(t, rules, MARK("xx"), B(true))452 rules.Reset()453 assertEventsSucceed(t, rules, BD(), EvV, L(), MARK("1"), S("test"))454}455func TestTopLevelStringLikeReferenceID(t *testing.T) {456 opts := options.DefaultRuleOptions()457 rules := NewRules(nullevent.NewNullEventReceiver(), &opts)458 assertEventsSucceed(t, rules, BD(), EvV, REFR("http://x.y"), ED())459}460func TestRulesForwardLocalReference(t *testing.T) {461 rules := newRulesAfterVersion(nil)462 assertEventsSucceed(t, rules, M(),463 S("marked"), MARK("x"), M(),464 S("recursive"), REFL("x"),465 E(),466 E())467}468func TestRulesIdentifier(t *testing.T) {469 rules := newRulesAfterVersion(nil)470 assertEventsFail(t, rules, MARK("12\u0001abc"), N(1))471 rules = newRulesAfterVersion(nil)472 assertEventsFail(t, rules, MARK(""), N(1))473 rules = newRulesAfterVersion(nil)474 assertEventsFail(t, rules, MARK("a+b"), N(1))475 rules = newRulesAfterVersion(nil)476 assertEventsFail(t, rules, MARK("a+b"), N(1))477 rules = newRulesAfterVersion(nil)478 assertEventsFail(t, rules, MARK(":a"), N(1))479 rules = newRulesAfterVersion(nil)480 assertEventsFail(t, rules, MARK("a:"), N(1))481 rules = newRulesAfterVersion(nil)482 assertEventsFail(t, rules, MARK("a::a"), N(1))483 rules = newRulesAfterVersion(nil)484 assertEventsSucceed(t, rules, MARK("1"), N(1))485 rules = newRulesAfterVersion(nil)486 assertEventsSucceed(t, rules, MARK("a"), N(1))487 rules = newRulesAfterVersion(nil)488 assertEventsSucceed(t, rules, MARK("a-a"), N(1))489 rules = newRulesAfterVersion(nil)490 assertEventsSucceed(t, rules, MARK("_a"), N(1))491 rules = newRulesAfterVersion(nil)492 assertEventsSucceed(t, rules, MARK("a_"), N(1))493 rules = newRulesAfterVersion(nil)494 assertEventsSucceed(t, rules, MARK("a-"), N(1))495 rules = newRulesAfterVersion(nil)496 assertEventsSucceed(t, rules, MARK("-a"), N(1))497 rules = newRulesAfterVersion(nil)498 assertEventsSucceed(t, rules, MARK("a."), N(1))499 rules = newRulesAfterVersion(nil)500 assertEventsSucceed(t, rules, MARK(".a"), N(1))501 rules = newRulesAfterVersion(nil)502 assertEventsSucceed(t, rules, MARK("0_"), N(1))503 rules = newRulesAfterVersion(nil)504 assertEventsSucceed(t, rules, MARK("0-"), N(1))505 rules = newRulesAfterVersion(nil)506 assertEventsSucceed(t, rules, MARK("a-_a12-_3_gy"), N(1))507 rules = newRulesAfterVersion(nil)508 assertEventsSucceed(t, rules, MARK("人æ°"), N(1))509 rules = newRulesAfterVersion(nil)510 assertEventsSucceed(t, rules, MARK("a...."), N(1))511 rules = newRulesAfterVersion(nil)512 assertEventsSucceed(t, rules, MARK("a\u0300"), N(1))513}514func TestRulesMultichunk(t *testing.T) {515 rules := newRulesAfterVersion(nil)516 assertEventsSucceed(t, rules, BS(), ACM(1), ADT("a"), ACL(0))517}518func TestRulesEdge(t *testing.T) {519 rules := newRulesAfterVersion(nil)520 assertEventsSucceed(t, rules, EDGE(), RID("x"), RID("y"), N(1), E())521 rules = newRulesAfterVersion(nil)522 assertEventsSucceed(t, rules, EDGE(), RID("a"), RID("b"), N(1), E(), ED())523}524// =============525// Allowed Types526// =============527func TestRulesAllowedTypesTLO(t *testing.T) {528 assertEventStreamsSucceed(t,529 test.GenerateAllVariants(530 test.Events{BD(), V(ceVer)},531 test.Events{},532 test.Events{},533 test.Events{ED()},534 test.ValidTLOValues))535 assertEventStreamsFail(t,536 test.GenerateAllVariants(537 test.Events{BD(), V(ceVer)},538 test.Events{},539 test.Events{},540 test.Events{ED()},541 test.InvalidTLOValues))542}543func TestRulesAllowedTypesList(t *testing.T) {544 assertEventStreamsSucceed(t,545 test.GenerateAllVariants(546 test.Events{BD(), V(ceVer)},547 test.Events{L()},548 test.Events{E()},549 test.Events{ED()},550 test.ValidListValues))551 assertEventStreamsFail(t,552 test.GenerateAllVariants(553 test.Events{BD(), V(ceVer)},554 test.Events{L()},555 test.Events{E()},556 test.Events{ED()},557 test.InvalidListValues))558}559func TestRulesAllowedTypesMapKey(t *testing.T) {560 assertEventStreamsSucceed(t,561 test.GenerateAllVariants(562 test.Events{BD(), V(ceVer)},563 test.Events{M()},564 test.Events{N(1), E()},565 test.Events{ED()},566 test.ValidMapKeys))567 assertEventStreamsFail(t,568 test.GenerateAllVariants(569 test.Events{BD(), V(ceVer)},570 test.Events{M()},571 test.Events{N(1), E()},572 test.Events{ED()},573 test.InvalidMapKeys))574}575func TestRulesAllowedTypesMapValue(t *testing.T) {576 assertEventStreamsSucceed(t,577 test.GenerateAllVariants(578 test.Events{BD(), V(ceVer)},579 test.Events{M(), B(true)},580 test.Events{E()},581 test.Events{ED()},582 test.ValidMapValues))583 assertEventStreamsFail(t,584 test.GenerateAllVariants(585 test.Events{BD(), V(ceVer)},586 test.Events{M(), B(true)},587 test.Events{E()},588 test.Events{ED()},589 test.InvalidMapValues))590}591func TestRulesAllowedTypesNonStringArrayBegin(t *testing.T) {592 assertSuccess := func(events ...test.Event) {593 for _, arrayType := range test.NonStringArrayBeginTypes {594 for _, event := range events {595 rules := newRulesWithMaxDepth(10)596 assertEventsSucceed(t, rules, arrayType)597 assertEventsSucceed(t, rules, event)598 }599 }600 }601 assertFail := func(events ...test.Event) {602 for _, arrayType := range test.NonStringArrayBeginTypes {603 for _, event := range events {604 rules := newRulesWithMaxDepth(10)605 assertEventsSucceed(t, rules, arrayType)606 assertEventsFail(t, rules, event)607 }608 }609 }610 assertSuccess(test.ValidAfterNonStringArrayBegin...)611 assertFail(test.InvalidAfterNonStringArrayBegin...)612}613func TestRulesAllowedTypesStringArrayBegin(t *testing.T) {614 assertSuccess := func(events ...test.Event) {615 for _, arrayType := range test.StringArrayBeginTypes {616 for _, event := range events {617 rules := newRulesWithMaxDepth(10)618 assertEventsSucceed(t, rules, arrayType)619 assertEventsSucceed(t, rules, event)620 }621 }622 }623 assertFail := func(events ...test.Event) {624 for _, arrayType := range test.StringArrayBeginTypes {625 for _, event := range events {626 rules := newRulesWithMaxDepth(10)627 assertEventsSucceed(t, rules, arrayType)628 assertEventsFail(t, rules, event)629 }630 }631 }632 assertSuccess(test.ValidAfterStringArrayBegin...)633 assertFail(test.InvalidAfterStringArrayBegin...)634}635func TestRulesAllowedTypesArrayChunk(t *testing.T) {636 assertSuccess := func(events ...test.Event) {637 for _, arrayType := range test.ArrayBeginTypes {638 for _, event := range events {639 rules := newRulesWithMaxDepth(10)640 assertEventsSucceed(t, rules, arrayType, ACL(1))641 assertEventsSucceed(t, rules, event)642 }643 }644 }645 assertFail := func(events ...test.Event) {646 for _, arrayType := range test.ArrayBeginTypes {647 for _, event := range events {648 rules := newRulesWithMaxDepth(10)649 assertEventsSucceed(t, rules, arrayType, ACL(1))650 assertEventsFail(t, rules, event)651 }652 }653 }654 // TODO: Make sure end of array is properly aligned to size width655 assertSuccess(test.ValidAfterArrayChunk...)656 assertFail(test.InvalidAfterArrayChunk...)657}658func TestRulesAllowedTypesMarkerValue(t *testing.T) {659 assertEventStreamsSucceed(t,660 test.GenerateAllVariants(661 test.Events{BD(), V(ceVer)},662 test.Events{MARK("1")},663 test.Events{},664 test.Events{ED()},665 test.ValidMarkerValues))666 assertEventStreamsFail(t,667 test.GenerateAllVariants(668 test.Events{BD(), V(ceVer)},669 test.Events{MARK("1")},670 test.Events{},671 test.Events{ED()},672 test.InvalidMarkerValues))673}674func TestRulesAllowedTypesNodeValue(t *testing.T) {675 assertEventStreamsSucceed(t,676 test.GenerateAllVariants(677 test.Events{BD(), V(ceVer)},678 test.Events{NODE()},679 test.Events{E()},680 test.Events{ED()},681 test.ValidNodeValues))682 assertEventStreamsFail(t,683 test.GenerateAllVariants(684 test.Events{BD(), V(ceVer)},685 test.Events{NODE()},686 test.Events{E()},687 test.Events{ED()},688 test.InvalidNodeValues))689}690func TestRulesAllowedTypesNodeChild(t *testing.T) {691 assertEventStreamsSucceed(t,692 test.GenerateAllVariants(693 test.Events{BD(), V(ceVer)},694 test.Events{NODE(), N(1)},695 test.Events{E()},696 test.Events{ED()},697 test.ValidListValues))698 assertEventStreamsFail(t,699 test.GenerateAllVariants(700 test.Events{BD(), V(ceVer)},701 test.Events{NODE(), N(1)},702 test.Events{E()},703 test.Events{ED()},704 test.InvalidListValues))705 assertEventStreamsSucceed(t,706 test.GenerateAllVariants(707 test.Events{BD(), V(ceVer)},708 test.Events{NODE(), N(1), N(1)},709 test.Events{E()},710 test.Events{ED()},711 test.ValidListValues))712 assertEventStreamsFail(t,713 test.GenerateAllVariants(714 test.Events{BD(), V(ceVer)},715 test.Events{NODE(), N(1), N(1)},716 test.Events{E()},717 test.Events{ED()},718 test.InvalidListValues))719}720func TestRulesAllowedTypesEdgeSource(t *testing.T) {721 assertEventStreamsSucceed(t,722 test.GenerateAllVariants(723 test.Events{BD(), V(ceVer)},724 test.Events{EDGE()},725 test.Events{RID("a"), N(1), E()},726 test.Events{ED()},727 test.ValidEdgeSources))728 assertEventStreamsFail(t,729 test.GenerateAllVariants(730 test.Events{BD(), V(ceVer)},731 test.Events{EDGE()},732 test.Events{RID("a"), N(1), E()},733 test.Events{ED()},734 test.InvalidEdgeSources))735}736func TestRulesAllowedTypesEdgeDescription(t *testing.T) {737 assertEventStreamsSucceed(t,738 test.GenerateAllVariants(739 test.Events{BD(), V(ceVer)},740 test.Events{EDGE(), RID("a")},741 test.Events{N(1), E()},742 test.Events{ED()},743 test.ValidEdgeDescriptions))744 assertEventStreamsFail(t,745 test.GenerateAllVariants(746 test.Events{BD(), V(ceVer)},747 test.Events{EDGE(), RID("a")},748 test.Events{N(1), E()},749 test.Events{ED()},750 test.InvalidEdgeDescriptions))751}752func TestRulesAllowedTypesEdgeDestination(t *testing.T) {753 assertEventStreamsSucceed(t,754 test.GenerateAllVariants(755 test.Events{BD(), V(ceVer)},756 test.Events{EDGE(), RID("a"), RID("b")},757 test.Events{E()},758 test.Events{ED()},759 test.ValidEdgeDestinations))760 assertEventStreamsFail(t,761 test.GenerateAllVariants(762 test.Events{BD(), V(ceVer)},763 test.Events{EDGE(), RID("a"), RID("b")},764 test.Events{E()},765 test.Events{ED()},766 test.InvalidEdgeDescriptions))767}768func TestMedia(t *testing.T) {769 rules := NewRules(nullevent.NewNullEventReceiver(), nil)770 assertEventsSucceed(t, rules, BD(), V(0), BMEDIA("a/b"), ACL(0), ED())771}772func TestComment(t *testing.T) {773 assertEvents(t, BD(), V(ceVer), CM("a"), S("b"), ED())774 assertEvents(t, BD(), V(ceVer), CS("a"), S("b"), ED())...
string_test.go
Source:string_test.go
...517 var eArr []object.Object518 eArr = append(eArr, err)519 eOut := VAL(nil, eArr)520 if eOut.Type() != object.ERROR {521 fmt.Printf("Failed to find error")522 }523 var nArr []object.Object524 nArr = append(nArr, num)525 nOut := VAL(nil, nArr)526 if nOut.Type() != object.NUMBER {527 fmt.Printf("Failed to find number")528 }529 // str - this should become a number530 var sArr []object.Object531 sArr = append(sArr, str)532 sOut := VAL(nil, sArr)533 if sOut.Type() != object.NUMBER {534 fmt.Printf("Failed to convert string to number")535 }536 // invalid input - this should become an error537 var fArr []object.Object538 fArr = append(fArr, object.String("Not a number!"))539 fOut := VAL(nil, fArr)540 if fOut.Type() != object.ERROR {541 fmt.Printf("Error-handling failed")542 }543}...
maths_test.go
Source:maths_test.go
1// maths_test.go - Simple test-cases for maths-related primitives.2package builtin3import (4 "math"5 "testing"6 "github.com/skx/gobasic/object"7)8func TestABS(t *testing.T) {9 //10 // Requires a number argument11 //12 var failArgs []object.Object13 failArgs = append(failArgs, object.Error("Bogus type"))14 out := ABS(nil, failArgs)15 if out.Type() != object.ERROR {16 t.Errorf("We expected a type-error, but didn't receive one")17 }18 //19 // Now test that postivie and negative values work.20 //21 // Setup a structure for testing.22 //23 type ABSTest struct {24 In float6425 Out float6426 }27 // Define some tests28 tests := []ABSTest{29 {In: 3, Out: 3},30 {In: -3, Out: 3},31 }32 for _, test := range tests {33 args := []object.Object{object.Number(test.In)}34 output := ABS(nil, args)35 if output.Type() != object.NUMBER {36 t.Errorf("We expected a number-result, but got something else")37 }38 if output.(*object.NumberObject).Value != test.Out {39 t.Errorf("Abs %f gave '%f' not '%f'",40 test.In, output.(*object.NumberObject).Value, test.Out)41 }42 }43}44func TestACS(t *testing.T) {45 //46 // Requires a number argument47 //48 var failArgs []object.Object49 failArgs = append(failArgs, object.Error("Bogus type"))50 out := ACS(nil, failArgs)51 if out.Type() != object.ERROR {52 t.Errorf("We expected a type-error, but didn't receive one")53 }54 //55 // Call normally - ignore the result. Sorry.56 //57 var ok []object.Object58 ok = append(ok, object.Number(21))59 out2 := ACS(nil, ok)60 if out2.Type() != object.NUMBER {61 t.Errorf("We expected a numeric-result, but didn't receive one.")62 }63}64func TestASN(t *testing.T) {65 //66 // Requires a number argument67 //68 var failArgs []object.Object69 failArgs = append(failArgs, object.Error("Bogus type"))70 out := ASN(nil, failArgs)71 if out.Type() != object.ERROR {72 t.Errorf("We expected a type-error, but didn't receive one")73 }74 //75 // Call normally - ignore the result. Sorry.76 //77 var ok []object.Object78 ok = append(ok, object.Number(21))79 out2 := ASN(nil, ok)80 if out2.Type() != object.NUMBER {81 t.Errorf("We expected a numeric-result, but didn't receive one.")82 }83}84func TestATN(t *testing.T) {85 //86 // Requires a number argument87 //88 var failArgs []object.Object89 failArgs = append(failArgs, object.Error("Bogus type"))90 out := ATN(nil, failArgs)91 if out.Type() != object.ERROR {92 t.Errorf("We expected a type-error, but didn't receive one")93 }94 //95 // Call normally - ignore the result. Sorry.96 //97 var ok []object.Object98 ok = append(ok, object.Number(21))99 out2 := ATN(nil, ok)100 if out2.Type() != object.NUMBER {101 t.Errorf("We expected a numeric-result, but didn't receive one.")102 }103}104func TestBIN(t *testing.T) {105 //106 // Requires a number argument107 //108 var failArgs []object.Object109 failArgs = append(failArgs, object.Error("Bogus type"))110 out := BIN(nil, failArgs)111 if out.Type() != object.ERROR {112 t.Errorf("We expected a type-error, but didn't receive one")113 }114 //115 // Test an invalid input116 //117 var bogus []object.Object118 bogus = append(bogus, object.Number(2001))119 out = BIN(nil, bogus)120 if out.Type() != object.ERROR {121 t.Errorf("We expected an error, but didn't receive one")122 }123 //124 // Test a valid input125 //126 var valid []object.Object127 valid = append(valid, object.Number(1001))128 out = BIN(nil, valid)129 if out.Type() != object.NUMBER {130 t.Errorf("We expected no error, but got one")131 }132 if out.(*object.NumberObject).Value != 9 {133 t.Errorf("Wrong result for binary conversion of 1001")134 }135}136func TestCOS(t *testing.T) {137 //138 // Requires a number argument139 //140 var failArgs []object.Object141 failArgs = append(failArgs, object.Error("Bogus type"))142 out := COS(nil, failArgs)143 if out.Type() != object.ERROR {144 t.Errorf("We expected a type-error, but didn't receive one")145 }146 //147 // Call normally - ignore the result. Sorry.148 //149 var ok []object.Object150 ok = append(ok, object.Number(21))151 out2 := COS(nil, ok)152 if out2.Type() != object.NUMBER {153 t.Errorf("We expected a numeric-result, but didn't receive one.")154 }155}156func TestEXP(t *testing.T) {157 //158 // Requires a number argument159 //160 var failArgs []object.Object161 failArgs = append(failArgs, object.Error("Bogus type"))162 out := EXP(nil, failArgs)163 if out.Type() != object.ERROR {164 t.Errorf("We expected a type-error, but didn't receive one")165 }166 //167 // Call normally - ignore the result. Sorry.168 //169 var ok []object.Object170 ok = append(ok, object.Number(21))171 out2 := EXP(nil, ok)172 if out2.Type() != object.NUMBER {173 t.Errorf("We expected a numeric-result, but didn't receive one.")174 }175}176func TestINT(t *testing.T) {177 //178 // Requires a number argument179 //180 var failArgs []object.Object181 failArgs = append(failArgs, object.Error("Bogus type"))182 out := INT(nil, failArgs)183 if out.Type() != object.ERROR {184 t.Errorf("We expected a type-error, but didn't receive one")185 }186 //187 // Now test that truncation works188 //189 // Setup a structure for testing.190 //191 type INTTest struct {192 In float64193 Out int194 }195 // Define some tests196 tests := []INTTest{197 {In: 3.1, Out: 3},198 {In: -3.2, Out: -3},199 }200 for _, test := range tests {201 args := []object.Object{object.Number(test.In)}202 output := INT(nil, args)203 if output.Type() != object.NUMBER {204 t.Errorf("We expected a number-result, but got something else")205 }206 if int(output.(*object.NumberObject).Value) != test.Out {207 t.Errorf("INT %f gave '%d' not '%d'",208 test.In, int(output.(*object.NumberObject).Value), test.Out)209 }210 }211}212func TestLN(t *testing.T) {213 //214 // Requires a number argument215 //216 var failArgs []object.Object217 failArgs = append(failArgs, object.Error("Bogus type"))218 out := LN(nil, failArgs)219 if out.Type() != object.ERROR {220 t.Errorf("We expected a type-error, but didn't receive one")221 }222 //223 // Call normally - ignore the result. Sorry.224 //225 var ok []object.Object226 ok = append(ok, object.Number(21))227 out2 := LN(nil, ok)228 if out2.Type() != object.NUMBER {229 t.Errorf("We expected a numeric-result, but didn't receive one.")230 }231}232func TestPI(t *testing.T) {233 out := PI(nil, nil)234 if out.Type() != object.NUMBER {235 t.Errorf("Invalid type in return value")236 }237 if out.(*object.NumberObject).Value != math.Pi {238 t.Errorf("Invalid return value")239 }240}241func TestRND(t *testing.T) {242 //243 // Requires a number argument244 //245 var failArgs []object.Object246 failArgs = append(failArgs, object.Error("Bogus type"))247 out := RND(nil, failArgs)248 if out.Type() != object.ERROR {249 t.Errorf("We expected a type-error, but didn't receive one")250 }251 //252 // Requires a POSITIVE argument253 //254 var negs []object.Object255 negs = append(negs, object.Number(-32))256 out = RND(nil, negs)257 if out.Type() != object.ERROR {258 t.Errorf("We expected an error, but didn't receive one")259 }260 //261 // Now call normally.262 //263 var ok []object.Object264 ok = append(ok, object.Number(32))265 out2 := RND(nil, ok)266 if out2.Type() != object.NUMBER {267 t.Errorf("We expected a number, but didn't receive one")268 }269}270func TestSGN(t *testing.T) {271 //272 // Requires a number argument273 //274 var failArgs []object.Object275 failArgs = append(failArgs, object.Error("Bogus type"))276 out := SGN(nil, failArgs)277 if out.Type() != object.ERROR {278 t.Errorf("We expected a type-error, but didn't receive one")279 }280 //281 // Now test that sign extension works.282 //283 // Setup a structure for testing.284 //285 type SGNTest struct {286 In float64287 Out float64288 }289 // Define some tests290 tests := []SGNTest{291 {In: 3.1, Out: 1},292 {In: 0, Out: 0},293 {In: -3.2, Out: -1},294 }295 for _, test := range tests {296 args := []object.Object{object.Number(test.In)}297 output := SGN(nil, args)298 if output.Type() != object.NUMBER {299 t.Errorf("We expected a number-result, but got something else")300 }301 if output.(*object.NumberObject).Value != test.Out {302 t.Errorf("INT %f gave '%f' not '%f'",303 test.In, output.(*object.NumberObject).Value, test.Out)304 }305 }306}307func TestSIN(t *testing.T) {308 //309 // Requires a number argument310 //311 var failArgs []object.Object312 failArgs = append(failArgs, object.Error("Bogus type"))313 out := SIN(nil, failArgs)314 if out.Type() != object.ERROR {315 t.Errorf("We expected a type-error, but didn't receive one")316 }317 //318 // Call normally - ignore the result. Sorry.319 //320 var ok []object.Object321 ok = append(ok, object.Number(21))322 out2 := SIN(nil, ok)323 if out2.Type() != object.NUMBER {324 t.Errorf("We expected a numeric-result, but didn't receive one.")325 }326}327func TestSQR(t *testing.T) {328 //329 // Requires a number argument330 //331 var failArgs []object.Object332 failArgs = append(failArgs, object.Error("Bogus type"))333 out := SQR(nil, failArgs)334 if out.Type() != object.ERROR {335 t.Errorf("We expected a type-error, but didn't receive one")336 }337 //338 // Requires a POSITIVE argument339 //340 var negs []object.Object341 negs = append(negs, object.Number(-32))342 out = SQR(nil, negs)343 if out.Type() != object.ERROR {344 t.Errorf("We expected an error, but didn't receive one")345 }346 //347 // Now call normally.348 //349 var ok []object.Object350 ok = append(ok, object.Number(16))351 out2 := SQR(nil, ok)352 if out2.Type() != object.NUMBER {353 t.Errorf("We expected a number, but didn't receive one")354 }355 if out2.(*object.NumberObject).Value != 4 {356 t.Errorf("Square-root result was wrong")357 }358}359func TestTAN(t *testing.T) {360 //361 // Requires a number argument362 //363 var failArgs []object.Object364 failArgs = append(failArgs, object.Error("Bogus type"))365 out := TAN(nil, failArgs)366 if out.Type() != object.ERROR {367 t.Errorf("We expected a type-error, but didn't receive one")368 }369 //370 // Call normally - ignore the result. Sorry.371 //372 var ok []object.Object373 ok = append(ok, object.Number(21))374 out2 := TAN(nil, ok)375 if out2.Type() != object.NUMBER {376 t.Errorf("We expected a numeric-result, but didn't receive one.")377 }378}...
Fail
Using AI Code Generation
1import (2func TestFail(t *testing.T) {3 t.Fail()4}5import (6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import (10func TestError(t *testing.T) {11 t.Error("Error")12}13import (14func TestErrorf(t *testing.T) {15 t.Errorf("Errorf")16}17import (18func TestFatal(t *testing.T) {19 t.Fatal("Fatal")20}21import (22func TestFatalf(t *testing.T) {23 t.Fatalf("Fatalf")24}25import (26func TestLog(t *testing.T) {27 t.Log("Log")28}29import (30func TestLogf(t *testing.T) {31 t.Logf("Logf")32}33import (34func TestSkip(t *testing.T) {35 t.Skip("Skip")36}37import (38func TestSkipNow(t *testing.T) {39 t.SkipNow()40}41import (42func TestSkipf(t *testing.T) {43 t.Skipf("Skipf")44}45import (46func TestSkipped(t *testing.T) {47 t.Skipped()48}
Fail
Using AI Code Generation
1import (2func TestFail(t *testing.T) {3 t.Fail()4}5import (6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import (10func TestLog(t *testing.T) {11 t.Log("Hello")12}13import (14func TestLogf(t *testing.T) {15 t.Logf("Hello %s", "World")16}17import (18func TestParallel(t *testing.T) {19 t.Parallel()20}21import (22func TestRun(t *testing.T) {23 t.Run("subtest", func(t *testing.T) {24 t.Log("Hello")25 })26}27import (28func TestSkip(t *testing.T) {29 t.Skip("skip this test")30}31import (32func TestSkipNow(t *testing.T) {33 t.SkipNow()34}35import (36func TestSkipf(t *testing.T) {37 t.Skipf("skip this test")38}39import (40func TestSkipped(t *testing.T) {41 t.Log("Hello")42 t.Log(t.Skipped())43}44import (45func TestError(t *testing.T) {46 t.Error("Hello")47}48import (
Fail
Using AI Code Generation
1import (2func TestFail(t *testing.T) {3 t.Fail()4}5import (6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import (10func TestFatal(t *testing.T) {11 t.Fatal()12}13import (14func TestFatalf(t *testing.T) {15 t.Fatalf("Error: %d", 123)16}17import (18func TestLog(t *testing.T) {19 t.Log("Hello")20}21import (22func TestLogf(t *testing.T) {23 t.Logf("Hello %s", "World")24}25import (26func TestLog(t *testing.T) {27 t.Log("Hello")28}29import (30func TestLogf(t *testing.T) {31 t.Logf("Hello %s", "World")32}33import (34func TestSkip(t *testing.T) {35 t.Skip()36}37import (38func TestSkipNow(t *testing.T) {39 t.SkipNow()40}41import (42func TestSkipf(t *testing.T) {43 t.Skipf("Error: %d", 123)44}45import (46func TestSkip(t *testing.T) {
Fail
Using AI Code Generation
1import (2func TestFail(t *testing.T) {3 t.Fail()4}5import (6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import (10func TestSkip(t *testing.T) {11 t.Skip("Skipping this test")12}13import (14func TestLog(t *testing.T) {15 t.Log("This is a log message")16}17import (18func TestLogf(t *testing.T) {19 t.Logf("This is a formatted log message")20}21import (22func TestError(t *testing.T) {23 t.Error("This is an error message")24}25import (26func TestErrorf(t *testing.T) {27 t.Errorf("This is a formatted error message")28}29import (30func TestFatal(t *testing.T) {31 t.Fatal("This is a fatal message")32}33import (34func TestFatalf(t *testing.T) {35 t.Fatalf("This is a formatted fatal message")36}37import (38func TestParallel(t *testing.T) {39 t.Parallel()40}41import (42func TestRun(t *testing.T) {43 t.Run("Subtest", func(t *testing.T) {44 t.Log("This is a subtest")45 })46}
Fail
Using AI Code Generation
1import (2func TestFail(t *testing.T) {3 t.Fail()4}5import (6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import (10func TestLog(t *testing.T) {11 t.Log("Hello World!")12}13import (14func TestLogf(t *testing.T) {15 t.Logf("Hello %s!", name)16}17import (18func TestError(t *testing.T) {19 t.Error("Hello World!")20}21import (22func TestErrorf(t *testing.T) {23 t.Errorf("Hello %s!", name)24}25import (26func TestFatal(t *testing.T) {27 t.Fatal("Hello World!")28}29import (30func TestFatalf(t *testing.T) {31 t.Fatalf("Hello %s!", name)32}33import (34func TestSkip(t *testing.T) {35 t.Skip("Hello World!")36}37import (38func TestSkipf(t *testing.T) {39 t.Skipf("Hello %s!", name)40}41import (42func TestSkipNow(t *testing.T) {43 t.SkipNow()44}
Fail
Using AI Code Generation
1import "testing"2func TestFail(t *testing.T) {3 t.Fail()4}5import "testing"6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import "testing"10func TestFatal(t *testing.T) {11 t.Fatal("Fatal")12}13import "testing"14func TestFatalf(t *testing.T) {15 t.Fatalf("Fatal")16}17import "testing"18func TestLog(t *testing.T) {19 t.Log("Log")20}21import "testing"22func TestLogf(t *testing.T) {23 t.Logf("Log")24}25import "testing"26func TestLog(t *testing.T) {27 t.Log("Log")28}29import "testing"30func TestLogf(t *testing.T) {31 t.Logf("Log")32}33import "testing"34func TestParallel(t *testing.T) {35 t.Parallel()36}37import "testing"38func TestSkip(t *testing.T) {39 t.Skip()40}41import "testing"42func TestSkipNow(t *testing.T) {43 t.SkipNow()44}45import "testing"46func TestSkipf(t *testing.T) {47 t.Skipf("Skip")48}49import "testing"50func TestSkipNow(t *testing.T) {51 t.SkipNow()52}
Fail
Using AI Code Generation
1import (2func TestFail(t *testing.T) {3 t.Fail()4}5import (6func TestFailNow(t *testing.T) {7 t.FailNow()8}9import (10func TestFatal(t *testing.T) {11 t.Fatal()12}13import (14func TestLog(t *testing.T) {15 t.Log("Log method")16}17import (18func TestLogf(t *testing.T) {19 t.Logf("Logf method")20}21import (22func TestSkip(t *testing.T) {23 t.Skip("Skip method")24}25import (26func TestSkipNow(t *testing.T) {27 t.SkipNow()28}29import (30func TestSkipf(t *testing.T) {31 t.Skipf("Skipf method")32}33import (34func TestSkipNow(t *testing.T) {35 t.SkipNow()36}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!