Skip to content

Commit a2b5fff

Browse files
committed
Resolve remarks Steve
1 parent da7eb67 commit a2b5fff

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

dsc_lib/src/functions/first.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod tests {
5555
fn array_of_strings() {
5656
let mut parser = Statement::new().unwrap();
5757
let result = parser.parse_and_execute("[first(createArray('hello', 'world'))]", &Context::new()).unwrap();
58-
assert_eq!(result.to_string(), "\"hello\"");
58+
assert_eq!(result.as_str(), Some("hello"));
5959
}
6060

6161
#[test]
@@ -69,21 +69,21 @@ mod tests {
6969
fn array_of_mixed() {
7070
let mut parser = Statement::new().unwrap();
7171
let result = parser.parse_and_execute("[first(array('hello', 42))]", &Context::new()).unwrap();
72-
assert_eq!(result.to_string(), "\"hello\"");
72+
assert_eq!(result.as_str(), Some("hello"));
7373
}
7474

7575
#[test]
7676
fn string_input() {
7777
let mut parser = Statement::new().unwrap();
7878
let result = parser.parse_and_execute("[first('hello')]", &Context::new()).unwrap();
79-
assert_eq!(result.to_string(), "\"h\"");
79+
assert_eq!(result.as_str(), Some("h"));
8080
}
8181

8282
#[test]
8383
fn single_character_string() {
8484
let mut parser = Statement::new().unwrap();
8585
let result = parser.parse_and_execute("[first('a')]", &Context::new()).unwrap();
86-
assert_eq!(result.to_string(), "\"a\"");
86+
assert_eq!(result.as_str(), Some("a"));
8787
}
8888

8989
#[test]

dsc_lib/src/functions/index_of.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,14 @@ impl Function for IndexOf {
3131
fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
3232
debug!("{}", t!("functions.indexOf.invoked"));
3333

34-
let array = args[0].as_array().ok_or_else(|| {
35-
DscError::Parser(t!("functions.indexOf.invalidArrayArg").to_string())
36-
})?;
34+
let Some(array) = args[0].as_array() else {
35+
return Err(DscError::Parser(t!("functions.indexOf.invalidArrayArg").to_string()));
36+
};
3737

3838
let item_to_find = &args[1];
3939

4040
for (index, item) in array.iter().enumerate() {
41-
let matches = match (item_to_find, item) {
42-
// String comparison (case-sensitive)
43-
(Value::String(find_str), Value::String(item_str)) => find_str == item_str,
44-
(Value::Number(find_num), Value::Number(item_num)) => find_num == item_num,
45-
(Value::Array(find_arr), Value::Array(item_arr)) => find_arr == item_arr,
46-
(Value::Object(find_obj), Value::Object(item_obj)) => find_obj == item_obj,
47-
_ => false,
48-
};
49-
50-
if matches {
41+
if item == item_to_find {
5142
let index_i64 = i64::try_from(index).map_err(|_| {
5243
DscError::Parser("Array index too large to represent as integer".to_string())
5344
})?;

tree-sitter-dscexpression/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Rust artifacts
22
target/
3-
Cargo.lock
43

54
# Node artifacts
65
build/

0 commit comments

Comments
 (0)