File tree 2 files changed +58
-0
lines changed
2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ !e
2
+ ;;\p
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+
3
+ module SnippetExtractor
4
+ module Languages
5
+ class WasmTest < Minitest ::Test
6
+ def test_full_example
7
+ code = <<~CODE
8
+ (module ;; in-line comment
9
+ (func (export "score") (param $x f32) (param $y f32) (result i32)
10
+
11
+ ;; Calculate the distance from the center
12
+ (local $distance f32)
13
+ (local.set $distance (f32.sqrt
14
+ (f32.add
15
+ (f32.mul (local.get $x) (local.get $x))
16
+ (f32.mul (local.get $y) (local.get $y)))))
17
+
18
+ ;; We're outside the outer circle, OR
19
+ (if (f32.gt (local.get $distance) (f32.const 10.0)) (then
20
+ (return (i32.const 0))
21
+ ))
22
+
23
+ ;; We're outside the middle circle, OR
24
+ (if (f32.gt (local.get $distance) (f32.const 5.0)) (then
25
+ (return (i32.const 1))
26
+ ))
27
+
28
+ ;; We're outside the inner circle, OR
29
+ (if (f32.gt (local.get $distance) (f32.const 1.0)) (then
30
+ (return (i32.const 5))
31
+ ))
32
+
33
+ ;; We've hit the bullseye
34
+ (return (i32.const 10))
35
+ )
36
+ )
37
+ CODE
38
+
39
+ expected = <<~CODE
40
+ (module
41
+ (func (export "score") (param $x f32) (param $y f32) (result i32)
42
+
43
+ (local $distance f32)
44
+ (local.set $distance (f32.sqrt
45
+ (f32.add
46
+ (f32.mul (local.get $x) (local.get $x))
47
+ (f32.mul (local.get $y) (local.get $y)))))
48
+
49
+ (if (f32.gt (local.get $distance) (f32.const 10.0)) (then
50
+ CODE
51
+
52
+ assert_equal expected , ExtractSnippet . ( code , 'wasm' )
53
+ end
54
+ end
55
+ end
56
+ end
You can’t perform that action at this time.
0 commit comments