Skip to content

Commit

Permalink
src/swi_analyse_metta/convert_rust_tests_to_metta_tests_prompt.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Sep 1, 2024
1 parent 32aa292 commit 1520da8
Show file tree
Hide file tree
Showing 5 changed files with 3,745 additions and 491 deletions.
182 changes: 182 additions & 0 deletions src/swi_analyse_metta/convert_rust_tests_to_metta_tests_prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
This template shows the format you need for converting Rust test code into Metta-compatible syntax, with the original Rust code included as comments.

### Template Example:

```rust
;; Original:
;; #[test]
;; fn metta_type_cast() {
;; assert_eq!(run_program("(: a A) !(eval (type-cast a A &self))"), Ok(vec![vec![expr!("a")]]));
;; assert_eq!(run_program("(: a A) !(eval (type-cast a B &self))"), Ok(vec![vec![expr!("Error" "a" "BadType")]]));
;; assert_eq!(run_program("(: a A) !(eval (type-cast a %Undefined% &self))"), Ok(vec![vec![expr!("a")]]));
;; assert_eq!(run_program("!(eval (type-cast a B &self))"), Ok(vec![vec![expr!("a")]]));
;; assert_eq!(run_program("!(eval (type-cast 42 Number &self))"), Ok(vec![vec![expr!({Number::Integer(42)})]]));
;; assert_eq!(run_program("!(eval (type-cast 42 %Undefined% &self))"), Ok(vec![vec![expr!({Number::Integer(42)})]]));
;; assert_eq!(run_program("(: a A) !(eval (type-cast a Atom &self))"), Ok(vec![vec![expr!("a")]]));
;; assert_eq!(run_program("(: a A) !(eval (type-cast a Symbol &self))"), Ok(vec![vec![expr!("a")]]));
;; assert_eq!(run_program("!(eval (type-cast 42 Grounded &self))"), Ok(vec![vec![expr!({Number::Integer(42)})]]));
;; assert_eq!(run_program("!(eval (type-cast () Expression &self))"), Ok(vec![vec![expr!()]]));
;; assert_eq!(run_program("!(eval (type-cast (a b) Expression &self))"), Ok(vec![vec![expr!("a" "b")]]));
;; }

;; Converted:
!(assertEqual (eval (type-cast a A &self)) (a))
!(assertEqual (eval (type-cast a B &self)) ("Error" "a" "BadType"))
!(assertEqual (eval (type-cast a %Undefined% &self)) (a))
!(assertEqual (eval (type-cast 42 Number &self)) ({Number::Integer(42)}))
!(assertEqual (eval (type-cast 42 %Undefined% &self)) ({Number::Integer(42)}))
!(assertEqual (eval (type-cast a Atom &self)) (a))
!(assertEqual (eval (type-cast a Symbol &self)) (a))
!(assertEqual (eval (type-cast 42 Grounded &self)) ({Number::Integer(42)}))
!(assertEqual (eval (type-cast () Expression &self)) ())
!(assertEqual (eval (type-cast (a b) Expression &self)) (a b))
```

---

```rust
;; Original:
;; #[test]
;; fn test_quote() {
;; let metta = Metta::new(Some(EnvBuilder::test_env()));
;; let parser = SExprParser::new("
;; (= (foo) a)
;; (= (foo) b)
;; !(foo)
;; !(quote (foo))
;; ");
;;
;; assert_eq_metta_results!(metta.run(parser),
;; Ok(vec![
;; vec![expr!("a"), expr!("b")],
;; vec![expr!("quote" ("foo"))],
;; ]));
;; }

;; Converted:
(= (foo) a)
(= (foo) b)
!(assertEqualToResults (foo) (a b))
!(assertEqualToResults (quote (foo)) (quote (foo)))
```

---

```rust
;; Original:
;; #[test]
;; fn trace_op() {
;; assert_eq!(TraceOp{}.execute(&mut vec![sym!("\"Here?\""), sym!("42")]),
;; Ok(vec![sym!("42")]));
;; }

;; Converted:
!(assertEqual (trace! "Here?" 42) 42)
```

---

```rust
;; Original:
;; #[test]
;; fn intersection_op() {
;; let space = DynSpace::new(metta_space("
;; (= (foo) Z)
;; (= (foo) (A (B C)))
;; (= (foo) (f g))
;; (= (bar) (f g))
;; (= (bar) (A (B C)))
;; (= (bar) p)
;; (= (bar) (Q a))
;; (= (bar) Z)
;;
;; (= (nsl) 5)
;; (= (nsl) 4)
;; (= (nsl) 3)
;; (= (nsl) 2)
;; (= (nsr) 5)
;; (= (nsr) 3)
;; "));
;; let intersection_op = IntersectionOp::new(space);
;; let actual = intersection_op.execute(&mut vec![expr!(("foo")), expr!(("bar"))]).unwrap();
;; assert_eq_no_order!(actual,
;; vec![expr!("A" ("B" "C")), expr!("f" "g"), expr!("Z")]);
;;
;; assert_eq_no_order!(intersection_op.execute(&mut vec![expr!(("nsl")), expr!(("nsr"))]).unwrap(),
;; vec![expr!("5"), expr!("3")]);
;; }

;; Converted:
(= (foo) Z)
(= (foo) (A (B C)))
(= (foo) (f g))
(= (bar) (f g))
(= (bar) (A (B C)))
(= (bar) p)
(= (bar) (Q a))
(= (bar) Z)
(= (nsl) 5)
(= (nsl) 4)
(= (nsl) 3)
(= (nsl) 2)
(= (nsr) 5)
(= (nsr) 3)
!(assertEqualNoOrder (intersection (foo) (bar)) ((A (B C)) (f g) Z))
!(assertEqualNoOrder (intersection (nsl) (nsr)) (5 3))
```

---

### Final Prompt Example:

With these examples, you can build a comprehensive prompt for future Rust-to-Metta conversions:

---

**Prompt:**

I have some Rust test code that I need to convert into Metta-compatible syntax. The format should include the original Rust code as comments and the converted Metta syntax below. The converted code should look like the examples below:

```rust
;; Original:
;; #[test]
;; fn trace_op() {
;; assert_eq!(TraceOp{}.execute(&mut vec![sym!("\"Here?\""), sym!("42")]),
;; Ok(vec![sym!("42")]));
;; }

;; Converted:
!(assertEqual (trace! "Here?" 42) 42)
```

```rust
;; Original:
;; #[test]
;; fn test_quote() {
;; let metta = Metta::new(Some(EnvBuilder::test_env()));
;; let parser = SExprParser::new("
;; (= (foo) a)
;; (= (foo) b)
;; !(foo)
;; !(quote (foo))
;; ");

;; assert_eq_metta_results!(metta.run(parser),
;; Ok(vec![
;; vec![expr!("a"), expr!("b")],
;; vec![expr!("quote" ("foo"))],
;; ]));
;; }

;; Converted:
(= (foo) a)
(= (foo) b)
!(assertEqualToResults (foo) (a b))
!(assertEqualToResults (quote (foo)) (quote (foo)))
```

Here is the Rust code to convert:

<Insert Rust Code Here>


Loading

0 comments on commit 1520da8

Please sign in to comment.