Skip to content

Commit 18f7832

Browse files
Copilot0xrinegade
andcommitted
fix(clippy): fix critical lint errors - ok_or_else, test module order, and simple lints
Co-authored-by: 0xrinegade <[email protected]>
1 parent 09fe81d commit 18f7832

File tree

13 files changed

+111
-118
lines changed

13 files changed

+111
-118
lines changed

crates/ovsm/src/runtime/lisp_evaluator.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4913,13 +4913,11 @@ impl LispEvaluator {
49134913
}
49144914

49154915
// If we don't have &rest or &key, check for exact arg count
4916-
if rest_pos.is_none() && key_pos.is_none() && optional_pos.is_none() {
4917-
if args.len() != required_count {
4918-
return Err(Error::InvalidArguments {
4919-
tool: context.to_string(),
4920-
reason: format!("Expected {} arguments, got {}", required_count, args.len()),
4921-
});
4922-
}
4916+
if rest_pos.is_none() && key_pos.is_none() && optional_pos.is_none() && args.len() != required_count {
4917+
return Err(Error::InvalidArguments {
4918+
tool: context.to_string(),
4919+
reason: format!("Expected {} arguments, got {}", required_count, args.len()),
4920+
});
49234921
}
49244922

49254923
Ok(())

crates/ovsm/src/tools/stdlib/arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Tool for ArefTool {
158158
array
159159
.get(index)
160160
.cloned()
161-
.ok_or_else(|| Error::IndexOutOfBounds {
161+
.ok_or(Error::IndexOutOfBounds {
162162
index,
163163
length: array.len(),
164164
})

crates/ovsm/src/tools/stdlib/bit_operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Tool for MakeBitArrayTool {
3131
});
3232
}
3333

34-
let size = match args.get(0) {
34+
let size = match args.first() {
3535
Some(Value::Int(n)) if *n >= 0 => *n as usize,
3636
Some(Value::Int(n)) => {
3737
return Err(Error::InvalidArguments {
@@ -239,7 +239,7 @@ impl Tool for BitVectorPTool {
239239
"Check if object is bit vector"
240240
}
241241
fn execute(&self, args: &[Value]) -> Result<Value> {
242-
match args.get(0) {
242+
match args.first() {
243243
Some(Value::Array(arr)) => {
244244
let is_bit_vector = arr
245245
.iter()

crates/ovsm/src/tools/stdlib/data_processing.rs

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -808,76 +808,6 @@ impl Tool for TakeTool {
808808
}
809809
}
810810

811-
#[cfg(test)]
812-
mod tests {
813-
use super::*;
814-
815-
#[test]
816-
fn test_sum_tool() {
817-
let tool = SumTool;
818-
let arr = Value::array(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
819-
let result = tool.execute(&[arr]).unwrap();
820-
assert_eq!(result, Value::Int(6));
821-
}
822-
823-
#[test]
824-
fn test_count_tool() {
825-
let tool = CountTool;
826-
let arr = Value::array(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
827-
let result = tool.execute(&[arr]).unwrap();
828-
assert_eq!(result, Value::Int(3));
829-
}
830-
831-
#[test]
832-
fn test_flatten_tool() {
833-
let tool = FlattenTool;
834-
let nested = Value::array(vec![
835-
Value::array(vec![Value::Int(1), Value::Int(2)]),
836-
Value::array(vec![Value::Int(3), Value::Int(4)]),
837-
]);
838-
let result = tool.execute(&[nested]).unwrap();
839-
let expected = vec![Value::Int(1), Value::Int(2), Value::Int(3), Value::Int(4)];
840-
assert_eq!(result, expected);
841-
}
842-
843-
#[test]
844-
fn test_unique_tool() {
845-
let tool = UniqueTool;
846-
let arr = Value::array(vec![
847-
Value::Int(1),
848-
Value::Int(2),
849-
Value::Int(2),
850-
Value::Int(3),
851-
]);
852-
let result = tool.execute(&[arr]).unwrap();
853-
let expected = vec![Value::Int(1), Value::Int(2), Value::Int(3)];
854-
assert_eq!(result, expected);
855-
}
856-
857-
#[test]
858-
fn test_reverse_tool() {
859-
let tool = ReverseTool;
860-
let arr = Value::array(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
861-
let result = tool.execute(&[arr]).unwrap();
862-
let expected = vec![Value::Int(3), Value::Int(2), Value::Int(1)];
863-
assert_eq!(result, expected);
864-
}
865-
866-
#[test]
867-
fn test_first_last_tools() {
868-
let arr = Value::array(vec![Value::Int(10), Value::Int(20), Value::Int(30)]);
869-
870-
let first_tool = FirstTool;
871-
assert_eq!(
872-
first_tool.execute(std::slice::from_ref(&arr)).unwrap(),
873-
Value::Int(10)
874-
);
875-
876-
let last_tool = LastTool;
877-
assert_eq!(last_tool.execute(&[arr]).unwrap(), Value::Int(30));
878-
}
879-
}
880-
881811
// ============================================================================
882812
// Common Lisp List Accessors
883813
// ============================================================================
@@ -1172,3 +1102,73 @@ impl Tool for LengthTool {
11721102
Ok(Value::Int(len as i64))
11731103
}
11741104
}
1105+
1106+
#[cfg(test)]
1107+
mod tests {
1108+
use super::*;
1109+
1110+
#[test]
1111+
fn test_sum_tool() {
1112+
let tool = SumTool;
1113+
let arr = Value::array(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
1114+
let result = tool.execute(&[arr]).unwrap();
1115+
assert_eq!(result, Value::Int(6));
1116+
}
1117+
1118+
#[test]
1119+
fn test_count_tool() {
1120+
let tool = CountTool;
1121+
let arr = Value::array(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
1122+
let result = tool.execute(&[arr]).unwrap();
1123+
assert_eq!(result, Value::Int(3));
1124+
}
1125+
1126+
#[test]
1127+
fn test_flatten_tool() {
1128+
let tool = FlattenTool;
1129+
let nested = Value::array(vec![
1130+
Value::array(vec![Value::Int(1), Value::Int(2)]),
1131+
Value::array(vec![Value::Int(3), Value::Int(4)]),
1132+
]);
1133+
let result = tool.execute(&[nested]).unwrap();
1134+
let expected = vec![Value::Int(1), Value::Int(2), Value::Int(3), Value::Int(4)];
1135+
assert_eq!(result, expected);
1136+
}
1137+
1138+
#[test]
1139+
fn test_unique_tool() {
1140+
let tool = UniqueTool;
1141+
let arr = Value::array(vec![
1142+
Value::Int(1),
1143+
Value::Int(2),
1144+
Value::Int(2),
1145+
Value::Int(3),
1146+
]);
1147+
let result = tool.execute(&[arr]).unwrap();
1148+
let expected = vec![Value::Int(1), Value::Int(2), Value::Int(3)];
1149+
assert_eq!(result, expected);
1150+
}
1151+
1152+
#[test]
1153+
fn test_reverse_tool() {
1154+
let tool = ReverseTool;
1155+
let arr = Value::array(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
1156+
let result = tool.execute(&[arr]).unwrap();
1157+
let expected = vec![Value::Int(3), Value::Int(2), Value::Int(1)];
1158+
assert_eq!(result, expected);
1159+
}
1160+
1161+
#[test]
1162+
fn test_first_last_tools() {
1163+
let arr = Value::array(vec![Value::Int(10), Value::Int(20), Value::Int(30)]);
1164+
1165+
let first_tool = FirstTool;
1166+
assert_eq!(
1167+
first_tool.execute(std::slice::from_ref(&arr)).unwrap(),
1168+
Value::Int(10)
1169+
);
1170+
1171+
let last_tool = LastTool;
1172+
assert_eq!(last_tool.execute(&[arr]).unwrap(), Value::Int(30));
1173+
}
1174+
}

crates/ovsm/src/tools/stdlib/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl Tool for EnvironmentPTool {
343343
"Check if object is environment"
344344
}
345345
fn execute(&self, args: &[Value]) -> Result<Value> {
346-
match args.get(0) {
346+
match args.first() {
347347
Some(Value::Object(_)) => Ok(Value::Bool(true)),
348348
_ => Ok(Value::Bool(false)),
349349
}

crates/ovsm/src/tools/stdlib/multiple_values.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Tool for ValuesCountTool {
189189
"Get number of values returned"
190190
}
191191
fn execute(&self, args: &[Value]) -> Result<Value> {
192-
let count = match args.get(0) {
192+
let count = match args.first() {
193193
Some(Value::Array(arr)) => arr.len(),
194194
Some(_) => 1,
195195
None => 0,
@@ -208,7 +208,7 @@ impl Tool for ExtractPrimaryValueTool {
208208
"Extract only primary value, discard rest"
209209
}
210210
fn execute(&self, args: &[Value]) -> Result<Value> {
211-
match args.get(0) {
211+
match args.first() {
212212
Some(Value::Array(arr)) => Ok(arr.first().cloned().unwrap_or(Value::Null)),
213213
Some(v) => Ok(v.clone()),
214214
None => Ok(Value::Null),
@@ -311,7 +311,7 @@ impl Tool for GetPropertiesTool {
311311
Ok(Value::Array(Arc::new(vec![
312312
Value::Null,
313313
Value::Null,
314-
args.get(0).cloned().unwrap_or(Value::Null),
314+
args.first().cloned().unwrap_or(Value::Null),
315315
])))
316316
}
317317
}
@@ -335,8 +335,8 @@ impl Tool for GetSetfExpansionTool {
335335
Value::Array(Arc::new(vec![])), // vars
336336
Value::Array(Arc::new(vec![])), // vals
337337
Value::Array(Arc::new(vec![])), // stores
338-
args.get(0).cloned().unwrap_or(Value::Null), // writer
339-
args.get(0).cloned().unwrap_or(Value::Null), // reader
338+
args.first().cloned().unwrap_or(Value::Null), // writer
339+
args.first().cloned().unwrap_or(Value::Null), // reader
340340
])))
341341
}
342342
}

crates/ovsm/src/tools/stdlib/packages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl Tool for DescribePackageTool {
531531
"Describe package structure and contents"
532532
}
533533
fn execute(&self, args: &[Value]) -> Result<Value> {
534-
match args.get(0) {
534+
match args.first() {
535535
Some(Value::String(name)) => Ok(Value::String(format!(
536536
"Package: {}\nNicknames: none\nUse list: (COMMON-LISP)\nUsed by: none\nSymbols: 0",
537537
name

crates/ovsm/src/tools/stdlib/random_extended.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Tool for RandomStatePTool {
4040
"Check if object is random state"
4141
}
4242
fn execute(&self, args: &[Value]) -> Result<Value> {
43-
Ok(Value::Bool(matches!(args.get(0), Some(Value::Int(_)))))
43+
Ok(Value::Bool(matches!(args.first(), Some(Value::Int(_)))))
4444
}
4545
}
4646

crates/ovsm/src/tools/stdlib/sequences.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl Tool for EltTool {
129129
chars
130130
.get(index)
131131
.map(|c| Value::String(c.to_string()))
132-
.ok_or_else(|| Error::IndexOutOfBounds {
132+
.ok_or(Error::IndexOutOfBounds {
133133
index,
134134
length: chars.len(),
135135
})
@@ -827,7 +827,7 @@ impl Tool for UnionTool {
827827
let list1 = args[0].as_array()?;
828828
let list2 = args[1].as_array()?;
829829

830-
let mut result: Vec<Value> = list1.iter().cloned().collect();
830+
let mut result: Vec<Value> = list1.to_vec();
831831

832832
for elem in list2.iter() {
833833
if !result.contains(elem) {
@@ -1661,9 +1661,7 @@ impl Tool for ReplaceToolSeq {
16611661
let seq2 = args[1].as_array()?;
16621662
let len = seq1.len().min(seq2.len());
16631663
let mut result = seq1.to_vec();
1664-
for i in 0..len {
1665-
result[i] = seq2[i].clone();
1666-
}
1664+
result[..len].clone_from_slice(&seq2[..len]);
16671665
Ok(Value::Array(Arc::new(result)))
16681666
}
16691667
}

crates/ovsm/src/tools/stdlib/sequences_advanced.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl Tool for FillPointerTool {
252252
"Get or set array fill pointer"
253253
}
254254
fn execute(&self, args: &[Value]) -> Result<Value> {
255-
match args.get(0) {
255+
match args.first() {
256256
Some(Value::Array(arr)) => Ok(Value::Int(arr.len() as i64)),
257257
_ => Ok(Value::Null),
258258
}

0 commit comments

Comments
 (0)