| 644 | } |
| 645 | |
| 646 | func TestString_AsNumber(t *testing.T) { |
| 647 | cases := []struct { |
| 648 | name string |
| 649 | str string |
| 650 | base []int |
| 651 | result chainResult |
| 652 | expectedNum float64 |
| 653 | }{ |
| 654 | { |
| 655 | name: "default base integer", |
| 656 | str: "1234567", |
| 657 | result: success, |
| 658 | expectedNum: float64(1234567), |
| 659 | }, |
| 660 | { |
| 661 | name: "default base float", |
| 662 | str: "11.22", |
| 663 | result: success, |
| 664 | expectedNum: float64(11.22), |
| 665 | }, |
| 666 | { |
| 667 | name: "default base bad", |
| 668 | str: "a1", |
| 669 | result: failure, |
| 670 | }, |
| 671 | { |
| 672 | name: "base10 integer", |
| 673 | str: "100", |
| 674 | base: []int{10}, |
| 675 | result: success, |
| 676 | expectedNum: float64(100), |
| 677 | }, |
| 678 | { |
| 679 | name: "base10 float", |
| 680 | str: "11.22", |
| 681 | base: []int{10}, |
| 682 | result: success, |
| 683 | expectedNum: float64(11.22), |
| 684 | }, |
| 685 | { |
| 686 | name: "base16 integer", |
| 687 | str: "100", |
| 688 | base: []int{16}, |
| 689 | result: success, |
| 690 | expectedNum: float64(0x100), |
| 691 | }, |
| 692 | { |
| 693 | name: "base16 float", |
| 694 | str: "11.22", |
| 695 | base: []int{16}, |
| 696 | result: failure, |
| 697 | }, |
| 698 | { |
| 699 | name: "base16 large integer", |
| 700 | str: "4000000000000000", |
| 701 | base: []int{16}, |
| 702 | result: success, |
| 703 | expectedNum: float64(0x4000000000000000), |