How to use init method of tests Package

Best K6 code snippet using tests.init

array_test.go

Source:array_test.go Github

copy

Full Screen

...22 end23 `, []interface{}{0, 2, 4}},24 }25 for i, tt := range tests {26 vm := initTestVM()27 evaluated := vm.testEval(t, tt.input, getFilename())28 verifyArrayObject(t, i, evaluated, tt.expected)29 vm.checkCFP(t, i, 0)30 vm.checkSP(t, i, 1)31 }32}33func TestArrayInitializationFail(t *testing.T) {34 testsFail := []errorTestCase{35 {`36 Array.new(1, 2, 3)37 `, "ArgumentError: Expect 1 to 2 argument(s). got: 3", 1},38 {`39 Array.new("foo")40 `, "ArgumentError: Expect argument to be Integer. got: String", 1},41 {`42 Array.new(-1)43 `, "ArgumentError: Negative Array Size", 1},44 }45 for i, tt := range testsFail {46 v := initTestVM()47 evaluated := v.testEval(t, tt.input, getFilename())48 checkErrorMsg(t, i, evaluated, tt.expected)49 v.checkCFP(t, i, tt.expectedCFP)50 v.checkSP(t, i, 1)51 }52}53func TestArrayClassSuperclass(t *testing.T) {54 tests := []struct {55 input string56 expected string57 }{58 {`Array.class.name`, "Class"},59 {`Array.superclass.name`, "Object"},60 }61 for i, tt := range tests {62 v := initTestVM()63 evaluated := v.testEval(t, tt.input, getFilename())64 VerifyExpected(t, i, evaluated, tt.expected)65 v.checkCFP(t, i, 0)66 v.checkSP(t, i, 1)67 }68}69func TestArrayEvaluation(t *testing.T) {70 input := `71 [1, "234", true]72 `73 vm := initTestVM()74 evaluated := vm.testEval(t, input, getFilename())75 vm.checkCFP(t, 0, 0)76 arr, ok := evaluated.(*ArrayObject)77 if !ok {78 t.Fatalf("Expect evaluated value to be an array. got=%T", evaluated)79 }80 VerifyExpected(t, 0, arr.Elements[0], 1)81 VerifyExpected(t, 0, arr.Elements[1], "234")82 VerifyExpected(t, 0, arr.Elements[2], true)83}84func TestArrayComparison(t *testing.T) {85 tests := []struct {86 input string87 expected interface{}88 }{89 {`[1, "String", true, 2..5] == 123`, false},90 {`[1, "String", true, 2..5] == "123"`, false},91 {`[1, "String", true, 2..5] == "124"`, false},92 {`[1, "String", true, 2..5] == (1..3)`, false},93 {`[1, "String", true, 2..5] == { a: 1, b: 2 }`, false},94 {`[1, "String", true, 2..5] == [1, "String", true, 2..5]`, true},95 {`[1, "String", true, 2..5] == [1, "String", false, 2..5]`, false},96 {`[1, "String", true, 2..5] == ["String", 1, false, 2..5]`, false}, // Array has order issue97 {`[1, { a: 1, b: 2 }, "Goby" ] == [1, { a: 1, b: 2 }, "Goby"]`, true},98 {`[1, { a: 1, b: 2 }, "Goby" ] == [1, { b: 2, a: 1 }, "Goby"]`, true},99 {`[1, { a: 1, b: 2 }, "Goby" ] == [1, { a: 1, b: 2, c: 3 }, "Goby"]`, false}, // Array of hash has no order issue100 {`[1, { a: 1, b: 2 }, "Goby" ] == [1, { a: 2, b: 2, a: 1 }, "Goby"]`, true}, // Array of hash key will be overwritten if duplicated101 {`[1, "String", true, 2..5] == Integer`, false},102 {`[1, "String", true, 2..5] != 123`, true},103 {`[1, "String", true, 2..5] != "123"`, true},104 {`[1, "String", true, 2..5] != "124"`, true},105 {`[1, "String", true, 2..5] != (1..3)`, true},106 {`[1, "String", true, 2..5] != { a: 1, b: 2 }`, true},107 {`[1, "String", true, 2..5] != [1, "String", true, 2..5]`, false},108 {`[1, "String", true, 2..5] != [1, "String", false, 2..5]`, true},109 {`[1, "String", true, 2..5] != ["String", 1, false, 2..5]`, true}, // Array has order issue110 {`[1, { a: 1, b: 2 }, "Goby" ] != [1, { a: 1, b: 2 }, "Goby"]`, false},111 {`[1, { a: 1, b: 2 }, "Goby" ] != [1, { b: 2, a: 1 }, "Goby"]`, false},112 {`[1, { a: 1, b: 2 }, "Goby" ] != [1, { a: 1, b: 2, c: 3 }, "Goby"]`, true}, // Array of hash has no order issue113 {`[1, { a: 1, b: 2 }, "Goby" ] != [1, { a: 2, b: 2, a: 1 }, "Goby"]`, false}, // Array of hash key will be overwritten if duplicated114 {`[1, "String", true, 2..5] != Integer`, true},115 }116 for i, tt := range tests {117 vm := initTestVM()118 evaluated := vm.testEval(t, tt.input, getFilename())119 VerifyExpected(t, i, evaluated, tt.expected)120 vm.checkCFP(t, i, 0)121 vm.checkSP(t, i, 1)122 }123}124func TestArrayIndex(t *testing.T) {125 tests := []struct {126 input string127 expected interface{}128 }{129 {`130 [][1]131 `, nil},132 {`133 [1, 2, 3][100]134 `, nil},135 {`136 [1, 2, 10, 5][2]137 `, 10},138 {`139 [1, "a", 10, 5][1]140 `, "a"},141 {`142 [1, "a", 10, "b"][-2]143 `, 10},144 {`145 a = [1, "a", 10, 5]146 a[0]147 `, 1},148 {`149 a = [1, "a", 10, 5]150 a[2] = a[1]151 a[2]152 `, "a"},153 {`154 a = [1, "a", 10, 5]155 a[-2] = a[1]156 a[-2]157 `, "a"},158 {`159 a = [1, "a", 10, 5]160 a[-4] = a[1]161 a[-4]162 `, "a"},163 {`164 a = []165 a[10] = 100166 a[10]167 `, 100},168 {`169 a = []170 a[10] = 100171 a[0]172 `, nil},173 {`174 a = [1, 2 ,3 ,5 , 10]175 a[0] = a[1] + a[2] + a[3] * a[4]176 a[0]177 `, 55},178 {`179 code = []180 code[100] = 'Continue'181 code[101] = 'Switching Protocols'182 code[102] = 'Processing'183 code[200] = 'OK'184 code.to_s185 `, `[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "Continue", "Switching Protocols", "Processing", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, "OK"]`},186 }187 for i, tt := range tests {188 v := initTestVM()189 evaluated := v.testEval(t, tt.input, getFilename())190 VerifyExpected(t, i, evaluated, tt.expected)191 v.checkCFP(t, i, 0)192 v.checkSP(t, i, 1)193 }194}195func TestArrayIndexFail(t *testing.T) {196 testsFail := []errorTestCase{197 {`198 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]199 a[-11] = 123200 `, "ArgumentError: Index value -11 too small for array. minimum: -10", 1},201 {`202 [1, "a", 10, "b"][-5]203 `, "ArgumentError: Index value -5 too small for array. minimum: -4", 1},204 }205 for i, tt := range testsFail {206 v := initTestVM()207 evaluated := v.testEval(t, tt.input, getFilename())208 checkErrorMsg(t, i, evaluated, tt.expected)209 v.checkCFP(t, i, tt.expectedCFP)210 v.checkSP(t, i, 1)211 }212}213func TestArrayIndexWithSuccessiveValues(t *testing.T) {214 tests := []struct {215 input string216 expected []interface{}217 }{218 {`219 a = [1, 2, 3, 4, 5]220 a[1, 0]221 `, []interface{}{}},222 {`223 a = [1, 2, 3, 4, 5]224 a[1, 1]225 `, []interface{}{2}},226 {`227 a = [1, 2, 3, 4, 5]228 a[1, 3]229 `, []interface{}{2, 3, 4}},230 {`231 a = [1, 2, 3, 4, 5]232 a[1, 5]233 `, []interface{}{2, 3, 4, 5}},234 {`235 a = [1, 2, 3, 4, 5]236 a[-5, 1]237 `, []interface{}{1}},238 {`239 a = [1, 2, 3, 4, 5]240 a[-5, 5]241 `, []interface{}{1, 2, 3, 4, 5}},242 {`243 a = [1, 2, 3, 4, 5]244 a[1, 10]245 `, []interface{}{2, 3, 4, 5}},246 {`247 a = [1, 2, 3, 4, 5]248 a[3, 1]249 `, []interface{}{4}},250 {`251 a = [1, 2, 3, 4, 5]252 a[3, 2]253 `, []interface{}{4, 5}},254 {`255 a = [1, 2, 3, 4, 5]256 a[3, 3]257 `, []interface{}{4, 5}},258 {`259 a = [1, 2, 3, 4, 5]260 a[4, 4]261 `, []interface{}{5}},262 {`263 a = [1, 2, 3, 4, 5]264 a[5, 5]265 `, []interface{}{}},266 {`267 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]268 a[3, 0]269 `, []interface{}{}},270 {`271 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]272 a[3, 1]273 `, []interface{}{4}},274 {`275 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]276 a[3, 3]277 `, []interface{}{4, 5, 6}},278 {`279 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]280 a[3, 5]281 `, []interface{}{4, 5, 6, 7, 8}},282 {`283 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]284 a[3, 7]285 `, []interface{}{4, 5, 6, 7, 8, 9, 10}},286 {`287 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]288 a[3, 10]289 `, []interface{}{4, 5, 6, 7, 8, 9, 10}},290 {`291 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]292 a[-7, 1]293 `, []interface{}{4}},294 {`295 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]296 a[-7, 3]297 `, []interface{}{4, 5, 6}},298 {`299 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]300 a[-7, 5]301 `, []interface{}{4, 5, 6, 7, 8}},302 {`303 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]304 a[-7, 7]305 `, []interface{}{4, 5, 6, 7, 8, 9, 10}},306 {`307 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]308 a[-7, 10]309 `, []interface{}{4, 5, 6, 7, 8, 9, 10}},310 {`311 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]312 a[2, 3] = [1, 2, 3, 4, 5]313 `, []interface{}{1, 2, 3, 4, 5}},314 {`315 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]316 a[2, 3] = [1, 2, 3, 4, 5]317 a318 `, []interface{}{1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},319 {`320 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]321 a[1, 7] = [1, 2, 3]322 a323 `, []interface{}{1, 1, 2, 3, 9, 10}},324 {`325 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]326 a[-5, 3] = [2, 4, 6, 8, 10]327 a328 `, []interface{}{1, 2, 3, 4, 5, 2, 4, 6, 8, 10, 9, 10}},329 {`330 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]331 a[5, 6] = 123332 a333 `, []interface{}{1, 2, 3, 4, 5, 123}},334 {`335 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]336 a[5, 0] = 123337 a338 `, []interface{}{1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10}},339 {`340 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]341 a[-7, 2] = "@Maxwell-Alexius is solving issue #403"342 a343 `, []interface{}{1, 2, 3, "@Maxwell-Alexius is solving issue #403", 6, 7, 8, 9, 10}},344 {`345 a = [1, 2, 3, 4, 5]346 a[5, 123] = 123347 a348 `, []interface{}{1, 2, 3, 4, 5, 123}},349 {`350 a = [1, 2, 3, 4, 5]351 a[1, 0] = 555352 a353 `, []interface{}{1, 555, 2, 3, 4, 5}},354 {`355 a = [1, 2, 3, 4, 5]356 a[5, 123] = [1, 2, 3]357 a358 `, []interface{}{1, 2, 3, 4, 5, 1, 2, 3}},359 {`360 a = [1, 2, 3, 4, 5]361 a[10, 123] = 123362 a363 `, []interface{}{1, 2, 3, 4, 5, nil, nil, nil, nil, nil, 123}},364 {`365 a = [1, 2, 3, 4, 5]366 a[10, 123] = [1, 2, 3]367 a368 `, []interface{}{1, 2, 3, 4, 5, nil, nil, nil, nil, nil, 1, 2, 3}},369 {`370 a = [1, 2, 3, 4, 5]371 a[10, 123] = "@Maxwell-Alexius is solving issue #403 which have tons of feature"372 a373 `, []interface{}{1, 2, 3, 4, 5, nil, nil, nil, nil, nil, "@Maxwell-Alexius is solving issue #403 which have tons of feature"}},374 }375 for i, tt := range tests {376 vm := initTestVM()377 evaluated := vm.testEval(t, tt.input, getFilename())378 verifyArrayObject(t, i, evaluated, tt.expected)379 vm.checkCFP(t, i, 0)380 vm.checkSP(t, i, 1)381 }382}383func TestArrayIndexWithSuccessiveValuesNullCases(t *testing.T) {384 tests := []struct {385 input string386 expected interface{}387 }{388 {`389 a = [1, 2, 3, 4, 5]390 a[6, 5] # Range exceeded391 `, nil},392 }393 for i, tt := range tests {394 v := initTestVM()395 evaluated := v.testEval(t, tt.input, getFilename())396 VerifyExpected(t, i, evaluated, tt.expected)397 v.checkCFP(t, i, 0)398 v.checkSP(t, i, 1)399 }400}401func TestArrayIndexWithSuccessiveValuesFail(t *testing.T) {402 testsFail := []errorTestCase{403 {`404 a = [1, 2, 3, 4, 5]405 a["1", 5]406 `, "TypeError: Expect argument to be Integer. got: String", 1},407 {`408 a = [1, 2, 3, 4, 5]409 a[1, "5"]410 `, "TypeError: Expect argument to be Integer. got: String", 1},411 {`412 a = [1, 2, 3, 4, 5]413 a[1, 3, 5]414 `, "ArgumentError: Expect 1 to 2 argument(s). got: 3", 1},415 {`416 a = [1, 2, 3, 4, 5]417 a[1, 3, 5, 7, 9]418 `, "ArgumentError: Expect 1 to 2 argument(s). got: 5", 1},419 {`420 a = [1, 2, 3, 4, 5]421 a[]422 `, "ArgumentError: Expect 1 to 2 argument(s). got: 0", 1},423 {`424 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]425 a[1, "5"] = 6426 `, "TypeError: Expect argument to be Integer. got: String", 1},427 {`428 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]429 a[1, "5", 6] = 123430 `, "ArgumentError: Expect 2 to 3 argument(s). got: 4", 1},431 {`432 a = [1, 2, 3, 4, 5]433 a[-6, 5]434 `, "ArgumentError: Index value -6 too small for array. minimum: -5", 1},435 {`436 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]437 a[1, -3] = [1, 2, 3, 4, 5]438 `, "ArgumentError: Expect second argument to be positive value. got: -3", 1},439 {`440 a = [1, 2, 3, 4, 5]441 a[-1, -1] = 555442 `, "ArgumentError: Expect second argument to be positive value. got: -1", 1},443 {`444 a = [1, 2, 3, 4, 5]445 a[6, -1] = 555446 `, "ArgumentError: Expect second argument to be positive value. got: -1", 1},447 {`448 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]449 a[-11, 2] = [1, 2, 3, 4, 5]450 `, "ArgumentError: Index value -11 too small for array. minimum: -10", 1},451 {`452 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]453 a[3, -1]454 `, "ArgumentError: Expect second argument to be positive value. got: -1", 1},455 {`456 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]457 a[-1, -4] # Both negative case458 `, "ArgumentError: Expect second argument to be positive value. got: -4", 1},459 }460 for i, tt := range testsFail {461 v := initTestVM()462 evaluated := v.testEval(t, tt.input, getFilename())463 checkErrorMsg(t, i, evaluated, tt.expected)464 v.checkCFP(t, i, tt.expectedCFP)465 v.checkSP(t, i, 1)466 }467}468func TestArrayAnyMethod(t *testing.T) {469 tests := []struct {470 input string471 expected interface{}472 }{473 {`474 [1, 2, 3].any? do |e|475 e == 2476 end477 `, true},478 {`479 [1, 2, 3].any? do |e|480 e481 end482 `, true},483 {`484 [1, 2, 3].any? do |e|485 e == 5486 end487 `, false},488 {`489 [1, 2, 3].any? do |e|490 nil491 end492 `, false},493 {`494 [].any? do |e|495 true496 end497 `, false},498 // cases for providing an empty block499 {`500 [1, 2, 3].any? do end501 `, false},502 {`503 [1, 2, 3].any? do |i| end504 `, false},505 {`506 [].any? do end507 `, false},508 {`509 [].any? do |i| end510 `, false},511 }512 for i, tt := range tests {513 v := initTestVM()514 evaluated := v.testEval(t, tt.input, getFilename())515 VerifyExpected(t, i, evaluated, tt.expected)516 v.checkCFP(t, i, 0)517 v.checkSP(t, i, 1)518 }519}520func TestArrayAnyMethodFail(t *testing.T) {521 testsFail := []errorTestCase{522 {`[].any?`, "InternalError: Can't yield without a block", 1},523 }524 for i, tt := range testsFail {525 v := initTestVM()526 evaluated := v.testEval(t, tt.input, getFilename())527 checkErrorMsg(t, i, evaluated, tt.expected)528 v.checkCFP(t, i, tt.expectedCFP)529 v.checkSP(t, i, 1)530 }531}532func TestArrayAtMethod(t *testing.T) {533 tests := []struct {534 input string535 expected interface{}536 }{537 {`538 [].at(1)539 `, nil},540 {`541 [1, 2, 10, 5].at(2)542 `, 10},543 {`544 [1, "a", 10, 5].at(1)545 `, "a"},546 {`547 [1, "a", 10, 5].at(4)548 `, nil},549 {`550 [1, "a", 10, 5].at(-2)551 `, 10},552 {`553 a = [1, "a", 10, 5]554 a.at(0)555 `, 1},556 {`557 a = [1, "a", 10, 5]558 a[2] = a.at(1)559 a[2]560 `, "a"},561 {`562 a = [1, 2, 3, 5, 10]563 a[0] = a.at(1) + a.at(2) + a.at(3) * a.at(4)564 a.at(0)565 `, 55},566 }567 for i, tt := range tests {568 v := initTestVM()569 evaluated := v.testEval(t, tt.input, getFilename())570 VerifyExpected(t, i, evaluated, tt.expected)571 v.checkCFP(t, i, 0)572 v.checkSP(t, i, 1)573 }574}575func TestArrayAtMethodFail(t *testing.T) {576 testsFail := []errorTestCase{577 {`[1, 2, 3].at`, "ArgumentError: Expect 1 argument(s). got: 0", 1},578 {`[1, 2, 3].at(2, 3)`, "ArgumentError: Expect 1 argument(s). got: 2", 1},579 {`[1, 2, 3].at(true)`, "TypeError: Expect argument to be Integer. got: Boolean", 1},580 {`[1, 2, 3].at(1..3)`, "TypeError: Expect argument to be Integer. got: Range", 1},581 {`[1, "a", 10, 5].at(-5)`, "ArgumentError: Index value -5 too small for array. minimum: -4", 1},582 }583 for i, tt := range testsFail {584 v := initTestVM()585 evaluated := v.testEval(t, tt.input, getFilename())586 checkErrorMsg(t, i, evaluated, tt.expected)587 v.checkCFP(t, i, tt.expectedCFP)588 v.checkSP(t, i, 1)589 }590}591func TestArrayClearMethod(t *testing.T) {592 tests := []struct {593 input string594 expected []interface{}595 }{596 {`597 a = [1, 2, 3]598 a.clear599 `, []interface{}{}},600 {`601 a = []602 a.clear603 `, []interface{}{}},604 }605 for i, tt := range tests {606 vm := initTestVM()607 evaluated := vm.testEval(t, tt.input, getFilename())608 verifyArrayObject(t, i, evaluated, tt.expected)609 vm.checkCFP(t, i, 0)610 vm.checkSP(t, i, 1)611 }612}613func TestArrayClearMethodFail(t *testing.T) {614 testsFail := []errorTestCase{615 {`['Maxwell', 'Alexius'].clear(123)`, "ArgumentError: Expect 0 argument(s). got: 1", 1},616 {`['Taipei', 101].clear(1, 0, 1)`, "ArgumentError: Expect 0 argument(s). got: 3", 1},617 }618 for i, tt := range testsFail {619 v := initTestVM()620 evaluated := v.testEval(t, tt.input, getFilename())621 checkErrorMsg(t, i, evaluated, tt.expected)622 v.checkCFP(t, i, tt.expectedCFP)623 v.checkSP(t, i, 1)624 }625}626func TestArrayConcatMethod(t *testing.T) {627 tests := []struct {628 input string629 expected []interface{}630 }{631 {`632 a = [1, 2]633 a.concat([3], [4])634 `, []interface{}{1, 2, 3, 4}},635 {`636 a = []637 a.concat([1], [2], ["a", "b"], [3], [4])638 `, []interface{}{1, 2, "a", "b", 3, 4}},639 {`640 a = [1, 2]641 a.concat()642 `, []interface{}{1, 2}},643 }644 for i, tt := range tests {645 vm := initTestVM()646 evaluated := vm.testEval(t, tt.input, getFilename())647 verifyArrayObject(t, i, evaluated, tt.expected)648 vm.checkCFP(t, i, 0)649 vm.checkSP(t, i, 1)650 }651}652func TestArrayConcatMethodFail(t *testing.T) {653 testsFail := []errorTestCase{654 {`a = [1, 2]655 a.concat(3)656 `, "TypeError: Expect argument to be Array. got: Integer", 1},657 {`a = []658 a.concat("a")659 `, "TypeError: Expect argument to be Array. got: String", 1},660 }661 for i, tt := range testsFail {662 v := initTestVM()663 evaluated := v.testEval(t, tt.input, getFilename())664 checkErrorMsg(t, i, evaluated, tt.expected)665 v.checkCFP(t, i, tt.expectedCFP)666 v.checkSP(t, i, 1)667 }668}669func TestArrayCountMethod(t *testing.T) {670 tests := []struct {671 input string672 expected int673 }{674 {`675 a = [1, 2]676 a.count677 `, 2},678 {`679 a = [1, 2]680 a.count(1)681 `, 1},682 {`683 a = ["a", "bb", "c", "db", "bb", 2]684 a.count("bb")685 `, 2},686 {`687 a = [true, true, true, false, true]688 a.count(true)689 `, 4},690 {`691 a = []692 a.count(true)693 `, 0},694 {`695 a = [1, 2, 3, 4, 5, 6, 7, 8]696 a.count do |i|697 i > 3698 end699 `, 5},700 {`701 a = ["a", "bb", "c", "db", "bb"]702 a.count do |i|703 i.size > 1704 end705 `, 3},706 {`707 [].count do |i|708 i.size > 1709 end710 `, 0},711 // cases for providing an empty block712 {`713 ["a", "bb", "c", "db", "bb"].count do714 end715 `, 0},716 {`717 ["a", "bb", "c", "db", "bb"].count do |i|718 end719 `, 0},720 {`721 [].count do722 end723 `, 0},724 {`725 [].count do |i|726 end727 `, 0},728 }729 for i, tt := range tests {730 v := initTestVM()731 evaluated := v.testEval(t, tt.input, getFilename())732 VerifyExpected(t, i, evaluated, tt.expected)733 v.checkCFP(t, i, 0)734 v.checkSP(t, i, 1)735 }736}737func TestArrayCountMethodFail(t *testing.T) {738 testsFail := []errorTestCase{739 {740 `a = [1, 2]741 a.count(3, 3)742 `, "ArgumentError: Expect 1 or less argument(s). got: 2", 1},743 }744 for i, tt := range testsFail {745 v := initTestVM()746 evaluated := v.testEval(t, tt.input, getFilename())747 checkErrorMsg(t, i, evaluated, tt.expected)748 v.checkCFP(t, i, tt.expectedCFP)749 v.checkSP(t, i, 1)750 }751}752func TestArrayDeleteAtMethod(t *testing.T) {753 tests := []struct {754 input string755 expected interface{}756 }{757 {`758 [].delete_at(1)759 `, nil},760 {`761 [1, 2, 10, 5].delete_at(2)762 `, 10},763 {`764 [1, "a", 10, 5].delete_at(1)765 `, "a"},766 {`767 [1, "a", 10, 5].delete_at(4)768 `, nil},769 {`770 [1, "a", 10, 5].delete_at(-2)771 `, 10},772 {`773 [1, "a", 10, 5].delete_at(-5)774 `, nil},775 }776 for i, tt := range tests {777 v := initTestVM()778 evaluated := v.testEval(t, tt.input, getFilename())779 VerifyExpected(t, i, evaluated, tt.expected)780 v.checkCFP(t, i, 0)781 v.checkSP(t, i, 1)782 }783 testsArray := []struct {784 input string785 expected []interface{}786 }{787 {`788 a = [1, 2, 10, 5]789 a.delete_at(2)790 a791 `, []interface{}{1, 2, 5}},792 {`793 a = [1, "a", 10, 5]794 a.delete_at(4)795 a796 `, []interface{}{1, "a", 10, 5}},797 {`798 a = [1, "a", 10, 5]799 a.delete_at(-2)800 a801 `, []interface{}{1, "a", 5}},802 {`803 a = [1, "a", 10, 5]804 a.delete_at(-5)805 a806 `, []interface{}{1, "a", 10, 5}},807 }808 for i, tt := range testsArray {809 vm := initTestVM()810 evaluated := vm.testEval(t, tt.input, getFilename())811 verifyArrayObject(t, i, evaluated, tt.expected)812 vm.checkCFP(t, i, 0)813 vm.checkSP(t, i, 1)814 }815}816func TestArrayDeleteAtMethodFail(t *testing.T) {817 testsFail := []errorTestCase{818 {`[1, 2, 3].delete_at`, "ArgumentError: Expect 1 argument(s). got: 0", 1},819 {`[1, 2, 3].delete_at(2, 3)`, "ArgumentError: Expect 1 argument(s). got: 2", 1},820 {`[1, 2, 3].delete_at(true)`, "TypeError: Expect argument to be Integer. got: Boolean", 1},821 {`[1, 2, 3].delete_at(1..3)`, "TypeError: Expect argument to be Integer. got: Range", 1},822 }823 for i, tt := range testsFail {824 v := initTestVM()825 evaluated := v.testEval(t, tt.input, getFilename())826 checkErrorMsg(t, i, evaluated, tt.expected)827 v.checkCFP(t, i, tt.expectedCFP)828 v.checkSP(t, i, 1)829 }830}831func TestArrayDigMethod(t *testing.T) {832 tests := []struct {833 input string834 expected interface{}835 }{836 {`837 [1 , 2].dig(-2)838 `, 1},839 {`840 [{a: 3} , 2].dig(0, :a)841 `, 3},842 {`843 [[], 2].dig(0, 1)844 `, nil},845 {`846 [[], 2].dig(0, 1, 2)847 `, nil},848 {`[[1, 2, [3, [8, [9]]]], 4, 5].dig(0, 2, 1, 1, 0)`, 9},849 }850 for i, tt := range tests {851 v := initTestVM()852 evaluated := v.testEval(t, tt.input, getFilename())853 VerifyExpected(t, i, evaluated, tt.expected)854 v.checkCFP(t, i, 0)855 v.checkSP(t, i, 1)856 }857}858func TestArrayDigMethodFail(t *testing.T) {859 testsFail := []errorTestCase{860 {`[1, 2].dig`, "ArgumentError: Expect 1 or more argument(s). got: 0", 1},861 {`[1, 2].dig(0, 1)`, "TypeError: Expect target to be Diggable, got Integer", 1},862 }863 for i, tt := range testsFail {864 v := initTestVM()865 evaluated := v.testEval(t, tt.input, getFilename())866 checkErrorMsg(t, i, evaluated, tt.expected)867 v.checkCFP(t, i, tt.expectedCFP)868 v.checkSP(t, i, 1)869 }870}871func TestArrayEachMethod(t *testing.T) {872 tests := []struct {873 input string874 expected int875 }{876 {`877 sum = 0878 [1, 2, 3, 4, 5].each do |i|879 sum = sum + i880 end881 sum882 `, 15},883 {`884 sum = 0885 [].each do |i|886 sum += i887 end888 sum889 `, 0},890 // cases for providing an empty block891 {`892 a = [1,2,3].each do893 end894 a[2]895 `, 3},896 {`897 a = [1,2,3].each do |i|898 end899 a[2]900 `, 3},901 {`902 a = [].each do903 end904 a.length905 `, 0},906 {`907 a = [].each do |i|908 end909 a.length910 `, 0},911 }912 for i, tt := range tests {913 v := initTestVM()914 evaluated := v.testEval(t, tt.input, getFilename())915 VerifyExpected(t, i, evaluated, tt.expected)916 v.checkCFP(t, i, 0)917 v.checkSP(t, i, 1)918 }919}920func TestArrayEachMethodFail(t *testing.T) {921 testsFail := []errorTestCase{922 {`['M', 'A', 'X', 'W', 'E', 'L', 'L'].each`, "InternalError: Can't yield without a block", 1},923 {`924 ['T', 'A', 'I', 'P', 'E', 'I'].each(101) do |char|925 puts char926 end927 `, "ArgumentError: Expect 0 argument(s). got: 1", 1},928 }929 for i, tt := range testsFail {930 v := initTestVM()931 evaluated := v.testEval(t, tt.input, getFilename())932 checkErrorMsg(t, i, evaluated, tt.expected)933 v.checkCFP(t, i, tt.expectedCFP)934 v.checkSP(t, i, 1)935 }936}937func TestArrayEachIndexMethod(t *testing.T) {938 tests := []struct {939 input string940 expected int941 }{942 {`943 sum = 0944 [2, 3, 40, 5, 22].each_index do |i|945 sum = sum + i946 end947 sum948 `, 10},949 {`950 sum = 0951 [].each_index do |i|952 sum += i953 end954 sum955 `, 0},956 // cases for providing an empty block957 {`958 a = [1,2,3].each_index do959 end960 a[2]961 `, 3},962 {`963 a = [1,2,3].each_index do |i|964 end965 a[2]966 `, 3},967 {`968 a = [].each_index do969 end970 a.length971 `, 0},972 {`973 a = [].each_index do |i|974 end975 a.length976 `, 0},977 }978 for i, tt := range tests {979 v := initTestVM()980 evaluated := v.testEval(t, tt.input, getFilename())981 VerifyExpected(t, i, evaluated, tt.expected)982 v.checkCFP(t, i, 0)983 v.checkSP(t, i, 1)984 }985}986func TestArrayEachIndexMethodFail(t *testing.T) {987 testsFail := []errorTestCase{988 {`['M', 'A', 'X', 'W', 'E', 'L', 'L'].each_index`, "InternalError: Can't yield without a block", 1},989 {`990 ['T', 'A', 'I', 'P', 'E', 'I'].each_index(101) do |char|991 puts char992 end993 `, "ArgumentError: Expect 0 argument(s). got: 1", 1},994 }995 for i, tt := range testsFail {996 v := initTestVM()997 evaluated := v.testEval(t, tt.input, getFilename())998 checkErrorMsg(t, i, evaluated, tt.expected)999 v.checkCFP(t, i, tt.expectedCFP)1000 v.checkSP(t, i, 1)1001 }1002}1003func TestArrayEmptyMethod(t *testing.T) {1004 tests := []struct {1005 input string1006 expected bool1007 }{1008 {1009 `1010 [1, 2, 3].empty?1011 `, false},1012 {1013 `1014 [nil].empty?1015 `, false},1016 {1017 `1018 [].empty?1019 `, true},1020 {1021 `1022 a = [[]]1023 a.empty?1024 `, false},1025 }1026 for i, tt := range tests {1027 v := initTestVM()1028 evaluated := v.testEval(t, tt.input, getFilename())1029 VerifyExpected(t, i, evaluated, tt.expected)1030 v.checkCFP(t, i, 0)1031 v.checkSP(t, i, 1)1032 }1033}1034func TestArrayEmptyMethodFail(t *testing.T) {1035 testsFail := []errorTestCase{1036 {`[1, 2, 3].empty?(123)`, "ArgumentError: Expect 0 argument(s). got: 1", 1},1037 {`['T', 'A', 'I', 'P', 'E', 'I'].empty?(1, 0, 1)`, "ArgumentError: Expect 0 argument(s). got: 3", 1},1038 }1039 for i, tt := range testsFail {1040 v := initTestVM()1041 evaluated := v.testEval(t, tt.input, getFilename())1042 checkErrorMsg(t, i, evaluated, tt.expected)1043 v.checkCFP(t, i, tt.expectedCFP)1044 v.checkSP(t, i, 1)1045 }1046}1047func TestArrayFirstMethod(t *testing.T) {1048 testsInt := []struct {1049 input string1050 expected interface{}1051 }{1052 {`1053 a = [1, 2]1054 a.first1055 `, 1},1056 {`1057[:apple, :orange, :grape, :melon].first`,1058 "apple",1059 },1060 }1061 for i, tt := range testsInt {1062 v := initTestVM()1063 evaluated := v.testEval(t, tt.input, getFilename())1064 VerifyExpected(t, i, evaluated, tt.expected)1065 v.checkCFP(t, i, 0)1066 }1067 testsArray := []struct {1068 input string1069 expected []interface{}1070 }{1071 {`1072 a = [3, 4, 5, 1, 6]1073 a.first(2)1074 `, []interface{}{3, 4}},1075 {`1076 a = ["a", "b", "d", "q"]1077 a.first(2)1078 `, []interface{}{"a", "b"}},1079 {`1080 a = ["M", "A", "X", "W", "E", "L", "L"]1081 a.first(7)`, []interface{}{"M", "A", "X", "W", "E", "L", "L"}},1082 {`1083 a = ["M", "A", "X", "W", "E", "L", "L"]1084 a.first(11)`, []interface{}{"M", "A", "X", "W", "E", "L", "L"}},1085 }1086 for i, tt := range testsArray {1087 v := initTestVM()1088 evaluated := v.testEval(t, tt.input, getFilename())1089 verifyArrayObject(t, i, evaluated, tt.expected)1090 v.checkCFP(t, i, 0)1091 v.checkSP(t, i, 1)1092 }1093}1094func TestArrayFirstMethodNullCases(t *testing.T) {1095 tests := []struct {1096 input string1097 expected interface{}1098 }{1099 {`1100 a = []1101 a.first # Empty Array Case1102 `, nil},1103 }1104 for i, tt := range tests {1105 v := initTestVM()1106 evaluated := v.testEval(t, tt.input, getFilename())1107 VerifyExpected(t, i, evaluated, tt.expected)1108 v.checkCFP(t, i, 0)1109 v.checkSP(t, i, 1)1110 }1111}1112func TestArrayFirstMethodFail(t *testing.T) {1113 testsFail := []errorTestCase{1114 {`a = [1, 2]1115 a.first("a")1116 `, "TypeError: Expect argument to be Integer. got: String", 1},1117 {`a = [1, 2]1118 a.first(1, 2, 3)1119 `, "ArgumentError: Expect 1 or less argument(s). got: 3", 1},1120 {`a = [1, 2]1121 a.first(-1)1122 `, "ArgumentError: Expect argument to be positive value. got: -1", 1},1123 }1124 for i, tt := range testsFail {1125 v := initTestVM()1126 evaluated := v.testEval(t, tt.input, getFilename())1127 checkErrorMsg(t, i, evaluated, tt.expected)1128 v.checkCFP(t, i, tt.expectedCFP)1129 v.checkSP(t, i, 1)1130 }1131}1132func TestArrayFlattenMethod(t *testing.T) {1133 testsArray := []struct {1134 input string1135 expected []interface{}1136 }{1137 {`1138 [1, 2].flatten1139 `, []interface{}{1, 2}},1140 {`1141 [1, 2, [3, 4, 5]].flatten1142 `, []interface{}{1, 2, 3, 4, 5}},1143 {`1144 [[1, 2], [3, 4], [5, 6]].flatten1145 `, []interface{}{1, 2, 3, 4, 5, 6}},1146 {`1147 [[[1, 2], [[[3, 4]], [5, 6]]]].flatten1148 `, []interface{}{1, 2, 3, 4, 5, 6}},1149 }1150 for i, tt := range testsArray {1151 vm := initTestVM()1152 evaluated := vm.testEval(t, tt.input, getFilename())1153 verifyArrayObject(t, i, evaluated, tt.expected)1154 vm.checkCFP(t, i, 0)1155 vm.checkSP(t, i, 1)1156 }1157}1158func TestArrayFlattenMethodFail(t *testing.T) {1159 testsFail := []errorTestCase{1160 {`a = [1, 2]1161 a.flatten(1)1162 `, "ArgumentError: Expect 0 argument(s). got: 1", 1},1163 }1164 for i, tt := range testsFail {1165 v := initTestVM()1166 evaluated := v.testEval(t, tt.input, getFilename())1167 checkErrorMsg(t, i, evaluated, tt.expected)1168 v.checkCFP(t, i, tt.expectedCFP)1169 v.checkSP(t, i, 1)1170 }1171}1172func TestArrayIndexWithMethod(t *testing.T) {1173 tests := []struct {1174 input string1175 expected map[string]interface{}1176 }{1177 {`1178 [:a, :b, :c, :d].index_with do |i| i * 3 end1179 `, map[string]interface{}{"a": "aaa", "b": "bbb", "c": "ccc", "d": "ddd"}},1180 {`1181 [:a, :b, :c, :d].index_with(:nothing) do |i|1182 if i == :c1183 i * 31184 end1185 end1186 `, map[string]interface{}{"a": "nothing", "b": "nothing", "c": "ccc", "d": "nothing"}},1187 }1188 for i, tt := range tests {1189 vm := initTestVM()1190 evaluated := vm.testEval(t, tt.input, getFilename())1191 verifyHashObject(t, i, evaluated, tt.expected)1192 vm.checkCFP(t, i, 0)1193 vm.checkSP(t, i, 1)1194 }1195}1196func TestArrayIncludeMethod(t *testing.T) {1197 tests := []struct {1198 input string1199 expected bool1200 }{1201 {`a = ["a", "b", "c"]1202 a.include?("b")1203 `, true},1204 {`a = ["a", "b", "c"]1205 a.include?("d")1206 `, false},1207 }1208 for i, tt := range tests {1209 v := initTestVM()1210 evaluated := v.testEval(t, tt.input, getFilename())1211 VerifyExpected(t, i, evaluated, tt.expected)1212 v.checkCFP(t, i, 0)1213 v.checkSP(t, i, 1)1214 }1215}1216func TestArrayJoinMethod(t *testing.T) {1217 testsInt := []struct {1218 input string1219 expected string1220 }{1221 {`1222 [1, 2].join1223 `, "12"},1224 {`1225 ["1", 2].join1226 `, "12"},1227 {`1228 [1, 2].join(",")1229 `, "1,2"},1230 {`1231 [1, 2, [3, 4]].join(",")1232 `, "1,2,3,4"},1233 {`[[:h, :e, :l], [[:l], :o]].join`, "hello"},1234 {`[[:hello],{k: :v}].join `, `hello{ k: "v" }`},1235 }1236 for i, tt := range testsInt {1237 v := initTestVM()1238 evaluated := v.testEval(t, tt.input, getFilename())1239 VerifyExpected(t, i, evaluated, tt.expected)1240 v.checkCFP(t, i, 0)1241 v.checkSP(t, i, 1)1242 }1243}1244func TestArrayJoinMethodFail(t *testing.T) {1245 testsFail := []errorTestCase{1246 {`a = [1, 2]1247 a.join(",", "-")1248 `, "ArgumentError: Expect 0 to 1 argument(s). got: 2", 1},1249 {`a = [1, 2]1250 a.join(1)1251 `, "TypeError: Expect argument to be String. got: Integer", 1},1252 }1253 for i, tt := range testsFail {1254 v := initTestVM()1255 evaluated := v.testEval(t, tt.input, getFilename())1256 checkErrorMsg(t, i, evaluated, tt.expected)1257 v.checkCFP(t, i, tt.expectedCFP)1258 v.checkSP(t, i, 1)1259 }1260}1261func TestArrayLastMethod(t *testing.T) {1262 testsArray := []struct {1263 input string1264 expected interface{}1265 }{1266 {`1267 a = []1268 a.last1269 `, nil},1270 {`1271 a = [2, 9, 7, 1, 8]1272 a.last1273 `, 8},1274 {`1275 a = [2, 9, 7, 1, 8]1276 a.last(1)1277 `, []interface{}{8}},1278 {`1279 a = [3, 4, 5, 1, 6]1280 a.last(3)1281 `, []interface{}{5, 1, 6}},1282 {`1283 a = ["a", "b", "d", "q"]1284 a.last(2)1285 `, []interface{}{"d", "q"}},1286 {`1287 a = ["M", "A", "X", "W", "E", "L", "L"]1288 a.last(7)1289 `, []interface{}{"M", "A", "X", "W", "E", "L", "L"}},1290 {`1291 a = ["M", "A", "X", "W", "E", "L", "L"]1292 a.last(10)1293 `, []interface{}{"M", "A", "X", "W", "E", "L", "L"}},1294 }1295 for i, tt := range testsArray {1296 vm := initTestVM()1297 evaluated := vm.testEval(t, tt.input, getFilename())1298 VerifyExpected(t, i, evaluated, tt.expected)1299 vm.checkCFP(t, i, 0)1300 vm.checkSP(t, i, 1)1301 }1302}1303func TestArrayLastMethodFail(t *testing.T) {1304 testsFail := []errorTestCase{1305 {`a = [1, 2]1306 a.last("l")1307 `, "TypeError: Expect argument to be Integer. got: String", 1},1308 {`a = [1, 2]1309 a.last(1, 2, 3)1310 `, "ArgumentError: Expect 1 or less argument(s). got: 3", 1},1311 {`a = [1, 2]1312 a.last(-1)1313 `, "ArgumentError: Expect argument to be positive value. got: -1", 1},1314 }1315 for i, tt := range testsFail {1316 v := initTestVM()1317 evaluated := v.testEval(t, tt.input, getFilename())1318 checkErrorMsg(t, i, evaluated, tt.expected)1319 v.checkCFP(t, i, tt.expectedCFP)1320 v.checkSP(t, i, 1)1321 }1322}1323func TestArrayLengthMethod(t *testing.T) {1324 tests := []struct {1325 input string1326 expected int1327 }{1328 {1329 `1330 [1, 2, 3].length1331 `, 3},1332 {1333 `1334 [nil].length1335 `, 1},1336 {1337 `1338 [].length1339 `, 0},1340 {1341 `1342 a = [-10, "123", [1,2,3], 1, 2, 3]1343 a.length1344 `, 6},1345 }1346 for i, tt := range tests {1347 v := initTestVM()1348 evaluated := v.testEval(t, tt.input, getFilename())1349 VerifyExpected(t, i, evaluated, tt.expected)1350 v.checkCFP(t, i, 0)1351 v.checkSP(t, i, 1)1352 }1353}1354func TestArrayLengthMethodFail(t *testing.T) {1355 testsFail := []errorTestCase{1356 {`[1, 2, 3].length(10)`, "ArgumentError: Expect 0 argument(s). got: 1", 1},1357 }1358 for i, tt := range testsFail {1359 v := initTestVM()1360 evaluated := v.testEval(t, tt.input, getFilename())1361 checkErrorMsg(t, i, evaluated, tt.expected)1362 v.checkCFP(t, i, tt.expectedCFP)1363 v.checkSP(t, i, 1)1364 }1365}1366func TestArrayMapMethod(t *testing.T) {1367 tests := []struct {1368 input string1369 expected []interface{}1370 }{1371 {`1372 a = [1, 2, 7]1373 a.map do |i|1374 i + 31375 end1376 `, []interface{}{4, 5, 10}},1377 {`1378 a = [true, false, true, false, true ]1379 a.map do |i|1380 !i1381 end1382 `, []interface{}{false, true, false, true, false}},1383 {`1384 a = ["1", "sss", "qwe"]1385 a.map do |i|1386 i + "1"1387 end1388 `, []interface{}{"11", "sss1", "qwe1"}},1389 {`1390 [].map do |i|1391 end1392 `, []interface{}{}},1393 // cases for providing an empty block1394 {`1395 [1, 2, 3, 4, 5].map do1396 end1397 `, []interface{}{nil, nil, nil, nil, nil}},1398 {`1399 [1, 2, 3, 4, 5].map do |i|1400 end1401 `, []interface{}{nil, nil, nil, nil, nil}},1402 {`1403 [].map do1404 end1405 `, []interface{}{}},1406 {`1407 [].map do |i|1408 end1409 `, []interface{}{}},1410 {`1411 a = [:apple, :orange, :lemon, :grape].map do |i|1412 i + "s"1413 end`, []interface{}{"apples", "oranges", "lemons", "grapes"}},1414 }1415 for i, tt := range tests {1416 v := initTestVM()1417 evaluated := v.testEval(t, tt.input, getFilename())1418 verifyArrayObject(t, i, evaluated, tt.expected)1419 v.checkCFP(t, i, 0)1420 v.checkSP(t, i, 1)1421 }1422}1423func TestArrayPlusOperator(t *testing.T) {1424 tests := []struct {1425 input string1426 expected []interface{}1427 }{1428 // Make sure the result is an entirely new array.1429 {`1430 a = [1, 2]1431 b = [3, 4]1432 c = a + b1433 a[0] = -11434 b[0] = -11435 c1436 `, []interface{}{1, 2, 3, 4}},1437 {`1438 a = []1439 b = []1440 a + b1441 `, []interface{}{}},1442 }1443 for i, tt := range tests {1444 vm := initTestVM()1445 evaluated := vm.testEval(t, tt.input, getFilename())1446 verifyArrayObject(t, i, evaluated, tt.expected)1447 vm.checkCFP(t, i, 0)1448 vm.checkSP(t, i, 1)1449 }1450}1451func TestArrayPlusOperatorFail(t *testing.T) {1452 testsFail := []errorTestCase{1453 {`[1, 2] + true`, "TypeError: Expect argument to be Array. got: Boolean", 1},1454 }1455 for i, tt := range testsFail {1456 v := initTestVM()1457 evaluated := v.testEval(t, tt.input, getFilename())1458 checkErrorMsg(t, i, evaluated, tt.expected)1459 v.checkCFP(t, i, tt.expectedCFP)1460 v.checkSP(t, i, 1)1461 }1462}1463func TestArrayPopMethod(t *testing.T) {1464 tests := []struct {1465 input string1466 expected interface{}1467 }{1468 {1469 `1470 a = [1, 2, 3].pop1471 a1472 `, 3},1473 {1474 `1475 a = [1, 2, 3]1476 a.pop1477 a.length1478 `, 2},1479 {1480 `1481 [].pop1482 `, nil},1483 }1484 for i, tt := range tests {1485 v := initTestVM()1486 evaluated := v.testEval(t, tt.input, getFilename())1487 VerifyExpected(t, i, evaluated, tt.expected)1488 v.checkCFP(t, i, 0)1489 v.checkSP(t, i, 1)1490 }1491}1492func TestArrayPopMethodFail(t *testing.T) {1493 testsFail := []errorTestCase{1494 {`[1, 2, 3, 4, 5].pop(123)`, "ArgumentError: Expect 0 argument(s). got: 1", 1},1495 {`[1, 2, 3, 4, 5].pop("Hello", "World")`, "ArgumentError: Expect 0 argument(s). got: 2", 1},1496 }1497 for i, tt := range testsFail {1498 v := initTestVM()1499 evaluated := v.testEval(t, tt.input, getFilename())1500 checkErrorMsg(t, i, evaluated, tt.expected)1501 v.checkCFP(t, i, tt.expectedCFP)1502 v.checkSP(t, i, 1)1503 }1504}1505func TestArrayPushMethod(t *testing.T) {1506 tests := []struct {1507 input string1508 expected interface{}1509 }{1510 {1511 `1512 a = [1, 2, 3]1513 a.push("test")1514 a[3]1515 `, "test"},1516 {1517 `1518 a = [1, 2, 3]1519 a.push("test")1520 a.length1521 `, 4},1522 {1523 `1524 a = []1525 a.push(nil)1526 a[0]1527 `, nil},1528 {1529 `1530 a = []1531 a.push("foo")1532 a.push(1)1533 a.push(234)1534 a[0]1535 `, "foo"},1536 {`1537 [1, 2, 3, 4].push(5, 6, 7).to_s1538 `, "[1, 2, 3, 4, 5, 6, 7]"},1539 {`1540 [].push(nil, "", '').to_s1541 `, `[nil, "", ""]`},1542 }1543 for i, tt := range tests {1544 v := initTestVM()1545 evaluated := v.testEval(t, tt.input, getFilename())1546 VerifyExpected(t, i, evaluated, tt.expected)1547 v.checkCFP(t, i, 0)1548 v.checkSP(t, i, 1)1549 }1550}1551func TestArrayReduceMethod(t *testing.T) {1552 tests := []struct {1553 input string1554 expected interface{}1555 }{1556 {`1557 a = [1, 2, 7]1558 a.reduce do |sum, n|1559 sum + n1560 end1561 `, 10},1562 {`1563 a = [1, 2, 7]1564 a.reduce(10) do |sum, n|1565 sum + n1566 end1567 `, 20},1568 {`1569 a = ["This ", "is a ", "test!"]1570 a.reduce do |prev, s|1571 prev + s1572 end1573 `, "This is a test!"},1574 {`1575 a = ["this ", "is a ", "test!"]1576 a.reduce("Yes, ") do |prev, s|1577 prev + s1578 end1579 `, "Yes, this is a test!"},1580 {`1581 [].reduce("foo") do |i|1582 true1583 end1584 `, "foo"},1585 // cases for providing an empty block1586 {`1587 a = [1, 2, 3].reduce() do; end1588 a.nil?1589 `, true},1590 {`1591 a = [1, 2, 3].reduce("foo") do; end1592 a.nil?1593 `, true},1594 {`1595 a = [1, 2, 3].reduce() do |i|; end1596 a.nil?1597 `, true},1598 {`1599 a = [1, 2, 3].reduce("foo") do |i|; end1600 a.nil?1601 `, true},1602 {`1603 a = [].reduce() do; end1604 a.nil?1605 `, true},1606 {`1607 a = [].reduce("foo") do; end1608 a.nil?1609 `, true},1610 {`1611 a = [].reduce() do |i|; end1612 a.nil?1613 `, true},1614 {`1615 a = [].reduce("foo") do |i|; end1616 a.nil?1617 `, true},1618 }1619 for i, tt := range tests {1620 v := initTestVM()1621 evaluated := v.testEval(t, tt.input, getFilename())1622 VerifyExpected(t, i, evaluated, tt.expected)1623 v.checkCFP(t, i, 0)1624 v.checkSP(t, i, 1)1625 }1626}1627func TestArrayReduceMethodFail(t *testing.T) {1628 testsFail := []errorTestCase{1629 {`a = [1, 2]1630 a.reduce(1)1631 `, "InternalError: Can't yield without a block", 1},1632 {`a = [1, 2]1633 a.reduce(1, 2) do |prev, n|1634 prev + n1635 end1636 `, "ArgumentError: Expect 1 or less argument(s). got: 2", 1},1637 }1638 for i, tt := range testsFail {1639 v := initTestVM()1640 evaluated := v.testEval(t, tt.input, getFilename())1641 checkErrorMsg(t, i, evaluated, tt.expected)1642 v.checkCFP(t, i, tt.expectedCFP)1643 v.checkSP(t, i, 1)1644 }1645}1646func TestArrayReverseMethod(t *testing.T) {1647 tests := []struct {1648 input string1649 expected []interface{}1650 }{1651 {`1652 a = [1, 2, 3]1653 a.reverse1654 `, []interface{}{3, 2, 1}},1655 {`1656 a = []1657 a.reverse1658 `, []interface{}{}},1659 }1660 for i, tt := range tests {1661 v := initTestVM()1662 evaluated := v.testEval(t, tt.input, getFilename())1663 verifyArrayObject(t, i, evaluated, tt.expected)1664 v.checkCFP(t, i, 0)1665 v.checkSP(t, i, 1)1666 }1667}1668func TestArrayReverseMethodFail(t *testing.T) {1669 testsFail := []errorTestCase{1670 {`[1, 2, 3, 4, 5].reverse(123)`, "ArgumentError: Expect 0 argument(s). got: 1", 1},1671 {`[1, 2, 3, 4, 5].reverse("Hello", "World")`, "ArgumentError: Expect 0 argument(s). got: 2", 1},1672 }1673 for i, tt := range testsFail {1674 v := initTestVM()1675 evaluated := v.testEval(t, tt.input, getFilename())1676 checkErrorMsg(t, i, evaluated, tt.expected)1677 v.checkCFP(t, i, tt.expectedCFP)1678 v.checkSP(t, i, 1)1679 }1680}1681func TestArrayReverseEachMethod(t *testing.T) {1682 tests := []struct {1683 input string1684 expected string1685 }{1686 {`1687 str = ""1688 ["a", "b", "c"].reverse_each do |char|1689 str += char1690 end1691 str1692 `, "cba"},1693 {`1694 str = ""1695 [].reverse_each do |i|1696 str += char1697 end1698 str1699 `, ""},1700 // cases for providing an empty block1701 {`1702 a = ["a", "b", "c"].reverse_each do; end1703 a.to_s1704 `, `["a", "b", "c"]`},1705 {`1706 a = ["a", "b", "c"].reverse_each do |i|; end1707 a.to_s1708 `, `["a", "b", "c"]`},1709 {`1710 a = [].reverse_each do; end1711 a.to_s1712 `, `[]`},1713 {`1714 a = [].reverse_each do |i|; end1715 a.to_s1716 `, `[]`},1717 }1718 for i, tt := range tests {1719 v := initTestVM()1720 evaluated := v.testEval(t, tt.input, getFilename())1721 VerifyExpected(t, i, evaluated, tt.expected)1722 v.checkCFP(t, i, 0)1723 v.checkSP(t, i, 1)1724 }1725}1726func TestArrayReverseEachMethodFail(t *testing.T) {1727 testsFail := []errorTestCase{1728 {`['M', 'A'].reverse_each`, "InternalError: Can't yield without a block", 1},1729 {`1730 ['T', 'A'].reverse_each(101) do |char|1731 puts char1732 end1733 `, "ArgumentError: Expect 0 argument(s). got: 1", 1},1734 }1735 for i, tt := range testsFail {1736 v := initTestVM()1737 evaluated := v.testEval(t, tt.input, getFilename())1738 checkErrorMsg(t, i, evaluated, tt.expected)1739 v.checkCFP(t, i, tt.expectedCFP)1740 v.checkSP(t, i, 1)1741 }1742}1743func TestArrayRotateMethod(t *testing.T) {1744 tests := []struct {1745 input string1746 expected []interface{}1747 }{1748 {`1749 a = [1, 2, 3, 4]1750 a.rotate1751 `, []interface{}{2, 3, 4, 1}},1752 {`1753 a = [1, 2, 3, 4]1754 a.rotate(2)1755 `, []interface{}{3, 4, 1, 2}},1756 {`1757 a = [1, 2, 3, 4]1758 a.rotate(0)1759 `, []interface{}{1, 2, 3, 4}},1760 {`1761 a = [1, 2, 3, 4]1762 a.rotate(-1)1763 `, []interface{}{4, 1, 2, 3}},1764 }1765 for i, tt := range tests {1766 v := initTestVM()1767 evaluated := v.testEval(t, tt.input, getFilename())1768 verifyArrayObject(t, i, evaluated, tt.expected)1769 v.checkCFP(t, i, 0)1770 v.checkSP(t, i, 1)1771 }1772}1773func TestArrayRotateMethodFail(t *testing.T) {1774 testsFail := []errorTestCase{1775 {`a = [1, 2]1776 a.rotate("a")1777 `, "TypeError: Expect argument to be Integer. got: String", 1},1778 {`a = [1, 2]1779 a.rotate(1, 2, 3)`, "ArgumentError: Expect 1 or less argument(s). got: 3", 1},1780 }1781 for i, tt := range testsFail {1782 v := initTestVM()1783 evaluated := v.testEval(t, tt.input, getFilename())1784 checkErrorMsg(t, i, evaluated, tt.expected)1785 v.checkCFP(t, i, tt.expectedCFP)1786 v.checkSP(t, i, 1)1787 }1788}1789func TestArraySelectMethod(t *testing.T) {1790 tests := []struct {1791 input string1792 expected []interface{}1793 }{1794 {`1795 a = [1, 2, 3, 4, 5]1796 a.select do |i|1797 i > 31798 end1799 `, []interface{}{4, 5}},1800 {`1801 a = [true, false, true, false, true ]1802 a.select do |i|1803 i1804 end1805 `, []interface{}{true, true, true}},1806 {`1807 a = ["test", "not2", "3", "test", "5"]1808 a.select do |i|1809 i == "test"1810 end1811 `, []interface{}{"test", "test"}},1812 {`1813 [].select do |i|1814 true1815 end1816 `, []interface{}{}},1817 // cases for providing an empty block1818 {`1819 [1, 2, 3, 4, 5].select do; end1820 `, []interface{}{}},1821 {`1822 [1, 2, 3, 4, 5].select do |i|; end1823 `, []interface{}{}},1824 {`1825 [].select do; end1826 `, []interface{}{}},1827 {`1828 [].select do |i|; end1829 `, []interface{}{}},1830 }1831 for i, tt := range tests {1832 v := initTestVM()1833 evaluated := v.testEval(t, tt.input, getFilename())1834 verifyArrayObject(t, i, evaluated, tt.expected)1835 v.checkCFP(t, i, 0)1836 v.checkSP(t, i, 1)1837 }1838}1839func TestArraySelectMethodFail(t *testing.T) {1840 testsFail := []errorTestCase{1841 {`[1, 2].select(1)`, "ArgumentError: Expect 0 argument(s). got: 1", 1},1842 {`[1, 2, 3, 4, 5].select`, "InternalError: Can't yield without a block", 1},1843 }1844 for i, tt := range testsFail {1845 v := initTestVM()1846 evaluated := v.testEval(t, tt.input, getFilename())1847 checkErrorMsg(t, i, evaluated, tt.expected)1848 v.checkCFP(t, i, tt.expectedCFP)1849 v.checkSP(t, i, 1)1850 }1851}1852func TestArrayShiftMethod(t *testing.T) {1853 tests := []struct {1854 input string1855 expected interface{}1856 }{1857 {1858 `1859 a = [1, 2, 3].shift1860 a1861 `, 1},1862 {1863 `1864 a = [1, 2, 3]1865 a.pop1866 a.length1867 `, 2},1868 {1869 `1870 [].shift1871 `, nil},1872 }1873 for i, tt := range tests {1874 v := initTestVM()1875 evaluated := v.testEval(t, tt.input, getFilename())1876 VerifyExpected(t, i, evaluated, tt.expected)1877 v.checkCFP(t, i, 0)1878 v.checkSP(t, i, 1)1879 }1880}1881func TestArrayShiftMethodFail(t *testing.T) {1882 testsFail := []errorTestCase{1883 {`a = [1, 2]1884 a.shift(3, 3, 4, 5)1885 `,1886 "ArgumentError: Expect 0 argument(s). got: 4", 1},1887 }1888 for i, tt := range testsFail {1889 v := initTestVM()1890 evaluated := v.testEval(t, tt.input, getFilename())1891 checkErrorMsg(t, i, evaluated, tt.expected)1892 v.checkCFP(t, i, tt.expectedCFP)1893 v.checkSP(t, i, 1)1894 }1895}1896func TestArraySortMethod(t *testing.T) {1897 tests := []struct {1898 input string1899 expected []interface{}1900 }{1901 {`1902 [5,4,3,2,1].sort1903 `, []interface{}{1, 2, 3, 4, 5}},1904 {`1905 [5,4,1,2,3].sort1906 `, []interface{}{1, 2, 3, 4, 5}},1907 {`1908 [5,4.5,1.6,2.2,3].sort1909 `, []interface{}{1.6, 2.2, 3, 4.5, 5}},1910 {`1911 ["efg", "abc"].sort1912 `, []interface{}{"abc", "efg"}},1913 {`1914 ["abc", "aaaaaa"].sort1915 `, []interface{}{"aaaaaa", "abc"}},1916 }1917 for i, tt := range tests {1918 v := initTestVM()1919 evaluated := v.testEval(t, tt.input, getFilename())1920 verifyArrayObject(t, i, evaluated, tt.expected)1921 v.checkCFP(t, i, 0)1922 v.checkSP(t, i, 1)1923 }1924}1925func TestArraySortMethodFail(t *testing.T) {1926 testsFail := []errorTestCase{1927 {`a = [1, 2]1928 a.sort(3, 3, 4, 5)1929 `,1930 "ArgumentError: Expect 0 argument. got=4", 1},1931 }1932 for i, tt := range testsFail {1933 v := initTestVM()1934 evaluated := v.testEval(t, tt.input, getFilename())1935 checkErrorMsg(t, i, evaluated, tt.expected)1936 v.checkCFP(t, i, tt.expectedCFP)1937 v.checkSP(t, i, 1)1938 }1939}1940func TestArrayToHashMethod(t *testing.T) {1941 tests := []struct {1942 input string1943 expected map[string]interface{}1944 }{1945 {`1946 [[:john, [:guitar, :harmonica]], [:paul, :base], [:george, :guitar], [:ringo, :drum]].to_h1947 `, map[string]interface{}{"george": "guitar", "john": []interface{}{"guitar", "harmonica"}, "paul": "base", "ringo": "drum"}},1948 {`1949 [].to_h1950 `, map[string]interface{}{}},1951 }1952 for i, tt := range tests {1953 vm := initTestVM()1954 evaluated := vm.testEval(t, tt.input, getFilename())1955 verifyHashObject(t, i, evaluated, tt.expected)1956 vm.checkCFP(t, i, 0)1957 vm.checkSP(t, i, 1)1958 }1959}1960func TestArrayToHashMethodFail(t *testing.T) {1961 testsFail := []errorTestCase{1962 {`[:john].to_h`, "TypeError: Expect the Array's element #0 to be Array. got: String", 1},1963 {`[[:john]].to_h`, `ArgumentError: Expect element #0 to have 2 elements as a key-value pair. got: ["john"]`, 1},1964 {`[[:john, :paul, :george]].to_h`, `ArgumentError: Expect element #0 to have 2 elements as a key-value pair. got: ["john", "paul", "george"]`, 1},1965 {`[[1, :paul]].to_h`, `TypeError: Expect the key in the Array's element #0 to be String. got: Integer`, 1},1966 }1967 for i, tt := range testsFail {1968 v := initTestVM()1969 evaluated := v.testEval(t, tt.input, getFilename())1970 checkErrorMsg(t, i, evaluated, tt.expected)1971 v.checkCFP(t, i, tt.expectedCFP)1972 v.checkSP(t, i, 1)1973 }1974}1975func TestArrayStarMethod(t *testing.T) {1976 tests := []struct {1977 input string1978 expected []interface{}1979 }{1980 {`1981 a = [1, 2, 3]1982 a * 21983 `, []interface{}{1, 2, 3, 1, 2, 3}},1984 // Make sure the result is an entirely new array.1985 {`1986 a = [1, 2, 3]1987 (a * 2)[0] = -11988 a1989 `, []interface{}{1, 2, 3}},1990 {`1991 a = [1, 2, 3]1992 a * 01993 `, []interface{}{}},1994 {`1995 a = []1996 a * 21997 `, []interface{}{}},1998 }1999 for i, tt := range tests {2000 vm := initTestVM()2001 evaluated := vm.testEval(t, tt.input, getFilename())2002 verifyArrayObject(t, i, evaluated, tt.expected)2003 vm.checkCFP(t, i, 0)2004 vm.checkSP(t, i, 1)2005 }2006}2007func TestArrayStarMethodFail(t *testing.T) {2008 testsFail := []errorTestCase{2009 {`[1, 2] * nil`, "TypeError: Expect argument to be Integer. got: Null", 1},2010 }2011 for i, tt := range testsFail {2012 v := initTestVM()2013 evaluated := v.testEval(t, tt.input, getFilename())2014 checkErrorMsg(t, i, evaluated, tt.expected)2015 v.checkCFP(t, i, tt.expectedCFP)2016 v.checkSP(t, i, 1)2017 }2018}2019func TestArrayToEnumMethod(t *testing.T) {2020 input := `2021 iterated_values = []2022 enumerator = [1, 2, 4].to_enum2023 while enumerator.has_next? do2024 iterated_values.push(enumerator.next)2025 end2026 iterated_values2027 `2028 expected := []interface{}{1, 2, 4}2029 v := initTestVM()2030 evaluated := v.testEval(t, input, getFilename())2031 verifyArrayObject(t, i, evaluated, expected)2032 v.checkCFP(t, i, 0)2033 v.checkSP(t, i, 1)2034}2035func TestArrayUnshiftMethod(t *testing.T) {2036 tests := []struct {2037 input string2038 expected interface{}2039 }{2040 {2041 `2042 a = [1, 2, 3]2043 a.unshift(0)2044 a[0]2045 `, 0},2046 {2047 `2048 a = [1, 2, 3]2049 a.unshift(0)2050 a.length2051 `, 4},2052 {2053 `2054 a = []2055 a.unshift(nil)2056 a[0]2057 `, nil},2058 {2059 `2060 a = []2061 a.unshift("foo")2062 a.unshift(1, 2)2063 a[0]2064 `, 1},2065 {2066 `2067 a = []2068 a.unshift("foo")2069 a.unshift(1, 2)2070 a[1]2071 `, 2},2072 {2073 `2074 a = []2075 a.unshift("foo")2076 a.unshift(1, 2)2077 a[2]2078 `, "foo"},2079 }2080 for i, tt := range tests {2081 v := initTestVM()2082 evaluated := v.testEval(t, tt.input, getFilename())2083 VerifyExpected(t, i, evaluated, tt.expected)2084 v.checkCFP(t, i, 0)2085 v.checkSP(t, i, 1)2086 }2087}2088func TestArrayValuesAtMethod(t *testing.T) {2089 tests := []struct {2090 input string2091 expected []interface{}2092 }{2093 {2094 `2095 a = ["a", "b", "c"]2096 a.values_at(1)2097 `, []interface{}{"b"}},2098 {2099 `2100 a = ["a", "b", "c"]2101 a.values_at(-1, 3)2102 `, []interface{}{"c", nil}},2103 {2104 `2105 a = ["a", "b", "c"]2106 a.values_at()2107 `, []interface{}{}},2108 {2109 `2110 a = []2111 a.values_at(1, -1)2112 `, []interface{}{nil, nil}},2113 }2114 for i, tt := range tests {2115 v := initTestVM()2116 evaluated := v.testEval(t, tt.input, getFilename())2117 verifyArrayObject(t, i, evaluated, tt.expected)2118 v.checkCFP(t, i, 0)2119 v.checkSP(t, i, 1)2120 }2121}2122func TestArrayInspectCallsToString(t *testing.T) {2123 input := `[1, "234", true, nil].to_s == [1, "234", true, nil].inspect`2124 expected := true2125 vm := initTestVM()2126 evaluated := vm.testEval(t, input, getFilename())2127 VerifyExpected(t, i, evaluated, expected)2128 vm.checkCFP(t, i, 0)2129 vm.checkSP(t, i, 1)2130}2131func TestArrayInspectCallsChildElementToString(t *testing.T) {2132 input := `[1, "234", true, nil].inspect`2133 expected := `[1, "234", true, nil]`2134 vm := initTestVM()2135 evaluated := vm.testEval(t, input, getFilename())2136 VerifyExpected(t, i, evaluated, expected)2137 vm.checkCFP(t, i, 0)2138 vm.checkSP(t, i, 1)2139}2140func TestArrayValuesAtMethodFail(t *testing.T) {2141 testsFail := []errorTestCase{2142 {`a = ["a", "b", "c"]2143 a.values_at("-")2144 `, "TypeError: Expect argument to be Integer. got: String", 1},2145 }2146 for i, tt := range testsFail {2147 v := initTestVM()2148 evaluated := v.testEval(t, tt.input, getFilename())2149 checkErrorMsg(t, i, evaluated, tt.expected)2150 v.checkCFP(t, i, tt.expectedCFP)2151 v.checkSP(t, i, 1)2152 }2153}2154func TestArrayDupMethod(t *testing.T) {2155 tests := []struct {2156 input string2157 expected interface{}2158 }{2159 {`[1,2,3].dup`, []interface{}{1, 2, 3}},2160 {`2161a = [1,2,3]2162b = a.dup2163a[0] = 102164b2165`, []interface{}{1, 2, 3}},2166 }2167 for i, tt := range tests {2168 v := initTestVM()2169 evaluated := v.testEval(t, tt.input, getFilename())2170 VerifyExpected(t, i, evaluated, tt.expected)2171 v.checkCFP(t, i, 0)2172 v.checkSP(t, i, 1)2173 }2174}...

