Skip to content

Commit 0278c73

Browse files
authored
[variable-length-quantity] Add a Jinja test template (#876)
[no important files changed]
1 parent 3326ae9 commit 0278c73

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{ header }}
2+
3+
#
4+
# *** Input and Output numbers are expressed in hexadecimal.
5+
#
6+
7+
{% for idx, case in cases %}
8+
@test "{{ case["description"] }}" {
9+
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
10+
{%- set hex_input = [] %}
11+
{%- for num in case["input"]["integers"] %}
12+
{%- set _ = hex_input.append('%02X' % num) %}
13+
{%- endfor %}
14+
run bash {{ solution }} {{ case["property"] }} {{ hex_input | join(" ") }}
15+
{%- if case["expect_error"] %}
16+
assert_failure
17+
{#- The error message from the canonical data is not used. #}
18+
assert_output --partial "incomplete byte sequence"
19+
{%- else %}
20+
{%- set hex_output = [] %}
21+
{%- for num in case["expected"] %}
22+
{%- set _ = hex_output.append('%02X' % num) %}
23+
{%- endfor %}
24+
assert_success
25+
assert_output "{{ hex_output | join(" ") }}"
26+
{%- endif %}
27+
}
28+
{% endfor %}
29+
30+
@test "invalid subcommand" {
31+
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
32+
run bash variable_length_quantity.sh hello 80
33+
assert_failure
34+
assert_output --partial "unknown subcommand"
35+
}

exercises/practice/variable-length-quantity/variable_length_quantity.bats

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bats
22
load bats-extra
33

4+
# generated on 2026-06-29T19:27:37+00:00
5+
46
#
57
# *** Input and Output numbers are expressed in hexadecimal.
68
#
79

810

9-
# Encode a series of integers, producing a series of bytes.
10-
1111
@test "zero" {
12-
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
12+
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
1313
run bash variable_length_quantity.sh encode 00
1414
assert_success
1515
assert_output "00"
@@ -26,7 +26,7 @@ load bats-extra
2626
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
2727
run bash variable_length_quantity.sh encode 53
2828
assert_success
29-
assert_output 53
29+
assert_output "53"
3030
}
3131

3232
@test "largest single byte" {
@@ -169,9 +169,6 @@ load bats-extra
169169
assert_output "C0 00 C8 E8 56 FF FF FF 7F 00 FF 7F 81 80 00"
170170
}
171171

172-
173-
# Decode a series of bytes, producing a series of integers.
174-
175172
@test "one byte" {
176173
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
177174
run bash variable_length_quantity.sh decode 7F
@@ -207,16 +204,6 @@ load bats-extra
207204
assert_output "FFFFFFFF"
208205
}
209206

210-
@test "multiple values" {
211-
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
212-
run bash variable_length_quantity.sh decode C0 00 C8 E8 56 FF FF FF 7F 00 FF 7F 81 80 00
213-
assert_success
214-
assert_output "2000 123456 FFFFFFF 00 3FFF 4000"
215-
}
216-
217-
218-
# Some error conditions
219-
220207
@test "incomplete sequence causes error" {
221208
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
222209
run bash variable_length_quantity.sh decode FF
@@ -231,6 +218,14 @@ load bats-extra
231218
assert_output --partial "incomplete byte sequence"
232219
}
233220

221+
@test "multiple values" {
222+
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
223+
run bash variable_length_quantity.sh decode C0 00 C8 E8 56 FF FF FF 7F 00 FF 7F 81 80 00
224+
assert_success
225+
assert_output "2000 123456 FFFFFFF 00 3FFF 4000"
226+
}
227+
228+
234229
@test "invalid subcommand" {
235230
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
236231
run bash variable_length_quantity.sh hello 80

0 commit comments

Comments
 (0)