package parser import ( "testing" ) func TestInteger(t *testing.T) { for _, test := range []parseTest{ {``, []string{`Error: unexpected end of file (expected a number) at start of file`}}, // Decimal {`0`, []string{`integer(0)`}}, {`+0`, []string{`integer(0)`}}, {`-0`, []string{`integer(0)`}}, {`1`, []string{`integer(1)`}}, {`42`, []string{`integer(42)`}}, {`+99`, []string{`integer(99)`}}, {`-17`, []string{`integer(-17)`}}, {`1234`, []string{`integer(1234)`}}, {`_`, []string{`Error: unexpected input (expected a number) at start of file`}}, {`1_`, []string{`integer(1)`, `Error: unexpected input (expected end of file) at line 1, column 2`}}, {`1_000`, []string{`integer(1000)`}}, {`5_349_221`, []string{`integer(5349221)`}}, {`1_2_3_4_5`, []string{`integer(12345)`}}, {`9_223_372_036_854_775_807`, []string{`integer(9223372036854775807)`}}, {`9_223_372_036_854_775_808`, []string{ `Panic: Handler error: MakeInt64Token cannot handle input "9223372036854775808": ` + `strconv.ParseInt: parsing "9223372036854775808": value out of range (only use a ` + `type conversion token maker, when the input has been validated on beforehand)`}}, {`-9_223_372_036_854_775_808`, []string{`integer(-9223372036854775808)`}}, // TODO make the use of the same kind of handling for panics and for errors between parsekit and TOML. {`-9_223_372_036_854_775_809`, []string{ `Panic: Handler error: MakeInt64Token cannot handle input "-9223372036854775809": ` + `strconv.ParseInt: parsing "-9223372036854775809": value out of range (only use a ` + `type conversion token maker, when the input has been validated on beforehand)`}}, // Hexadecimal {`0x0`, []string{`integer(0)`}}, {`0x1`, []string{`integer(1)`}}, {`0x01`, []string{`integer(1)`}}, {`0x00fF`, []string{`integer(255)`}}, {`0xf_f`, []string{`integer(255)`}}, {`0x0_0_f_f`, []string{`integer(255)`}}, {`0xdead_beef`, []string{`integer(3735928559)`}}, {`0xgood_beef`, []string{`integer(0)`, `Error: unexpected input (expected end of file) at line 1, column 2`}}, {`0x7FFFFFFFFFFFFFFF`, []string{`integer(9223372036854775807)`}}, {`0x8000000000000000`, []string{ `Error: Cannot parse value 0x8000000000000000: strconv.ParseInt: parsing "8000000000000000": ` + `value out of range at line 1, column 19`}}, //Octal {`0o0`, []string{`integer(0)`}}, {`0o1`, []string{`integer(1)`}}, {`0o01`, []string{`integer(1)`}}, {`0o10`, []string{`integer(8)`}}, {`0o1_6`, []string{`integer(14)`}}, {`0o0_0_1_1_1`, []string{`integer(73)`}}, {`0o9`, []string{`integer(0)`, `Error: unexpected input (expected end of file) at line 1, column 2`}}, {`0o777777777777777777777`, []string{`integer(9223372036854775807)`}}, {`0o1000000000000000000000`, []string{ `Error: Cannot parse value 0o1000000000000000000000: strconv.ParseInt: parsing "1000000000000000000000": ` + `value out of range at line 1, column 25`}}, // Binary {`0b0`, []string{`integer(0)`}}, {`0b1`, []string{`integer(1)`}}, {`0b01`, []string{`integer(1)`}}, {`0b10`, []string{`integer(2)`}}, {`0b0100`, []string{`integer(4)`}}, {`0b00001000`, []string{`integer(8)`}}, {`0b0001_0000`, []string{`integer(16)`}}, {`0b9`, []string{`integer(0)`, `Error: unexpected input (expected end of file) at line 1, column 2`}}, {`0b1_1_0_1_1`, []string{`integer(27)`}}, {`0b11111111_11111111`, []string{`integer(65535)`}}, {`0b01111111_11111111_11111111_11111111_11111111_11111111_11111111_11111111`, []string{`integer(9223372036854775807)`}}, {`0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000`, []string{ `Error: Cannot parse value 0b1000000000000000000000000000000000000000000000000000000000000000: ` + `strconv.ParseInt: parsing "1000000000000000000000000000000000000000000000000000000000000000": ` + `value out of range at line 1, column 74`}}, } { p := &parser{} testParseHandler(t, p, p.startNumber, test) } } func TestFloat(t *testing.T) { for _, test := range []parseTest{ {``, []string{`Error: unexpected end of file (expected a number) at start of file`}}, {`0.0`, []string{`float(0)`}}, {`+0.0`, []string{`float(0)`}}, {`-0.0`, []string{`float(-0)`}}, {`+1.0`, []string{`float(1)`}}, {`3.1415`, []string{`float(3.1415)`}}, {`-0.01`, []string{`float(-0.01)`}}, {`5e+22`, []string{`float(5e+22)`}}, {`1E6`, []string{`float(1e+06)`}}, {`-2E-2`, []string{`float(-0.02)`}}, {`6.626e-34`, []string{`float(6.626e-34)`}}, {`224_617.445_991_228`, []string{`float(224617.445991228)`}}, {`12_345.111_222e+1_2_3`, []string{`float(1.2345111222e+127)`}}, {`+nan`, []string{`float(NaN)`}}, {`-nan`, []string{`float(NaN)`}}, {`nan`, []string{`float(NaN)`}}, {`inf`, []string{`float(+Inf)`}}, {`+inf`, []string{`float(+Inf)`}}, {`-inf`, []string{`float(-Inf)`}}, } { p := &parser{} testParseHandler(t, p, p.startNumber, test) } }