Skip to content

Commit

Permalink
Organize tests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons authored Oct 17, 2024
1 parent ca3fc32 commit da3653f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 53 deletions.
82 changes: 33 additions & 49 deletions test/coerce_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,35 @@ import startest/expect
pub fn coerce_into_valid_number_string_tests() {
describe("coerce_into_valid_number_string_test", [
describe(
"should_error_as_whitespace_only_or_empty_string",
"should_coerce",
[
#("0", "0"),
#("0.0", "0.0"),
#(".1", "0.1"),
#("1.", "1.0"),
#("+1000", "+1000"),
#("-1000", "-1000"),
#(" 1000 ", "1000"),
#(" -1000 ", "-1000"),
#("+1.0", "+1.0"),
#("-1.0", "-1.0"),
#("1_000", "1000"),
#("1_000_000", "1000000"),
#("1_000_000.0", "1000000.0"),
#("1_000_000.000_1", "1000000.0001"),
#("1000.000_000", "1000.000000"),
]
|> list.map(fn(pair) {
let #(input, output) = pair
use <- it("\"" <> input <> "\" -> \"" <> output <> "\"")

input
|> coerce_into_valid_number_string
|> expect.to_equal(Ok(output))
}),
),
describe(
"has_invalid_whitespace",
["", " ", "\t", "\n", "\r", "\f", " \t\n\r\f "]
|> list.map(fn(text) {
let printable_text = text |> into_printable_text
Expand All @@ -35,18 +63,6 @@ pub fn coerce_into_valid_number_string_tests() {
|> expect.to_equal(Error(InvalidCharacter(invalid_character)))
}),
),
describe(
"has_valid_sign_position",
[#("+1", "+1"), #("-1", "-1"), #("+1.0", "+1.0"), #("-1.0", "-1.0")]
|> list.map(fn(pair) {
let #(input, output) = pair
use <- it("\"" <> output <> "\" in \"" <> input <> "\"")

input
|> coerce_into_valid_number_string
|> expect.to_equal(Ok(output))
}),
),
describe(
"has_invalid_sign_position",
[#("1+", "+"), #("1-", "-"), #("1+1", "+"), #("1-1", "-")]
Expand All @@ -63,17 +79,6 @@ pub fn coerce_into_valid_number_string_tests() {
)
}),
),
describe(
"has_valid_decimal_position",
[#(".1", "0.1"), #("1.", "1.0")]
|> list.map(fn(pair) {
let #(input, output) = pair
use <- it("\"" <> input <> "\"")
input
|> coerce_into_valid_number_string
|> expect.to_equal(Ok(output))
}),
),
describe(
"has_invalid_decimal_position",
[".", "..", "0.0.", ".0.0"]
Expand All @@ -84,38 +89,17 @@ pub fn coerce_into_valid_number_string_tests() {
|> expect.to_equal(Error(InvalidDecimalPosition))
}),
),
describe(
"has_valid_underscore_position",
[
#("0", "0"),
#("0.0", "0.0"),
#("+1000", "+1000"),
#("-1000", "-1000"),
#(" 1000 ", "1000"),
#(" -1000 ", "-1000"),
#("1_000", "1000"),
#("1_000_000", "1000000"),
#("1_000_000.0", "1000000.0"),
#("1_000_000.000_1", "1000000.0001"),
#("1000.000_000", "1000.000000"),
]
|> list.map(fn(pair) {
let #(input, output) = pair
use <- it("\"" <> input <> "\" -> \"" <> output <> "\"")

input
|> coerce_into_valid_number_string
|> expect.to_equal(Ok(output))
}),
),
describe(
"has_invalid_underscore_position",
[
"_", "_1000", "1000_", "+_1000", "-_1000", "1__000", "1_.000", "1._000",
"_1000.0", "1000.0_", "1000._0", "1000_.0", "1000_.",
]
|> list.map(fn(text) {
use <- it("\"" <> text <> "\"")
let error = InvalidUnderscorePosition
let error_text = error |> parse_error.to_string

use <- it("\"" <> text <> "\" -> " <> error_text)

text
|> coerce_into_valid_number_string
Expand Down
4 changes: 2 additions & 2 deletions test/to_float_parse_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import startest/expect
pub fn coerce_into_valid_number_string_tests() {
describe("float_test", [
describe(
"should_coerce_to_float",
"should_coerce",
[
#("1.001", 1.001),
#("1.00", 1.0),
Expand All @@ -37,7 +37,7 @@ pub fn coerce_into_valid_number_string_tests() {
}),
),
describe(
"should_not_coerce_to_float",
"should_not_coerce",
[
#("1_000__000.0", InvalidUnderscorePosition),
#("..1", InvalidDecimalPosition),
Expand Down
4 changes: 2 additions & 2 deletions test/to_int_parse_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import startest/expect
pub fn coerce_into_valid_number_string_tests() {
describe("int_test", [
describe(
"should_coerce_to_int",
"should_coerce",
[
#("1", 1),
#("+123", 123),
Expand All @@ -31,7 +31,7 @@ pub fn coerce_into_valid_number_string_tests() {
}),
),
describe(
"should_not_coerce_to_int",
"should_not_coerce",
[
#("1_000__000", InvalidUnderscorePosition),
#("1.", GleamIntParseError),
Expand Down

0 comments on commit da3653f

Please sign in to comment.