diff --git a/src/lenient_parse/internal/build.gleam b/src/lenient_parse/internal/build.gleam index ac9b8c5..10b5415 100644 --- a/src/lenient_parse/internal/build.gleam +++ b/src/lenient_parse/internal/build.gleam @@ -8,10 +8,10 @@ pub fn float_value( is_positive is_positive: Bool, whole_digits whole_digits: Queue(Int), fractional_digits fractional_digits: Queue(Int), - exponent exponent: Int, + scale_factor scale_factor: Int, ) -> Float { let #(whole_digits, fractional_digits) = - scale.queues(whole_digits, fractional_digits, exponent) + scale.queues(whole_digits, fractional_digits, scale_factor) let fractional_digits_length = fractional_digits |> queue.length let #(all_digits, _) = scale.queues(whole_digits, fractional_digits, fractional_digits_length) diff --git a/src/lenient_parse/internal/parser.gleam b/src/lenient_parse/internal/parser.gleam index 191efaf..a0c6d95 100644 --- a/src/lenient_parse/internal/parser.gleam +++ b/src/lenient_parse/internal/parser.gleam @@ -105,7 +105,7 @@ pub fn parse_float(tokens tokens: List(Token)) -> Result(Float, ParseError) { is_positive: is_positive, whole_digits: whole_digits, fractional_digits: fractional_digits, - exponent: exponent, + scale_factor: exponent, )) } } diff --git a/test/build_test.gleam b/test/build_test.gleam new file mode 100644 index 0000000..ac40309 --- /dev/null +++ b/test/build_test.gleam @@ -0,0 +1,43 @@ +import gleam/queue +import lenient_parse/internal/build +import startest/expect + +pub fn build_float_empty_fractional_test() { + build.float_value( + is_positive: True, + whole_digits: queue.from_list([1]), + fractional_digits: queue.from_list([]), + scale_factor: 0, + ) + |> expect.to_equal(1.0) +} + +pub fn build_float_explicit_0_fractional_test() { + build.float_value( + is_positive: True, + whole_digits: queue.from_list([1]), + fractional_digits: queue.from_list([0]), + scale_factor: 0, + ) + |> expect.to_equal(1.0) +} + +pub fn build_float_empty_whole_test() { + build.float_value( + is_positive: True, + whole_digits: queue.from_list([]), + fractional_digits: queue.from_list([1]), + scale_factor: 0, + ) + |> expect.to_equal(0.1) +} + +pub fn build_float_explicit_0_whole_test() { + build.float_value( + is_positive: True, + whole_digits: queue.from_list([0]), + fractional_digits: queue.from_list([1]), + scale_factor: 0, + ) + |> expect.to_equal(0.1) +}