Repository: CSML-by-Clevy/csml-engine (rust)

Issue:
slice() does not accept 0 as first parameter
**Describe the bug**
Slice returns the following error when trying to pass 0 as first parameter
`.slice(start, optional) args need to be inferior to the string length at line 6, column 12 at flow [Default]`

**To Reproduce**
Check this code https://play.csml.dev/bot/2874f635-3fa2-4154-a760-4d65dee6c3f7

**Expected behavior**
It should accept 0 as first parameter



Pull request description:
fix: string method slice
Fixes #323 

## Proposed Changes

- accept 0 as starting value for string slice



Patch:
diff --git a/csml_interpreter/src/data/primitive/string.rs b/csml_interpreter/src/data/primitive/string.rs
index f5876e89..a879abdf 100644
--- a/csml_interpreter/src/data/primitive/string.rs
+++ b/csml_interpreter/src/data/primitive/string.rs
@@ -809,12 +809,12 @@ impl PrimitiveString {
                     )?
                     .to_owned();
 
-                    if int_start.is_negative() {
+                    if int_start < 0 {
                         int_start = len as i64 + int_start;
                     }
 
                     let start = match int_start {
-                        value if value.is_positive() && (value as usize) < len => value as usize,
+                        value if value >= 0 && (value as usize) < len => value as usize,
                         _ => {
                             return Err(gen_error_info(
                                 Position::new(interval, &data.context.flow),
@@ -849,7 +849,7 @@ impl PrimitiveString {
                     )?
                     .to_owned();
 
-                    if int_start.is_negative() {
+                    if int_start < 0 {
                         int_start = len as i64 + int_start;
                     }
 
@@ -865,8 +865,8 @@ impl PrimitiveString {
 
                     let (start, end) = match (int_start, int_end) {
                         (start, end)
-                            if start.is_positive()
-                                && end.is_positive()
+                            if int_start >= 0
+                                && end >= 0
                                 && (start as usize) < len
                                 && (end as usize) <= len =>
                         {


Test patch:
diff --git a/csml_interpreter/CSML/basic_test/stdlib/string.csml b/csml_interpreter/CSML/basic_test/stdlib/string.csml
index 0a1d4add..e7619382 100644
--- a/csml_interpreter/CSML/basic_test/stdlib/string.csml
+++ b/csml_interpreter/CSML/basic_test/stdlib/string.csml
@@ -84,4 +84,8 @@ step_11:
     say toto[0].is_number()
     say toto
 
+    goto end
+
+step_12_slice:
+    say "Hello World".slice(0, 3)
     goto end
\ No newline at end of file
diff --git a/csml_interpreter/tests/string.rs b/csml_interpreter/tests/string.rs
index 9f3a471f..5dd95193 100644
--- a/csml_interpreter/tests/string.rs
+++ b/csml_interpreter/tests/string.rs
@@ -277,3 +277,30 @@ fn string_step_11() {
 
     assert_eq!(v1, v2)
 }
+
+
+#[test]
+fn string_step_12_slice() {
+    let data = r#"{
+        "memories":[],
+        "messages":[
+            {"content_type":"text", "content":{"text": "Hel"}}
+        ]}"#;
+    let msg = format_message(
+        Event::new("payload", "", serde_json::json!({})),
+        Context::new(
+            HashMap::new(),
+            HashMap::new(),
+            None,
+            None,
+            "step_12_slice",
+            "flow",
+        ),
+        "CSML/basic_test/stdlib/string.csml",
+    );
+
+    let v1: Value = message_to_json_value(msg);
+    let v2: Value = serde_json::from_str(data).unwrap();
+
+    assert_eq!(v1, v2)
+}