Full Screen

Full Screen

float_test.go

Source:float_test.go Github

copy

Full Screen

...10 {`Float.class.name`, "Class"},11 {`Float.superclass.name`, "Object"},12 }13 for i, tt := range tests {14 v := initTestVM()15 evaluated := v.testEval(t, tt.input, getFilename())16 VerifyExpected(t, i, evaluated, tt.expected)17 v.checkCFP(t, i, 0)18 v.checkSP(t, i, 1)19 }20}21func TestFloatArithmeticOperationWithFloat(t *testing.T) {22 tests := []struct {23 input string24 expected interface{}25 }{26 {`13.5 + 3.2`, 16.7},27 {`13.5 - 3.2`, 10.3},28 {`13.5 * 3.2`, 43.2},29 {`13.5 % 3.75`, 2.25},30 {`13.5 / 3.75`, 3.6},31 {`16.0 ** 3.5`, 16384.0},32 }33 for i, tt := range tests {34 v := initTestVM()35 evaluated := v.testEval(t, tt.input, getFilename())36 VerifyExpected(t, i, evaluated, tt.expected)37 v.checkCFP(t, i, 0)38 v.checkSP(t, i, 1)39 }40}41func TestFloatArithmeticOperationWithInteger(t *testing.T) {42 tests := []struct {43 input string44 expected interface{}45 }{46 {`13.5 + 3`, 16.5},47 {`13.5 - 3`, 10.5},48 {`13.5 * 3`, 40.5},49 {`13.5 % 3`, 1.5},50 {`13.5 / 3`, 4.5},51 {`13.5 ** 3`, 2460.375},52 }53 for i, tt := range tests {54 v := initTestVM()55 evaluated := v.testEval(t, tt.input, getFilename())56 VerifyExpected(t, i, evaluated, tt.expected)57 v.checkCFP(t, i, 0)58 v.checkSP(t, i, 1)59 }60}61func TestFloatArithmeticOperationFail(t *testing.T) {62 testsFail := []errorTestCase{63 {`1.1 + "p"`, "TypeError: Expect argument to be Numeric. got: String", 1},64 {`1.1 - "m"`, "TypeError: Expect argument to be Numeric. got: String", 1},65 {`1.1 ** "p"`, "TypeError: Expect argument to be Numeric. got: String", 1},66 {`1.1 / "t"`, "TypeError: Expect argument to be Numeric. got: String", 1},67 }68 for i, tt := range testsFail {69 v := initTestVM()70 evaluated := v.testEval(t, tt.input, getFilename())71 checkErrorMsg(t, i, evaluated, tt.expected)72 v.checkCFP(t, i, tt.expectedCFP)73 v.checkSP(t, i, 1)74 }75}76func TestFloatComparisonWithFloat(t *testing.T) {77 tests := []struct {78 input string79 expected interface{}80 }{81 {`1.5 > 2.5`, false},82 {`2.5 > 1.5`, true},83 {`3.5 > 3.5`, false},84 {`1.5 < 2.5`, true},85 {`2.5 < 1.5`, false},86 {`3.5 < 3.5`, false},87 {`1.5 >= 2.5`, false},88 {`2.5 >= 1.5`, true},89 {`3.5 >= 3.5`, true},90 {`1.5 <= 2.5`, true},91 {`2.5 <= 1.5`, false},92 {`3.5 <= 3.5`, true},93 {`1.5 <=> 2.5`, -1},94 {`2.5 <=> 1.5`, 1},95 {`3.5 <=> 3.5`, 0},96 }97 for i, tt := range tests {98 v := initTestVM()99 evaluated := v.testEval(t, tt.input, getFilename())100 VerifyExpected(t, i, evaluated, tt.expected)101 v.checkCFP(t, i, 0)102 v.checkSP(t, i, 1)103 }104}105func TestFloatComparisonWithInteger(t *testing.T) {106 tests := []struct {107 input string108 expected interface{}109 }{110 {`1 > 2`, false},111 {`2 > 1`, true},112 {`3 > 3`, false},113 {`1 < 2`, true},114 {`2 < 1`, false},115 {`3 < 3`, false},116 {`1 >= 2`, false},117 {`2 >= 1`, true},118 {`3 >= 3`, true},119 {`1 <= 2`, true},120 {`2 <= 1`, false},121 {`3 <= 3`, true},122 {`1 <=> 2`, -1},123 {`2 <=> 1`, 1},124 {`3 <=> 3`, 0},125 }126 for i, tt := range tests {127 v := initTestVM()128 evaluated := v.testEval(t, tt.input, getFilename())129 VerifyExpected(t, i, evaluated, tt.expected)130 v.checkCFP(t, i, 0)131 v.checkSP(t, i, 1)132 }133}134func TestFloatComparisonFail(t *testing.T) {135 testsFail := []errorTestCase{136 {`1 > "m"`, "TypeError: Expect argument to be Numeric. got: String", 1},137 {`1 >= "m"`, "TypeError: Expect argument to be Numeric. got: String", 1},138 {`1 < "m"`, "TypeError: Expect argument to be Numeric. got: String", 1},139 {`1 <= "m"`, "TypeError: Expect argument to be Numeric. got: String", 1},140 {`1 <=> "m"`, "TypeError: Expect argument to be Numeric. got: String", 1},141 }142 for i, tt := range testsFail {143 v := initTestVM()144 evaluated := v.testEval(t, tt.input, getFilename())145 checkErrorMsg(t, i, evaluated, tt.expected)146 v.checkCFP(t, i, tt.expectedCFP)147 v.checkSP(t, i, 1)148 }149}150func TestFloatEquality(t *testing.T) {151 tests := []struct {152 input string153 expected interface{}154 }{155 {`123.5 == 123.5`, true},156 {`123 == 123`, true},157 {`123.5 == 124`, false},158 {`123.5 == "123.5"`, false},159 {`123.5 == (1..3)`, false},160 {`123.5 == { a: 1 }`, false},161 {`123.5 == [1]`, false},162 {`123.5 == Float`, false},163 {`123.5 != 123.5`, false},164 {`123.5 != 123`, true},165 {`123.5 != 124`, true},166 {`123.5 != "123.5"`, true},167 {`123.5 != (1..3)`, true},168 {`123.5 != { a: 1 }`, true},169 {`123.5 != [1]`, true},170 {`123.5 != Float`, true},171 }172 for i, tt := range tests {173 v := initTestVM()174 evaluated := v.testEval(t, tt.input, getFilename())175 VerifyExpected(t, i, evaluated, tt.expected)176 v.checkCFP(t, i, 0)177 v.checkSP(t, i, 1)178 }179}180func TestFloatConversions(t *testing.T) {181 tests := []struct {182 input string183 expected interface{}184 }{185 {`(100.3).to_i`, 100},186 {`(100.3).to_s`, "100.3"},187 {`(100.3).to_d.to_s`, "100.3"},188 {`189 (3.14159265358979).to_d.to_s`,190 "3.14159265358979"},191 {`192 (-273.150000000).to_d.to_s`,193 "-273.15"},194 {`100.3.to_i`, 100},195 {`100.3.to_s`, "100.3"},196 {`100.3.to_d.to_s`, "100.3"},197 {`198 3.14159265358979.to_d.to_s`,199 "3.14159265358979"},200 {`201 -273.150000000.to_d.to_s`,202 "-273.15"},203 }204 for i, tt := range tests {205 v := initTestVM()206 evaluated := v.testEval(t, tt.input, getFilename())207 VerifyExpected(t, i, evaluated, tt.expected)208 v.checkCFP(t, i, 0)209 v.checkSP(t, i, 1)210 }211}212func TestFloatEdgeCases(t *testing.T) {213 tests := []struct {214 input string215 expected interface{}216 }{217 {`(0.1 + 0.2).to_s`, "0.30000000000000004"},218 }219 for i, tt := range tests {220 v := initTestVM()221 evaluated := v.testEval(t, tt.input, getFilename())222 VerifyExpected(t, i, evaluated, tt.expected)223 v.checkCFP(t, i, 0)224 v.checkSP(t, i, 1)225 }226}227func TestFloatZeroDivisionFail(t *testing.T) {228 testsFail := []errorTestCase{229 {`6.0 / 0`, "ZeroDivisionError: Divided by 0", 1},230 {`6.0 / -0`, "ZeroDivisionError: Divided by 0", 1},231 {`6.0 / 0.0`, "ZeroDivisionError: Divided by 0", 1},232 {`6.0 / -0.0`, "ZeroDivisionError: Divided by 0", 1},233 {`6.0 % 0`, "ZeroDivisionError: Divided by 0", 1},234 {`6.0 % -0`, "ZeroDivisionError: Divided by 0", 1},235 {`6.0 % 0.0`, "ZeroDivisionError: Divided by 0", 1},236 {`6.0 % -0.0`, "ZeroDivisionError: Divided by 0", 1},237 }238 for i, tt := range testsFail {239 v := initTestVM()240 evaluated := v.testEval(t, tt.input, getFilename())241 checkErrorMsg(t, i, evaluated, tt.expected)242 v.checkCFP(t, i, tt.expectedCFP)243 v.checkSP(t, i, 1)244 }245}246func TestFloatTruncation(t *testing.T) {247 tests := []struct {248 input string249 expected string250 }{251 {`[9.0][0].to_s`, "9.0"},252 {`[9.00][0].to_s`, "9.0"},253 {`[1.0][0].to_s`, "1.0"},254 {`[1.00][0].to_s`, "1.0"},255 {`[0.0][0].to_s`, "0.0"},256 {`[0.00][0].to_s`, "0.0"},257 {`[0.0][0].class.to_s`, "Float"},258 }259 for i, tt := range tests {260 v := initTestVM()261 evaluated := v.testEval(t, tt.input, getFilename())262 VerifyExpected(t, i, evaluated, tt.expected)263 v.checkCFP(t, i, 0)264 v.checkSP(t, i, 1)265 }266}267func TestFloatNumberOfDigit(t *testing.T) {268 tests := []struct {269 input string270 expected string271 }{272 {`3.14.to_s`, "3.14"},273 {`3.141.to_s`, "3.141"},274 {`3.1415.to_s`, "3.1415"},275 {`3.14159.to_s`, "3.14159"},276 {`3.141592.to_s`, "3.141592"},277 {`3.1415926.to_s`, "3.1415926"},278 {`3.14159265.to_s`, "3.14159265"},279 {`3.141592653.to_s`, "3.141592653"},280 {`3.1415926535.to_s`, "3.1415926535"},281 {`3.14159265358.to_s`, "3.14159265358"},282 {`3.141592653589.to_s`, "3.141592653589"},283 {`3.1415926535897.to_s`, "3.1415926535897"},284 {`3.14159265358979.to_s`, "3.14159265358979"},285 {`3.141592653589793.to_s`, "3.141592653589793"},286 {`3.1415926535897932.to_s`, "3.141592653589793"},287 {`3.1415926535897932384626.to_s`, "3.141592653589793"},288 {`-3.14.to_s`, "-3.14"},289 {`-3.141.to_s`, "-3.141"},290 {`-3.1415.to_s`, "-3.1415"},291 {`-3.14159.to_s`, "-3.14159"},292 {`-3.141592.to_s`, "-3.141592"},293 {`-3.1415926.to_s`, "-3.1415926"},294 {`-3.14159265.to_s`, "-3.14159265"},295 {`-3.141592653.to_s`, "-3.141592653"},296 {`-3.1415926535.to_s`, "-3.1415926535"},297 {`-3.14159265358.to_s`, "-3.14159265358"},298 {`-3.141592653589.to_s`, "-3.141592653589"},299 {`-3.1415926535897.to_s`, "-3.1415926535897"},300 {`-3.14159265358979.to_s`, "-3.14159265358979"},301 {`-3.141592653589793.to_s`, "-3.141592653589793"},302 {`-3.1415926535897932.to_s`, "-3.141592653589793"},303 {`-3.1415926535897932384626.to_s`, "-3.141592653589793"},304 }305 for i, tt := range tests {306 v := initTestVM()307 evaluated := v.testEval(t, tt.input, getFilename())308 VerifyExpected(t, i, evaluated, tt.expected)309 v.checkCFP(t, i, 0)310 v.checkSP(t, i, 1)311 }312}313// API tests314func TestFloatAbs(t *testing.T) {315 tests := []struct {316 input string317 expected interface{}318 }{319 {"34.56.abs", 34.56},320 {"-34.56.abs", 34.56},321 }322 for i, tt := range tests {323 v := initTestVM()324 evaluated := v.testEval(t, tt.input, getFilename())325 VerifyExpected(t, i, evaluated, tt.expected)326 v.checkCFP(t, i, 0)327 v.checkSP(t, i, 1)328 }329}330func TestFloatMinusZero(t *testing.T) {331 tests := []struct {332 input string333 expected string334 }{335 {`0.0.to_s`, "0.0"},336 {`-0.0.to_s`, "-0.0"},337 {`(-0.0 == 0.0).to_s`, "true"},338 {`(0.0 + 0.0).to_s`, "0.0"},339 {`(0.0 + -0.0).to_s`, "0.0"},340 {`(0.0 - 0.0).to_s`, "0.0"},341 {`(0.0 - -0.0).to_s`, "0.0"},342 {`(-0.0 + 0.0).to_s`, "0.0"},343 {`(-0.0 + -0.0).to_s`, "-0.0"},344 {`(-0.0 - 0.0).to_s`, "-0.0"},345 {`(-0.0 - -0.0).to_s`, "0.0"},346 {`(0.0 * 0.0).to_s`, "0.0"},347 {`(0.0 * -0.0).to_s`, "-0.0"},348 {`(-0.0 * 0.0).to_s`, "-0.0"},349 {`(-0.0 * -0.0).to_s`, "0.0"},350 }351 for i, tt := range tests {352 v := initTestVM()353 evaluated := v.testEval(t, tt.input, getFilename())354 VerifyExpected(t, i, evaluated, tt.expected)355 v.checkCFP(t, i, 0)356 v.checkSP(t, i, 1)357 }358}359func TestFloatCeil(t *testing.T) {360 tests := []struct {361 input string362 expected interface{}363 }{364 {"1.2.ceil", 2},365 {"2.0.ceil", 2},366 {"-1.2.ceil", -1},367 {"-2.0.ceil", -2},368 }369 for i, tt := range tests {370 v := initTestVM()371 evaluated := v.testEval(t, tt.input, getFilename())372 VerifyExpected(t, i, evaluated, tt.expected)373 v.checkCFP(t, i, 0)374 v.checkSP(t, i, 1)375 }376}377func TestFloatDupMethod(t *testing.T) {378 tests := []struct {379 input string380 expected interface{}381 }{382 {`1.1.dup == 1.1`, true},383 }384 for i, tt := range tests {385 v := initTestVM()386 evaluated := v.testEval(t, tt.input, getFilename())387 VerifyExpected(t, i, evaluated, tt.expected)388 v.checkCFP(t, i, 0)389 v.checkSP(t, i, 1)390 }391}392func TestFloatFloor(t *testing.T) {393 tests := []struct {394 input string395 expected interface{}396 }{397 {"1.2.floor", 1},398 {"2.0.floor", 2},399 {"-1.2.floor", -2},400 {"-2.0.floor", -2},401 }402 for i, tt := range tests {403 v := initTestVM()404 evaluated := v.testEval(t, tt.input, getFilename())405 VerifyExpected(t, i, evaluated, tt.expected)406 v.checkCFP(t, i, 0)407 v.checkSP(t, i, 1)408 }409}410func TestFloatNegative(t *testing.T) {411 tests := []struct {412 input string413 expected interface{}414 }{415 {"-1.0.negative?", true},416 {"0.0.negative?", false},417 {"1.0.negative?", false},418 }419 for i, tt := range tests {420 v := initTestVM()421 evaluated := v.testEval(t, tt.input, getFilename())422 VerifyExpected(t, i, evaluated, tt.expected)423 v.checkCFP(t, i, 0)424 v.checkSP(t, i, 1)425 }426}427func TestFloatPositive(t *testing.T) {428 tests := []struct {429 input string430 expected interface{}431 }{432 {"-1.0.positive?", false},433 {"0.0.positive?", false},434 {"1.0.positive?", true},435 }436 for i, tt := range tests {437 v := initTestVM()438 evaluated := v.testEval(t, tt.input, getFilename())439 VerifyExpected(t, i, evaluated, tt.expected)440 v.checkCFP(t, i, 0)441 v.checkSP(t, i, 1)442 }443}444func TestFloatRound(t *testing.T) {445 tests := []struct {446 input string447 expected interface{}448 }{449 {"1.115.round", 1.0},450 {"1.115.round(1)", 1.1},451 {"1.115.round(2)", 1.12},452 {"-1.115.round", -1.0},453 {"-1.115.round(1)", -1.1},454 {"-1.115.round(2)", -1.12},455 {"1.115.round(-1)", 0.0},456 {"-1.115.round(-1)", 0.0},457 }458 for i, tt := range tests {459 v := initTestVM()460 evaluated := v.testEval(t, tt.input, getFilename())461 VerifyExpected(t, i, evaluated, tt.expected)462 v.checkCFP(t, i, 0)463 v.checkSP(t, i, 1)464 }465}466func TestFloatZero(t *testing.T) {467 tests := []struct {468 input string469 expected interface{}470 }{471 {"0.0.zero?", true},472 {"1.0.zero?", false},473 }474 for i, tt := range tests {475 v := initTestVM()476 evaluated := v.testEval(t, tt.input, getFilename())477 VerifyExpected(t, i, evaluated, tt.expected)478 v.checkCFP(t, i, 0)479 v.checkSP(t, i, 1)480 }481}...

