| 141 | } |
| 142 | |
| 143 | func (s *OptionsTestSuite) TestGetInt() { |
| 144 | o := options.New() |
| 145 | o.Set("int", 42) |
| 146 | o.Set("int32", int32(32)) |
| 147 | o.Set("int16", int16(16)) |
| 148 | o.Set("int8", int8(8)) |
| 149 | o.Set("float", 3.14) |
| 150 | o.Set("string", "not_an_int") |
| 151 | |
| 152 | // Integer types |
| 153 | s.Require().Equal(42, o.GetInt("int", 0)) |
| 154 | s.Require().Equal(32, o.GetInt("int32", 0)) |
| 155 | s.Require().Equal(16, o.GetInt("int16", 0)) |
| 156 | s.Require().Equal(8, o.GetInt("int8", 0)) |
| 157 | |
| 158 | // Non-existing key |
| 159 | s.Require().Equal(100, o.GetInt("non_existing_key", 100)) |
| 160 | |
| 161 | // Type mismatch |
| 162 | s.Require().Panics(func() { |
| 163 | o.GetInt("float", 0) |
| 164 | }) |
| 165 | s.Require().Panics(func() { |
| 166 | o.GetInt("string", 0) |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | func (s *OptionsTestSuite) TestGetFloat() { |
| 171 | o := options.New() |