Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wasm language #81

Merged
merged 1 commit into from Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/languages/wasm.txt
@@ -0,0 +1,2 @@
!e
;;\p
56 changes: 56 additions & 0 deletions test/languages/wasm_test.rb
@@ -0,0 +1,56 @@
require "test_helper"

module SnippetExtractor
module Languages
class WasmTest < Minitest::Test
def test_full_example
code = <<~CODE
(module ;; in-line comment
(func (export "score") (param $x f32) (param $y f32) (result i32)

;; Calculate the distance from the center
(local $distance f32)
(local.set $distance (f32.sqrt
(f32.add
(f32.mul (local.get $x) (local.get $x))
(f32.mul (local.get $y) (local.get $y)))))

;; We're outside the outer circle, OR
(if (f32.gt (local.get $distance) (f32.const 10.0)) (then
(return (i32.const 0))
))

;; We're outside the middle circle, OR
(if (f32.gt (local.get $distance) (f32.const 5.0)) (then
(return (i32.const 1))
))

;; We're outside the inner circle, OR
(if (f32.gt (local.get $distance) (f32.const 1.0)) (then
(return (i32.const 5))
))

;; We've hit the bullseye
(return (i32.const 10))
)
)
CODE

expected = <<~CODE
(module
(func (export "score") (param $x f32) (param $y f32) (result i32)

(local $distance f32)
(local.set $distance (f32.sqrt
(f32.add
(f32.mul (local.get $x) (local.get $x))
(f32.mul (local.get $y) (local.get $y)))))

(if (f32.gt (local.get $distance) (f32.const 10.0)) (then
CODE

assert_equal expected, ExtractSnippet.(code, 'wasm')
end
end
end
end