a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package languages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestRustWasmBindgenStampsFileMeta(t *testing.T) {
|
|
src := `use wasm_bindgen::prelude::*;
|
|
|
|
#[wasm_bindgen]
|
|
pub fn greet(name: &str) -> String {
|
|
format!("Hello, {}", name)
|
|
}
|
|
`
|
|
ext := NewRustExtractor()
|
|
res, err := ext.Extract("pkg/lib.rs", []byte(src))
|
|
if err != nil {
|
|
t.Fatalf("extract: %v", err)
|
|
}
|
|
var fileNode *graph.Node
|
|
for _, n := range res.Nodes {
|
|
if n.Kind == graph.KindFile {
|
|
fileNode = n
|
|
break
|
|
}
|
|
}
|
|
if fileNode == nil {
|
|
t.Fatal("no file node emitted")
|
|
}
|
|
if v, _ := fileNode.Meta["uses_wasm_bindgen"].(bool); !v {
|
|
t.Errorf("expected uses_wasm_bindgen=true on file node, meta=%+v", fileNode.Meta)
|
|
}
|
|
}
|
|
|
|
func TestRustWasmBindgenAbsentOnRegularFile(t *testing.T) {
|
|
src := `pub fn add(a: i32, b: i32) -> i32 {
|
|
a + b
|
|
}
|
|
`
|
|
ext := NewRustExtractor()
|
|
res, err := ext.Extract("pkg/lib.rs", []byte(src))
|
|
if err != nil {
|
|
t.Fatalf("extract: %v", err)
|
|
}
|
|
for _, n := range res.Nodes {
|
|
if n.Kind == graph.KindFile {
|
|
if v, _ := n.Meta["uses_wasm_bindgen"].(bool); v {
|
|
t.Errorf("regular Rust file should not have uses_wasm_bindgen set")
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|