Skip to content

Commit 18beec6

Browse files
committed
clean up and tweak substr tests
1 parent 9628217 commit 18beec6

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/lib/unlang/xlat_builtin.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3475,7 +3475,8 @@ static xlat_action_t xlat_func_substr(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED
34753475
memcpy(buf, &in->vb_octets[start], len);
34763476
}
34773477
break;
3478-
default:
3478+
3479+
default: /* 'in' was cast to #FR_TYPE_STRING */
34793480
fr_assert(0);
34803481
}
34813482

src/tests/keywords/substr

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,54 @@ test_string = "hello world"
99
test_octets = 0x01234567
1010
test_int = 123456
1111

12-
if !(%str.substr(%{test_string}, 1, 3) == 'ell') {
12+
if !(%str.substr(test_string, 1, 3) == 'ell') {
1313
test_fail
1414
}
1515

16-
if !(%str.substr(%{test_string}, 0, 3) == 'hel') {
16+
if !(%str.substr(test_string, 0, 3) == 'hel') {
1717
test_fail
1818
}
1919

20-
if !(%str.substr(%{test_string}, 5) == ' world') {
20+
if !(%str.substr(test_string, 5) == ' world') {
2121
test_fail
2222
}
2323

24-
if !(%str.substr(%{test_string}, -3) == 'rld') {
24+
if !(%str.substr(test_string, -3) == 'rld') {
2525
test_fail
2626
}
2727

28-
if !(%str.substr(%{test_string}, -20) == 'hello world') {
28+
if !(%str.substr(test_string, -20) == 'hello world') {
2929
test_fail
3030
}
3131

32-
if !(%str.substr(%{test_string}, -4, 2) == 'or') {
32+
if !(%str.substr(test_string, -4, 2) == 'or') {
3333
test_fail
3434
}
3535

36-
if !(%str.substr(%{test_string}, -10, -3) == 'ello wo') {
36+
if !(%str.substr(test_string, -10, -3) == 'ello wo') {
3737
test_fail
3838
}
3939

40-
if (%str.substr(%{test_string}, 20)) {
40+
if (%str.substr(test_string, 20)) {
4141
test_fail
4242
}
4343

44-
if (%str.substr(%{test_string}, 5, -7)) {
44+
if (%str.substr(test_string, 5, -7)) {
4545
test_fail
4646
}
4747

48-
if !(%str.substr(%{test_octets}, 1, 2) == 0x2345) {
48+
if !(%str.substr(test_octets, 1, 2) == 0x2345) {
4949
test_fail
5050
}
5151

52-
if !(%str.substr(%{test_int}, 1, 2) == '23') {
52+
if !(%str.substr(test_int, 1, 2) == '23') {
53+
test_fail
54+
}
55+
56+
#
57+
# 123456 = 0x0001e240 in network byte order.
58+
#
59+
if !(%str.substr((octets) test_int, 1, 2) == 0x01e2) {
5360
test_fail
5461
}
5562

0 commit comments

Comments
 (0)