Download test/emojiscript_tests.cljs from Snapkitty/snapkitty-clojure-lisp-bridge: direct link, hf CLI and curl.
- Browser
- Download file 8.27 kB
-
https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/test/emojiscript_tests.cljs
- Command line
-
hf download hf://Snapkitty/snapkitty-clojure-lisp-bridge/test/emojiscript_tests.cljs
-
curl -L -o emojiscript_tests.cljs https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/test/emojiscript_tests.cljs
8.27 kB
| (ns snapkitty.lisp.test.emojiscript-tests | |
| "EmojiScript compiler + executor tests" | |
| (:require [cljs.test :refer [deftest is testing]] | |
| [snapkitty.lisp.emojiscript :as emoji])) | |
| ;; ============================================================================ | |
| ;; Compilation Tests | |
| ;; ============================================================================ | |
| (deftest test-compile-simple-arithmetic | |
| "Compile: π’40 π’2 β β©οΈ" | |
| (let [source "π’40 π’2 β β©οΈ" | |
| result (emoji/compile-emojiscript source)] | |
| (is (= true (:valid? result))) | |
| (is (= 4 (:instructions-count result))) | |
| (is (contains? #{:Push :Add :Ret} | |
| (map :op (:bytecode result)))))) | |
| (deftest test-compile-cap-gate | |
| "Compile: π’3 π’5 π β©οΈ (capability check)" | |
| (let [source "π’3 π’5 π β©οΈ" | |
| result (emoji/compile-emojiscript source)] | |
| (is (= true (:valid? result))) | |
| (is (some #(= :CapGate (:op %)) (:bytecode result))))) | |
| (deftest test-compile-memory-ops | |
| "Compile: π’64 π’9 ποΈ π’0 π€ β©οΈ (alloc + load)" | |
| (let [source "π’64 π’9 ποΈ π’0 π€ β©οΈ" | |
| result (emoji/compile-emojiscript source)] | |
| (is (= true (:valid? result))) | |
| (is (some #(= :Alloc (:op %)) (:bytecode result))) | |
| (is (some #(= :Load (:op %)) (:bytecode result))))) | |
| (deftest test-compile-jump | |
| "Compile: π’10 β‘οΈ (unconditional jump)" | |
| (let [source "π’10 β‘οΈ β©οΈ" | |
| result (emoji/compile-emojiscript source)] | |
| (is (= true (:valid? result))) | |
| (is (some #(= :Jump (:op %)) (:bytecode result))))) | |
| (deftest test-compile-conditional-jump | |
| "Compile: π’1 β (conditional jump)" | |
| (let [source "π’1 β β©οΈ" | |
| result (emoji/compile-emojiscript source)] | |
| (is (= true (:valid? result))) | |
| (is (some #(= :JumpIf (:op %)) (:bytecode result))))) | |
| (deftest test-compile-bitwise-ops | |
| "Compile: π’7 π’3 π€ β©οΈ (bitwise AND)" | |
| (let [source "π’7 π’3 π€ β©οΈ" | |
| result (emoji/compile-emojiscript source)] | |
| (is (= true (:valid? result))) | |
| (is (some #(= :And (:op %)) (:bytecode result))))) | |
| (deftest test-compile-rejects-empty | |
| "Reject empty program" | |
| (is (thrown-with-msg? | |
| js/Error | |
| #"Empty program" | |
| (emoji/compile-emojiscript "")))) | |
| (deftest test-compile-rejects-whitespace-only | |
| "Reject whitespace-only program" | |
| (is (thrown-with-msg? | |
| js/Error | |
| #"Empty program" | |
| (emoji/compile-emojiscript " \n\t ")))) | |
| (deftest test-compile-rejects-unknown-emoji | |
| "Reject unknown emoji" | |
| (is (thrown-with-msg? | |
| js/Error | |
| #"Unknown emoji" | |
| (emoji/compile-emojiscript "π₯·")))) | |
| ;; ============================================================================ | |
| ;; Execution Tests | |
| ;; ============================================================================ | |
| (deftest test-execute-simple-addition | |
| "Execute: π’40 π’2 β β©οΈ = 42" | |
| (let [source "π’40 π’2 β β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= true (:halted? result))) | |
| (is (= 42 (:result result))) | |
| (is (= [42] (:stack result))))) | |
| (deftest test-execute-subtraction | |
| "Execute: π’100 π’40 β β©οΈ = 60" | |
| (let [source "π’100 π’40 β β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= 60 (:result result))))) | |
| (deftest test-execute-multiplication | |
| "Execute: π’6 π’7 βοΈ β©οΈ = 42" | |
| (let [source "π’6 π’7 βοΈ β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= 42 (:result result))))) | |
| (deftest test-execute-division | |
| "Execute: π’84 π’2 β β©οΈ = 42" | |
| (let [source "π’84 π’2 β β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= 42 (:result result))))) | |
| (deftest test-execute-bitwise-and | |
| "Execute: π’15 π’7 π€ β©οΈ = 7 (bitwise AND)" | |
| (let [source "π’15 π’7 π€ β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= 7 (:result result))))) | |
| (deftest test-execute-bitwise-or | |
| "Execute: π’12 π’5 π β©οΈ = 13 (bitwise OR)" | |
| (let [source "π’12 π’5 π β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= 13 (:result result))))) | |
| (deftest test-execute-bitwise-xor | |
| "Execute: π’12 π’5 π β©οΈ = 9 (bitwise XOR)" | |
| (let [source "π’12 π’5 π β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (= 9 (:result result))))) | |
| (deftest test-execute-division-by-zero | |
| "Reject division by zero" | |
| (let [source "π’10 π’0 β β©οΈ" | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (contains? result :error)) | |
| (is (clojure.string/includes? (:error result) "Division by zero")))) | |
| (deftest test-execute-max-steps | |
| "Enforce step limit (prevent infinite loops)" | |
| (let [source "π’0 β‘οΈ" ; unconditional jump to 0 = infinite loop | |
| compiled (emoji/compile-emojiscript source) | |
| result (emoji/execute-emojiscript (:bytecode compiled) :max-steps 100)] | |
| (is (= 100 (:steps result))) | |
| (is (= false (:halted? result))))) | |
| ;; ============================================================================ | |
| ;; Integration Tests (MCP tools) | |
| ;; ============================================================================ | |
| ;; ============================================================================ | |
| ;; Semantic Passes (Phase 2) | |
| ;; ============================================================================ | |
| (deftest test-semantic-pass-stream | |
| "π Stream β telemetry-bus integration" | |
| (let [compiled (emoji/compile-emojiscript "π’42 π β©οΈ") | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (:halted? result)) | |
| (is (= 42 (:result result))) | |
| (is (some #(= (:type %) :telemetry) (:events result))) | |
| (is (>= (count (filter #(= (:event %) :stream-push) (:events result))) 1)))) | |
| (deftest test-semantic-pass-policy-check | |
| "π§ PolicyCheck β policy-immune routing" | |
| (let [compiled (emoji/compile-emojiscript "π’100 π§ β©οΈ") | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (:halted? result)) | |
| (is (= 100 (:result result))) | |
| (is (some #(= (:type %) :policy-route) (:events result))))) | |
| (deftest test-semantic-pass-seal | |
| "π Seal β Bifrost WORM signing" | |
| (let [compiled (emoji/compile-emojiscript "π’777 π β©οΈ") | |
| result (emoji/execute-emojiscript (:bytecode compiled) :worm-ledger {}) | |
| seal-event (first (filter #(= (:type %) :bifrost-seal) (:events result)))] | |
| (is (:halted? result)) | |
| (is (= 777 (:result result))) | |
| (is seal-event) | |
| (is (= 777 (:value seal-event))))) | |
| (deftest test-semantic-pass-readonly | |
| "π ReadOnly β capability downgrade" | |
| (let [compiled (emoji/compile-emojiscript "π’255 π β©οΈ") | |
| result (emoji/execute-emojiscript (:bytecode compiled))] | |
| (is (:halted? result)) | |
| (is (< (:result result) 255)) | |
| (is (some #(= (:type %) :capability-downgrade) (:events result))))) | |
| (deftest test-mcp-compile-tool | |
| "MCP compile_emojiscript tool" | |
| (let [source "π’40 π’2 β β©οΈ"] | |
| ; Would call: (tools/handle-compile-emojiscript {:source source}) | |
| ; For now, just verify compile works | |
| (is (truthy? (emoji/compile-emojiscript source))))) | |
| (deftest test-mcp-execute-tool | |
| "MCP execute_emojiscript tool" | |
| (let [source "π’40 π’2 β β©οΈ" | |
| compiled (emoji/compile-emojiscript source)] | |
| ; Would call: (tools/handle-execute-emojiscript {:source source :max-steps 10000}) | |
| (is (= 42 (:result (emoji/execute-emojiscript (:bytecode compiled))))))) | |