|
406 | 406 | describe "with an endless range" do |
407 | 407 | describe "and Integer values" do |
408 | 408 | it "yield Integer values incremented by 1 when not passed a step" do |
409 | | - eval("(-2..)").step { |x| break if x > 2; ScratchPad << x } |
| 409 | + (-2..).step { |x| break if x > 2; ScratchPad << x } |
410 | 410 | ScratchPad.recorded.should eql([-2, -1, 0, 1, 2]) |
411 | 411 |
|
412 | 412 | ScratchPad.record [] |
413 | | - eval("(-2...)").step { |x| break if x > 2; ScratchPad << x } |
| 413 | + (-2...).step { |x| break if x > 2; ScratchPad << x } |
414 | 414 | ScratchPad.recorded.should eql([-2, -1, 0, 1, 2]) |
415 | 415 | end |
416 | 416 |
|
417 | 417 | it "yields Integer values incremented by an Integer step" do |
418 | | - eval("(-5..)").step(2) { |x| break if x > 3; ScratchPad << x } |
| 418 | + (-5..).step(2) { |x| break if x > 3; ScratchPad << x } |
419 | 419 | ScratchPad.recorded.should eql([-5, -3, -1, 1, 3]) |
420 | 420 |
|
421 | 421 | ScratchPad.record [] |
422 | | - eval("(-5...)").step(2) { |x| break if x > 3; ScratchPad << x } |
| 422 | + (-5...).step(2) { |x| break if x > 3; ScratchPad << x } |
423 | 423 | ScratchPad.recorded.should eql([-5, -3, -1, 1, 3]) |
424 | 424 | end |
425 | 425 |
|
426 | 426 | it "yields Float values incremented by a Float step" do |
427 | | - eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x } |
| 427 | + (-2..).step(1.5) { |x| break if x > 1.0; ScratchPad << x } |
428 | 428 | ScratchPad.recorded.should eql([-2.0, -0.5, 1.0]) |
429 | 429 |
|
430 | 430 | ScratchPad.record [] |
431 | | - eval("(-2..)").step(1.5) { |x| break if x > 1.0; ScratchPad << x } |
| 431 | + (-2..).step(1.5) { |x| break if x > 1.0; ScratchPad << x } |
432 | 432 | ScratchPad.recorded.should eql([-2.0, -0.5, 1.0]) |
433 | 433 | end |
434 | 434 | end |
435 | 435 |
|
436 | 436 | describe "and Float values" do |
437 | 437 | it "yields Float values incremented by 1 and less than end when not passed a step" do |
438 | | - eval("(-2.0..)").step { |x| break if x > 1.5; ScratchPad << x } |
| 438 | + (-2.0..).step { |x| break if x > 1.5; ScratchPad << x } |
439 | 439 | ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0]) |
440 | 440 |
|
441 | 441 | ScratchPad.record [] |
442 | | - eval("(-2.0...)").step { |x| break if x > 1.5; ScratchPad << x } |
| 442 | + (-2.0...).step { |x| break if x > 1.5; ScratchPad << x } |
443 | 443 | ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0]) |
444 | 444 | end |
445 | 445 |
|
446 | 446 | it "yields Float values incremented by an Integer step" do |
447 | | - eval("(-5.0..)").step(2) { |x| break if x > 3.5; ScratchPad << x } |
| 447 | + (-5.0..).step(2) { |x| break if x > 3.5; ScratchPad << x } |
448 | 448 | ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0]) |
449 | 449 |
|
450 | 450 | ScratchPad.record [] |
451 | | - eval("(-5.0...)").step(2) { |x| break if x > 3.5; ScratchPad << x } |
| 451 | + (-5.0...).step(2) { |x| break if x > 3.5; ScratchPad << x } |
452 | 452 | ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0]) |
453 | 453 | end |
454 | 454 |
|
455 | 455 | it "yields Float values incremented by a Float step" do |
456 | | - eval("(-1.0..)").step(0.5) { |x| break if x > 0.6; ScratchPad << x } |
| 456 | + (-1.0..).step(0.5) { |x| break if x > 0.6; ScratchPad << x } |
457 | 457 | ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5]) |
458 | 458 |
|
459 | 459 | ScratchPad.record [] |
460 | | - eval("(-1.0...)").step(0.5) { |x| break if x > 0.6; ScratchPad << x } |
| 460 | + (-1.0...).step(0.5) { |x| break if x > 0.6; ScratchPad << x } |
461 | 461 | ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5]) |
462 | 462 | end |
463 | 463 |
|
464 | 464 | it "handles infinite values at the start" do |
465 | | - eval("(-Float::INFINITY..)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } |
| 465 | + (-Float::INFINITY..).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } |
466 | 466 | ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY]) |
467 | 467 |
|
468 | 468 | ScratchPad.record [] |
469 | | - eval("(-Float::INFINITY...)").step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } |
| 469 | + (-Float::INFINITY...).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 } |
470 | 470 | ScratchPad.recorded.should eql([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY]) |
471 | 471 | end |
472 | 472 | end |
473 | 473 |
|
474 | 474 | describe "and String values" do |
475 | 475 | it "yields String values incremented by #succ and less than or equal to end when not passed a step" do |
476 | | - eval("('A'..)").step { |x| break if x > "D"; ScratchPad << x } |
| 476 | + ('A'..).step { |x| break if x > "D"; ScratchPad << x } |
477 | 477 | ScratchPad.recorded.should == ["A", "B", "C", "D"] |
478 | 478 |
|
479 | 479 | ScratchPad.record [] |
480 | | - eval("('A'...)").step { |x| break if x > "D"; ScratchPad << x } |
| 480 | + ('A'...).step { |x| break if x > "D"; ScratchPad << x } |
481 | 481 | ScratchPad.recorded.should == ["A", "B", "C", "D"] |
482 | 482 | end |
483 | 483 |
|
484 | 484 | it "yields String values incremented by #succ called Integer step times" do |
485 | | - eval("('A'..)").step(2) { |x| break if x > "F"; ScratchPad << x } |
| 485 | + ('A'..).step(2) { |x| break if x > "F"; ScratchPad << x } |
486 | 486 | ScratchPad.recorded.should == ["A", "C", "E"] |
487 | 487 |
|
488 | 488 | ScratchPad.record [] |
489 | | - eval("('A'...)").step(2) { |x| break if x > "F"; ScratchPad << x } |
| 489 | + ('A'...).step(2) { |x| break if x > "F"; ScratchPad << x } |
490 | 490 | ScratchPad.recorded.should == ["A", "C", "E"] |
491 | 491 | end |
492 | 492 |
|
493 | 493 | it "raises a TypeError when passed a Float step" do |
494 | | - -> { eval("('A'..)").step(2.0) { } }.should raise_error(TypeError) |
495 | | - -> { eval("('A'...)").step(2.0) { } }.should raise_error(TypeError) |
| 494 | + -> { ('A'..).step(2.0) { } }.should raise_error(TypeError) |
| 495 | + -> { ('A'...).step(2.0) { } }.should raise_error(TypeError) |
496 | 496 | end |
497 | 497 |
|
498 | 498 | ruby_version_is "3.4" do |
499 | 499 | it "yields String values adjusted by step" do |
500 | | - eval("('A'..)").step("A") { |x| break if x > "AAA"; ScratchPad << x } |
| 500 | + ('A'..).step("A") { |x| break if x > "AAA"; ScratchPad << x } |
501 | 501 | ScratchPad.recorded.should == ["A", "AA", "AAA"] |
502 | 502 |
|
503 | 503 | ScratchPad.record [] |
504 | | - eval("('A'...)").step("A") { |x| break if x > "AAA"; ScratchPad << x } |
| 504 | + ('A'...).step("A") { |x| break if x > "AAA"; ScratchPad << x } |
505 | 505 | ScratchPad.recorded.should == ["A", "AA", "AAA"] |
506 | 506 | end |
507 | 507 |
|
508 | 508 | it "raises a TypeError when passed an incompatible type step" do |
509 | | - -> { eval("('A'..)").step([]) { } }.should raise_error(TypeError) |
510 | | - -> { eval("('A'...)").step([]) { } }.should raise_error(TypeError) |
| 509 | + -> { ('A'..).step([]) { } }.should raise_error(TypeError) |
| 510 | + -> { ('A'...).step([]) { } }.should raise_error(TypeError) |
511 | 511 | end |
512 | 512 | end |
513 | 513 | end |
|
0 commit comments