Skip to content

Commit 5a972d4

Browse files
committed
test: use qcheck.given with use syntax in property tests
1 parent bbb936d commit 5a972d4

1 file changed

Lines changed: 25 additions & 32 deletions

File tree

test/unitest/internal/discover_test.gleam

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,44 +112,37 @@ pub fn tags_scoped_to_function_test() {
112112

113113
pub fn byte_offset_to_line_always_positive_property_test() {
114114
let gen = qcheck.tuple2(qcheck.bounded_int(1, 100), qcheck.bounded_int(0, 50))
115-
qcheck.run(qcheck.default_config(), gen, fn(pair) {
116-
let #(line_count, offset_within) = pair
117-
let source =
118-
list.repeat("line", line_count)
119-
|> string.join("\n")
120-
let max_offset = string.byte_size(source) - 1
121-
let offset = int.clamp(offset_within, 0, int.max(0, max_offset))
122-
assert discover.byte_offset_to_line(source, offset) >= 1
123-
})
115+
use pair <- qcheck.given(gen)
116+
let #(line_count, offset_within) = pair
117+
let source =
118+
list.repeat("line", line_count)
119+
|> string.join("\n")
120+
let max_offset = string.byte_size(source) - 1
121+
let offset = int.clamp(offset_within, 0, int.max(0, max_offset))
122+
assert discover.byte_offset_to_line(source, offset) >= 1
124123
}
125124

126125
pub fn byte_offset_to_line_offset_zero_is_line_one_property_test() {
127-
qcheck.run(
128-
qcheck.default_config(),
129-
qcheck.bounded_int(1, 100),
130-
fn(line_count) {
131-
let source =
132-
list.repeat("line", line_count)
133-
|> string.join("\n")
134-
assert discover.byte_offset_to_line(source, 0) == 1
135-
},
136-
)
126+
use line_count <- qcheck.given(qcheck.bounded_int(1, 100))
127+
let source =
128+
list.repeat("line", line_count)
129+
|> string.join("\n")
130+
assert discover.byte_offset_to_line(source, 0) == 1
137131
}
138132

139133
pub fn byte_offset_to_line_monotonic_property_test() {
140-
qcheck.run(qcheck.default_config(), qcheck.bounded_int(2, 50), fn(line_count) {
141-
let source =
142-
list.repeat("abcd", line_count)
143-
|> string.join("\n")
144-
let first_newline = 4
145-
let second_newline = 9
146-
let before_first = discover.byte_offset_to_line(source, first_newline - 1)
147-
let after_first = discover.byte_offset_to_line(source, first_newline + 1)
148-
let after_second = discover.byte_offset_to_line(source, second_newline + 1)
149-
assert before_first == 1
150-
assert after_first == 2
151-
assert after_second >= after_first
152-
})
134+
use line_count <- qcheck.given(qcheck.bounded_int(2, 50))
135+
let source =
136+
list.repeat("abcd", line_count)
137+
|> string.join("\n")
138+
let first_newline = 4
139+
let second_newline = 9
140+
let before_first = discover.byte_offset_to_line(source, first_newline - 1)
141+
let after_first = discover.byte_offset_to_line(source, first_newline + 1)
142+
let after_second = discover.byte_offset_to_line(source, second_newline + 1)
143+
assert before_first == 1
144+
assert after_first == 2
145+
assert after_second >= after_first
153146
}
154147

155148
pub fn parse_module_captures_byte_spans_test() {

0 commit comments

Comments
 (0)