Full Screen

Full Screen

test.go

Source:test.go Github

copy

Full Screen

...28 Use: "web_client_tests_server",29 Short: "Run the server configured for running the web client tests against it",30 RunE: serverForWebClientTestsCmdF,31}32func init() {33 testCmd.AddCommand(34 runWebClientTestsCmd,35 runServerForWebClientTestsCmd,36 )37}38func webClientTestsCmdF(cmd *cobra.Command, args []string) error {39 a, err := initDBCommandContextCobra(cmd)40 if err != nil {41 return err42 }43 utils.InitTranslations(utils.Cfg.LocalizationSettings)44 a.Srv.Router = api.NewRouter()45 wsapi.InitRouter()46 api4.InitApi(a.Srv.Router, false)47 api.InitApi(a.Srv.Router)48 wsapi.InitApi()49 setupClientTests()50 a.StartServer()51 runWebClientTests()52 a.StopServer()53 return nil54}55func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error {56 a, err := initDBCommandContextCobra(cmd)57 if err != nil {58 return err59 }60 utils.InitTranslations(utils.Cfg.LocalizationSettings)61 a.Srv.Router = api.NewRouter()62 wsapi.InitRouter()63 api4.InitApi(a.Srv.Router, false)64 api.InitApi(a.Srv.Router)65 wsapi.InitApi()66 setupClientTests()67 a.StartServer()68 c := make(chan os.Signal)69 signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)70 <-c...

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1import (2func Test1(t *testing.T) {3 fmt.Println("Test1")4}5func Test2(t *testing.T) {6 fmt.Println("Test2")7}8func Test3(t *testing.T) {9 fmt.Println("Test3")10}11func Test4(t *testing.T) {12 fmt.Println("Test4")13}14func Test5(t *testing.T) {15 fmt.Println("Test5")16}17func Test6(t *testing.T) {18 fmt.Println("Test6")19}20func Test7(t *testing.T) {21 fmt.Println("Test7")22}23func Test8(t *testing.T) {24 fmt.Println("Test8")25}26func Test9(t *testing.T) {27 fmt.Println("Test9")28}29func Test10(t *testing.T) {30 fmt.Println("Test10")31}32import (33func Test11(t *testing.T) {34 fmt.Println("Test11")35}36func Test12(t *testing.T) {37 fmt.Println("Test12")38}39func Test13(t *testing.T) {40 fmt.Println("Test13")41}42func Test14(t *testing.T) {43 fmt.Println("Test14")44}45func Test15(t *testing.T) {46 fmt.Println("Test15")47}48func Test16(t *testing.T) {49 fmt.Println("Test16")50}51func Test17(t *testing.T) {52 fmt.Println("Test17")53}54func Test18(t *testing.T) {55 fmt.Println("Test18")56}57func Test19(t *testing.T) {58 fmt.Println("Test19")59}60func Test20(t *testing.T) {61 fmt.Println("Test20")62}63import (64func Test21(t *testing.T) {65 fmt.Println("Test21")66}67func Test22(t *testing.T) {68 fmt.Println("Test22")69}70func Test23(t *testing.T) {71 fmt.Println("Test23")72}73func Test24(t *testing.T) {74 fmt.Println("Test24")75}76func Test25(t *testing.T) {77 fmt.Println("Test25")78}79func Test26(t *testing.T) {80 fmt.Println("Test26")81}82func Test27(t *testing.T) {83 fmt.Println("

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1func TestMain(m *testing.M) {2 os.Exit(m.Run())3}4func TestMain(m *testing.M) {5 os.Exit(m.Run())6}7func TestMain(m *testing.M) {8 os.Exit(m.Run())9}10func TestMain(m *testing.M) {11 os.Exit(m.Run())12}13func TestMain(m *testing.M) {14 os.Exit(m.Run())15}16func TestMain(m *testing.M) {17 os.Exit(m.Run())18}19func TestMain(m *testing.M) {20 os.Exit(m.Run())21}22func TestMain(m *testing.M) {23 os.Exit(m.Run())24}25func TestMain(m *testing.M) {26 os.Exit(m.Run())27}28func TestMain(m *testing.M) {29 os.Exit(m.Run())30}31func TestMain(m *testing.M) {32 os.Exit(m.Run())33}

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1func TestMain(m *testing.M) {2 fmt.Println("TestMain")3 os.Exit(m.Run())4}5func Test1(t *testing.T) {6 fmt.Println("Test1")7}8func Test2(t *testing.T) {9 fmt.Println("Test2")10}11func Test3(t *testing.T) {12 fmt.Println("Test3")13}14func TestMain(m *testing.M) {15 fmt.Println("TestMain")16 os.Exit(m.Run())17}18func Test1(t *testing.T) {19 fmt.Println("Test1")20}21func Test2(t *testing.T) {22 fmt.Println("Test2")23}24func Test3(t *testing.T) {25 fmt.Println("Test3")26}27func TestMain(m *testing.M) {28 fmt.Println("TestMain")29 os.Exit(m.Run())30}31func Test1(t *testing.T) {32 fmt.Println("Test1")33}34func Test2(t *testing.T) {35 fmt.Println("Test2")36}37func Test3(t *testing.T) {38 fmt.Println("Test3")39}40func TestMain(m *testing.M) {41 fmt.Println("TestMain")42 os.Exit(m.Run())43}44func Test1(t *testing.T) {45 fmt.Println("Test1")46}47func Test2(t *testing.T) {48 fmt.Println("Test2")49}50func Test3(t *testing.T) {51 fmt.Println("Test3")52}53func TestMain(m *testing.M) {54 fmt.Println("TestMain")55 os.Exit(m.Run())56}57func Test1(t *testing.T) {58 fmt.Println("Test1")59}60func Test2(t *testing.T) {61 fmt.Println("Test2")62}63func Test3(t *testing.T) {64 fmt.Println("Test3")65}

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1func TestMain(m *testing.M) {2 os.Exit(m.Run())3}4func TestMain(m *testing.M) {5 os.Exit(m.Run())6}

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1import (2func init() {3 fmt.Println("init")4}5func TestHelloWorld(t *testing.T) {6 fmt.Println("Hello World")7}8import (9func init() {10 fmt.Println("init")11}12func TestHelloWorld(t *testing.T) {13 fmt.Println("Hello World")14}15import (16func init() {17 fmt.Println("init")18}19func TestHelloWorld(t *testing.T) {20 fmt.Println("Hello World")21}22import (23func init() {24 fmt.Println("init")25}26func TestHelloWorld(t *testing.T) {27 fmt.Println("Hello World")28}29import (30func init() {31 fmt.Println("init")32}33func TestHelloWorld(t *testing.T) {34 fmt.Println("Hello World")35}36import (37func init() {38 fmt.Println("init")39}40func TestHelloWorld(t *testing.T) {41 fmt.Println("Hello World")42}43import (44func init() {45 fmt.Println("init")46}47func TestHelloWorld(t *testing.T) {48 fmt.Println("Hello World")49}50import (51func init() {52 fmt.Println("init")53}54func TestHelloWorld(t *testing.T) {55 fmt.Println("Hello World")56}57import (58func init() {59 fmt.Println("init")60}61func TestHelloWorld(t *testing.T) {62 fmt.Println("Hello World")63}

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1import (2func init() {3 fmt.Println("Init method of main class")4}5func TestMain(t *testing.T) {6 fmt.Println("TestMain method of main class")7}8func TestMain2(t *testing.T) {9 fmt.Println("TestMain2 method of main class")10}11import (12func init() {13 fmt.Println("Init method of main class")14}15func TestMain(t *testing.T) {16 fmt.Println("TestMain method of main class")17}18func TestMain2(t *testing.T) {19 fmt.Println("TestMain2 method of main class")20}21func TestMain3(t *testing.T) {22 fmt.Println("TestMain3 method of main class")23}24import (25func init() {26 fmt.Println("Init method of main class")27}28func TestMain(t *testing.T) {29 fmt.Println("TestMain method of main class")30}31func TestMain2(t *testing.T) {32 fmt.Println("TestMain2 method of main class")33}34func TestMain3(t *testing.T) {35 fmt.Println("TestMain3 method of main class")36}37func TestMain4(t *testing.T) {38 fmt.Println("TestMain4 method of main class")39}

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1import "testing"2func TestMain(m *testing.M) {3 m.Run()4}5func TestOne(t *testing.T) {6 t.Run("TestOne", func(t *testing.T) {7 t.Run("TestOne", func(t *testing.T) {8 t.Run("TestOne", func(t *testing.T) {9 t.Run("TestOne", func(t *testing.T) {10 t.Run("TestOne", func(t *testing.T) {11 t.Run("TestOne", func(t *testing.T) {12 t.Run("TestOne", func(t *testing.T) {13 t.Run("TestOne", func(t *testing.T) {14 t.Run("TestOne", func(t *testing.T) {15 t.Run("TestOne", func(t *testing.T) {16 t.Run("TestOne", func(t *testing.T) {17 t.Run("TestOne", func(t *testing.T) {18 t.Run("TestOne", func(t *testing.T) {19 t.Run("TestOne", func(t *testing.T) {20 t.Run("TestOne", func(t *testing.T) {21 t.Run("TestOne", func(t *testing.T) {22 t.Run("TestOne", func(t *testing.T) {23 t.Run("TestOne", func(t *testing.T) {24 t.Run("TestOne", func(t *testing.T) {

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1import (2func init() {3 fmt.Println("Init method called")4}5func TestHello(t *testing.T) {6 fmt.Println("Test Hello called")7}8func TestWorld(t *testing.T) {9 fmt.Println("Test World called")10}11import (12func init() {13 fmt.Println("Init method called")14}15func TestHello(t *testing.T) {16 fmt.Println("Test Hello called")17}18func TestWorld(t *testing.T) {19 fmt.Println("Test World called")20}21--- PASS: TestHello (0.00s)

Full Screen

Full Screen

init

Using AI Code Generation

copy

Full Screen

1func TestMain(m *testing.M) {2 fmt.Println("TestMain: Before tests")3 os.Exit(m.Run())4}5func TestMain(m *testing.M) {6 fmt.Println("TestMain: Before tests")7 os.Exit(m.Run())8}9func TestMain(m *testing.M) {10 fmt.Println("TestMain: Before tests")11 os.Exit(m.Run())12}13func TestMain(m *testing.M) {14 fmt.Println("TestMain: Before tests")15 os.Exit(m.Run())16}17func TestMain(m *testing.M) {18 fmt.Println("TestMain: Before tests")19 os.Exit(m.Run())20}21func TestMain(m *testing.M) {22 fmt.Println("TestMain: Before tests")23 os.Exit(m.Run())24}25func TestMain(m *testing.M) {26 fmt.Println("TestMain: Before tests")27 os.Exit(m.Run())28}29func TestMain(m *testing.M) {30 fmt.Println("TestMain: Before tests")31 os.Exit(m.Run())32}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful