Skip to content

Commit 90a6b65

Browse files
committed
Convert function to accept only array
1 parent 71b5b3a commit 90a6b65

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

docs/reference/schemas/config/functions/join.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: join
77

88
## Synopsis
99

10-
Joins a string array into a single string, separated using a delimiter.
10+
Joins an array into a single string, separated using a delimiter.
1111

1212
## Syntax
1313

@@ -17,14 +17,12 @@ join(inputArray, delimiter)
1717

1818
## Description
1919

20-
The `join()` function takes either an array or a string and a delimiter.
20+
The `join()` function takes an array and a delimiter.
2121

22-
- If `inputArray` is an array, each element is converted to a string and
23-
concatenated with the delimiter between elements.
24-
- If `inputArray` is a string, its characters are joined with the delimiter
25-
between each character.
22+
- Each array element is converted to a string and concatenated with the
23+
delimiter between elements.
2624

27-
The `delimiter` can be any value; it is converted to a string.
25+
The `delimiter` can be any value; it’s converted to a string.
2826

2927
## Examples
3028

@@ -123,17 +121,17 @@ hadErrors: false
123121
124122
### inputArray
125123
126-
An array or a string.
124+
The array whose elements will be concatenated.
127125
128126
```yaml
129-
Type: array | string
127+
Type: array
130128
Required: true
131129
Position: 1
132130
```
133131
134132
### delimiter
135133
136-
Any value used between elements/characters. Converted to a string.
134+
Any value used between elements. Converted to a string.
137135
138136
```yaml
139137
Type: any

dsc/tests/dsc_functions.tests.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ Describe 'tests for function expressions' {
411411

412412
It 'join function works for: <expression>' -TestCases @(
413413
@{ expression = "[join(createArray('a','b','c'), '-')]"; expected = 'a-b-c' }
414-
@{ expression = "[join('abc', '-')]"; expected = 'a-b-c' }
415414
@{ expression = "[join(createArray(), '-')]"; expected = '' }
416-
@{ expression = "[join('', '-')]"; expected = '' }
417415
) {
418416
param($expression, $expected)
419417

dsc_lib/locales/en-us.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ invoked = "indexOf function"
324324
invalidArrayArg = "First argument must be an array"
325325

326326
[functions.join]
327-
description = "Joins a string array into a single string, separated using a delimiter."
327+
description = "Joins the elements of an array into a single string, separated using a delimiter."
328328
invoked = "join function"
329-
invalidInputType = "The inputArray must be an array or a string."
329+
invalidArrayArg = "First argument must be an array"
330330

331331
[functions.length]
332332
description = "Returns the length of a string, array, or object"

dsc_lib/src/functions/join.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Function for Join {
2929
min_args: 2,
3030
max_args: 2,
3131
accepted_arg_ordered_types: vec![
32-
vec![FunctionArgKind::Array, FunctionArgKind::String],
32+
vec![FunctionArgKind::Array],
3333
// delimiter: accept any type (no validation), convert to string
3434
vec![
3535
FunctionArgKind::Array,
@@ -55,14 +55,7 @@ impl Function for Join {
5555
return Ok(Value::String(items.join(&delimiter)));
5656
}
5757

58-
if let Some(s) = args[0].as_str() {
59-
// Edge case: empty string => empty string
60-
if s.is_empty() { return Ok(Value::String(String::new())); }
61-
let items: Vec<String> = s.chars().map(|c| c.to_string()).collect();
62-
return Ok(Value::String(items.join(&delimiter)));
63-
}
64-
65-
Err(DscError::Parser(t!("functions.join.invalidInputType").to_string()))
58+
Err(DscError::Parser(t!("functions.join.invalidArrayArg").to_string()))
6659
}
6760
}
6861

@@ -79,9 +72,9 @@ mod tests {
7972
}
8073

8174
#[test]
82-
fn join_string_chars() {
75+
fn join_empty_array_returns_empty() {
8376
let mut parser = Statement::new().unwrap();
84-
let result = parser.parse_and_execute("[join('abc', '-')]", &Context::new()).unwrap();
85-
assert_eq!(result, "a-b-c");
77+
let result = parser.parse_and_execute("[join(createArray(), '-')]", &Context::new()).unwrap();
78+
assert_eq!(result, "");
8679
}
8780
}

0 commit comments

Comments
 (0)